-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameWorld.as
More file actions
224 lines (205 loc) · 5.03 KB
/
GameWorld.as
File metadata and controls
224 lines (205 loc) · 5.03 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package
{
/**
* ...
* @author Bijan
*/
import flash.display.BitmapData;
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.masks.*;
import net.flashpunk.utils.*;
public class GameWorld extends World
{
public var player:Player;
public var level:Level;
public var cam:Camera;
public var timer:GameTimer;
public var hardMode:Boolean;
private var background:Background;
private var backgroundObj:BackgroundObj;
private var lvlCounter:int;
protected var mapImage:Image;
protected var mapGrid:Grid;
protected var sfxLevel1:Sfx = new Sfx(Assets.GFREAKMP3);
protected var sfxLevel2:Sfx = new Sfx(Assets.DATMP3);
protected var sfxLevel3:Sfx = new Sfx(Assets.GANBAREMP3);
protected var sfxLevel4:Sfx = new Sfx(Assets.BUDANGMP3);
protected var sfxLevel5:Sfx = new Sfx(Assets.RISEMP3);
public function GameWorld(mode:Boolean = false)
{
lvlCounter = 1;
hardMode = mode;
super();
loadLevel(Assets.LEVEL_ONE);
timer = new GameTimer(this);
add(timer);
}
override public function begin():void
{
super.begin();
}
public function loadLevel(mapData:Class):void
{
level = new Level(mapData, this);
background = new Background(mapData);
backgroundObj = new BackgroundObj(mapData);
player = level.player;
cam = new Camera(this);
add(player);
add(level);
add(background);
add(backgroundObj);
add(cam);
add(level.finish);
for (var i:int = 0; i < level.obstaclesArray.length; i++)
add(level.obstaclesArray[i]);
for (var j:int = 0; j < level.enemyHArray.length; j++)
add(level.enemyHArray[j]);
for (var k:int = 0; k < level.enemyVArray.length; k++)
add(level.enemyVArray[k]);
//choose which track to play and camera profile to use
switch(lvlCounter)
{
case 1:
cam.setProfile("horizontal");
if(!sfxLevel1.playing)
sfxLevel1.loop(0.25);
break;
case 2:
cam.setProfile("horizontal");
if(!sfxLevel2.playing)
sfxLevel2.loop(0.25);
break;
case 3:
cam.setProfile("balanced");
if(!sfxLevel3.playing)
sfxLevel3.loop(0.25);
break;
case 4:
cam.setProfile("vertical");
if(!sfxLevel4.playing)
sfxLevel4.loop(0.25);
break;
case 5:
cam.setProfile("default");
if(!sfxLevel5.playing)
sfxLevel5.loop(0.25);
break;
default:
break;
}
}
//unload level and move to next one
public function unloadLevelF():void
{
remove(player);
remove(level);
remove(background);
remove(backgroundObj);
remove(cam);
remove(level.finish);
for (var i:int = 0; i < level.obstaclesArray.length; i++)
remove(level.obstaclesArray[i]);
for (var j:int = 0; j < level.enemyHArray.length; j++)
remove(level.enemyHArray[j]);
for (var k:int = 0; k < level.enemyVArray.length; k++)
remove(level.enemyVArray[k]);
lvlCounter++;
switch(lvlCounter)
{
case 1:
loadLevel(Assets.LEVEL_ONE);
break;
case 2:
sfxLevel1.stop();
loadLevel(Assets.LEVEL_TWO);
break;
case 3:
sfxLevel2.stop();
loadLevel(Assets.LEVEL_THREE);
break;
case 4:
sfxLevel3.stop();
loadLevel(Assets.LEVEL_FOUR);
break;
case 5:
sfxLevel4.stop();
loadLevel(Assets.LEVEL_FIVE);
break;
default:
sfxLevel5.stop();
FP.world = new GameOverScreen(timer.time, hardMode);
break;
}
}
//reset level if player dies
public function unloadLevelR():void
{
remove(player);
remove(level);
remove(cam);
//things to not reload if on level 5 due to size
if (lvlCounter != 5)
{
remove(background);
remove(backgroundObj);
remove(level.finish);
for (var i:int = 0; i < level.obstaclesArray.length; i++)
remove(level.obstaclesArray[i]);
}
for (var j:int = 0; j < level.enemyHArray.length; j++)
remove(level.enemyHArray[j]);
for (var k:int = 0; k < level.enemyVArray.length; k++)
remove(level.enemyVArray[k]);
switch(lvlCounter)
{
case 1:
loadLevel(Assets.LEVEL_ONE);
break;
case 2:
loadLevel(Assets.LEVEL_TWO);
break;
case 3:
loadLevel(Assets.LEVEL_THREE);
break;
case 4:
loadLevel(Assets.LEVEL_FOUR);
break;
case 5:
reloadLevelFive(Assets.LEVEL_FIVE);
break;
default:
break;
}
}
public function reloadLevelFive(mapData:Class):void //special function to reduce loading time of level 5
{
level = new Level(mapData, this);
player = level.player;
cam = new Camera(this);
add(player);
add(level);
add(cam);
for (var j:int = 0; j < level.enemyHArray.length; j++)
add(level.enemyHArray[j]);
for (var k:int = 0; k < level.enemyVArray.length; k++)
add(level.enemyVArray[k]);
//choose which track to play and camera profile to use
switch(lvlCounter)
{
case 5:
cam.setProfile("default");
if(!sfxLevel5.playing)
sfxLevel5.loop(0.25);
break;
default:
break;
}
}
override public function update():void
{
super.update();
}
}
}