-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdennis_ball.java
66 lines (65 loc) · 2 KB
/
dennis_ball.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
65
66
import greenfoot.*;
import java.util.*;
/**
* Write a description of class dennis_ball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class dennis_ball extends Projectiles
{
SimpleTimer timer = new SimpleTimer();
/**
* Act - do whatever the dennis_ball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act() {
if(isTouching(Freeze.class) && !Freeze.grace){
getWorld().addObject(new dennis_ball_explode(), getX(), getY());
if(!Freeze.defence)Freeze.isHit = true;
getWorld().removeObject(this);
return;
}
if(isTouching(Bat.class) && !Bat.grace){
getWorld().addObject(new dennis_ball_explode(), getX(), getY());
if(!Bat.isDefencing)Bat.isHited = true;
getWorld().removeObject(this);
return;
}
if(isTouching(Louis.class) && !Louis.grace){
getWorld().addObject(new dennis_ball_explode(), getX(), getY());
if(!Louis.defence)Louis.isHit = true;
getWorld().removeObject(this);
return;
}
super.act();
animate();
move(6);
}
public void animate(){
if(timer.millisElapsed() > 0){
setImage("ball1.png");
}
if(timer.millisElapsed() > 25){
setImage("ball2.png");
}
if(timer.millisElapsed() > 50){
setImage("ball3.png");
}
if(timer.millisElapsed() > 75){
setImage("ball4.png");
}
if(timer.millisElapsed() > 100){
setImage("ball3.png");
}
if(timer.millisElapsed() > 125){
setImage("ball2.png");
}
if(timer.millisElapsed() > 150){
setImage("ball1.png");
}
if(timer.millisElapsed() > 175){
timer.mark();
}
}
}