-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyWorld.java
75 lines (70 loc) · 2.27 KB
/
MyWorld.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
67
68
69
70
71
72
73
74
75
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Ini adalah world class.
* @author (Muhammad Ammar Nabil)
*/
public class MyWorld extends World
{
private int counter = 0;
private int counterDif = 0;
private int counterGround = 0;
private int worldSpeed = 50;
private int random;
static public int difficulty = 0;
private boolean startTime = true;
public void act(){
counter++;
counterDif++;
counterGround++;
if (startTime){
difficulty = 0;
if (counter >= 180){
counter = 0;
counterGround = 0;
random = Greenfoot.getRandomNumber(15);
startTime = false;
addObject(new cactus(), 900,280);
}
} else if (counter >= (90+random)-(int)(1.7*(double)difficulty)){
counter = 0;
random = Greenfoot.getRandomNumber(15);
if (Greenfoot.getRandomNumber(3) == 0){
addObject(new bird(), 900,Greenfoot.getRandomNumber(190)+80);
} else{
addObject(new cactus(), 900,280);
}
}
if (counterDif >= 100){
difficulty++;
if (difficulty > 50){
difficulty = 50;
}
counterDif = 0;
}
}
public MyWorld()
{
super(900, 400, 1);
prepare();
setBackground("background.jpg");
Greenfoot.setSpeed(worldSpeed);
}
private void prepare()
{
dino dino = new dino();
moon moon = new moon();
addObject(dino,70,279);
addObject(moon,724,112);
addObject(new score(), 820, 35);
addObject(new ground(), 376, 303);
addObject(new ground(), 800, 303);
for (int i=0; i<5; i++){
addObject(new star(),Greenfoot.getRandomNumber(900), Greenfoot.getRandomNumber(170)+50);
}
for (int i=0; i<2; i++){
addObject(new cloud(),Greenfoot.getRandomNumber(900), Greenfoot.getRandomNumber(170)+50);
}
setPaintOrder(gameOver.class, dino.class, score.class, bird.class, cactus.class,
ground.class, cloud.class, moon.class, star.class);
}
}