-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel1.java
More file actions
108 lines (95 loc) · 2.95 KB
/
Level1.java
File metadata and controls
108 lines (95 loc) · 2.95 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Level1: Short speedrun.
*/
public class Level1 extends Scrolling {
//Creates String representing the map layout.
String[] textMap = {
"**********************************",
"*.eeeeeeeeeeeeeebropeeeeeeeeeeeee*",
"********************************e*",
"*meeeeeeeeeeeeeeeeeeeeeeeeeeeeeee*",
"**********************************"
};
public Level1() {
super(550, 600, 1, 2250, 1200);
setScrollingBackground(new GreenfootImage("road.jpg"));
stopSounds();
prepare();
drawMap();
}
/**
* Creates Level1 world.
*/
private void prepare() {
Timer.timer = 0;
stopSounds();
addObject(new Score(), 75, 575);
addObject(new PackLives(), 480, 575);
addObject(new Pack(), 0, 0);
}
/**
* Draws map using string with case switch.
*/
private void drawMap() {
for (int i = 0; i < textMap.length; i++) {
String mapLine = textMap[i];
for(int j = 0; j < mapLine.length(); j++) {
char mapChar = mapLine.charAt(j);
int y = 150 + i * 50;
int x = j * 50;
switch(mapChar) {
case '*':
addObject(new Wall(), x, y);
break;
case '.':
addObject(new SmallYummy(), x, y);
break;
case 'b':
addObject(new BlueGhost(), x, y);
break;
case 'r':
addObject(new RedGhost(), x, y);
break;
case 'o':
addObject(new OrangeGhost(), x, y);
break;
case 'p':
addObject(new PinkGhost(), x, y);
break;
case 'm':
addObject(new BigYummy(), x, y);
break;
default:
break;
}
}
}
}
public void act() {
checkLives();
checkSounds();
nextLevel();
checkNoPack();
}
/**
* Checks if Pack is alive or level reset button pressed.
*/
private void checkNoPack() {
if (getObjects(Pack.class).isEmpty() || Greenfoot.isKeyDown("r")) {
stopSounds();
PackLives.lives--;
Greenfoot.setWorld(new Level1());
Greenfoot.delay(5);
}
}
/**
* If SmallYummy empty goes to next world.
*/
private void nextLevel() {
if (getObjects(SmallYummy.class).isEmpty()) {
stopSounds();
Greenfoot.setWorld(new Level2());
}
}
}