-
Notifications
You must be signed in to change notification settings - Fork 6
/
WinRepeater.java
64 lines (52 loc) · 1.85 KB
/
WinRepeater.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MoneyBag here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class WinRepeater extends FallingObject
{
/**
* Act - do whatever the MoneyBag wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public GreenfootImage[] sprites = importSprites("srepeaterpacket", 2);
public boolean move = false;
public boolean addTrans = false;
public WinRepeater() {
super(-3, 0.15, Random.Double(-100, 100), 0, 750L);
}
public void update() {
currentFrame = System.nanoTime();
deltaTime = (currentFrame - lastFrame) / 1000000;
if (move) {
setImage("srepeaterpacket1.png");
if (getX() < (getWorld().getWidth()/2-5)) {
move(2);
} else if (getX() > (getWorld().getWidth()/2+5)){
move(-2);
} else {
if (!addTrans) {
addTrans=true;
getWorld().addObject(new Transition(false, new IntroLevel2(), "whitetransition.png", 1), 360, 215);
AudioPlayer.play(70, "lightfill.mp3");
}
}
} else {
animate(sprites, 200);
}
if (deltaTime < fallTime) {
double x = getExactX()+hSpeed;
double y = getExactY()+vSpeed;
setLocation(x,y);
turn(rotate);
vSpeed = vSpeed + acceleration;
} else {
}
if (Greenfoot.mouseClicked(this) && !move) {
move = true;
((MyWorld)getWorld()).finishLevel();
}
}
}