-
Notifications
You must be signed in to change notification settings - Fork 0
/
cactus.java
43 lines (39 loc) · 1.2 KB
/
cactus.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class cactus extends obstacle
{
private int counter = 0;
private boolean cactus = true;
public cactus(){
setImage("cactus-small-1.png");
}
public void act()
{
if(dino.alive){
counter++;
if(cactus){
randomization();
cactus = false;
}
move(-6 - MyWorld.difficulty);
if(isAtEdge()){
cactus = true;
getWorld().removeObject(this);
}
}
}
private void randomization(){
if (Greenfoot.getRandomNumber(6) == 0){
setImage("cactus-big-3.png");
} else if (Greenfoot.getRandomNumber(5) == 0){
setImage("cactus-big-2.png");
} else if (Greenfoot.getRandomNumber(4) == 0){
setImage("cactus-big-1.png");
} else if (Greenfoot.getRandomNumber(3) == 0){
setImage("cactus-small-3.png");
} else if (Greenfoot.getRandomNumber(2) == 0){
setImage("cactus-small-2.png");
} else {
setImage("cactus-small-1.png");
}
}
}