Skip to content

Commit 5b0f6a6

Browse files
committed
add DROWNING
1 parent 2d3abbc commit 5b0f6a6

File tree

3 files changed

+61
-35
lines changed

3 files changed

+61
-35
lines changed

game.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -148,29 +148,35 @@ function createGame(gameCavas, onGameLoaded)
148148
}
149149
}
150150

151+
152+
game.eventHandler = new EventHandler(game);
153+
154+
game.triggerHandler = new TriggerHandler(game);
155+
156+
151157
game.fileLoader = new FileLoader();
152158

159+
//- loading main.dat
153160
game.mainFileProvider = new MainFileProvider(game);
154161
game.mainFileProvider.load(function()
155162
{
156163
game.lemmingDrawer = new LemmingDrawer(game);
157164
game.lemmingDrawer.load();
158165

159-
});
160-
166+
//- creating GUI : requires main.dat
167+
game.gameGui = new GameGui(game);
168+
game.gameGui.load();
161169

162-
game.levelHandler = new LevelHandler(game);
163-
game.levelHandler.load(onLevelLoaded, game.levelIndex);
170+
//- loading level01.dat
171+
game.levelHandler = new LevelHandler(game);
172+
game.levelHandler.load(onLevelLoaded, game.levelIndex);
164173

165-
game.eventHandler = new EventHandler(game);
174+
});
166175

167176

168-
game.triggerHandler = new TriggerHandler(game);
169177

170178
function onLevelLoaded()
171179
{
172-
game.levelDrawer = new LevelDrawer(game);
173-
game.levelDrawer.load(onLevelDrawn);
174180
game.viewX = game.levelHandler.screenPositionX;
175181

176182
for (var i = 0; i < 10; i++)
@@ -181,19 +187,22 @@ function createGame(gameCavas, onGameLoaded)
181187
game.releaseRate = game.levelHandler.releaseRate;
182188
game.releaseRateMin = game.levelHandler.releaseRate;
183189
game.releaseCount = game.levelHandler.releaseCount;
190+
191+
192+
//- load GROUNDxO.DAT and VGAGRx.DAT
193+
game.levelDrawer = new LevelDrawer(game);
194+
game.levelDrawer.load(onLevelDrawerLoaded);
184195
}
185196

186197

187-
function onLevelDrawn()
198+
function onLevelDrawerLoaded()
188199
{
189200
//- generate terrain layer
190201
game.levelDrawer.createTerrain();
191202

192203
game.levelDrawer.createObjectTrigger();
193204

194-
game.gameGui = new GameGui(game);
195-
game.gameGui.load();
196-
205+
//- callback
197206
if (typeof onGameLoaded !== "undefined") onGameLoaded();
198207
}
199208

lemming.js

+39-22
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ function Lemming(gameObject, x, y)
44
{
55

66
this.STATE = {
7-
UNKNOWN : {id:0, canSetState:false, isFalling:false, name: "unknown"},
8-
WALKING : {id:1, canSetState:true, isFalling:false, name: "walking"},
9-
FALLING : {id:3, canSetState:false, isFalling:true, name: "fall"},
10-
FLYING : {id:4, canSetState:false, isFalling:true, name: "falling"},
11-
DIGGING : {id:5, canSetState:true, isFalling:false, name: "digging"},
12-
BLOCKING : {id:6, canSetState:false, isFalling:false, name: "blocking"},
13-
BUILDING : {id:7, canSetState:true, isFalling:false, name: "build"},
14-
BASHING : {id:8, canSetState:true, isFalling:false, name: "bush"},
15-
MINING : {id:9, canSetState:true, isFalling:false, name: "mining"},
16-
CLIMBING : {id:10, canSetState:false, isFalling:false, name: "climbing"},
17-
OHNO : {id:11, canSetState:false, isFalling:false, name: "Oh No"},
18-
EXPLODING: {id:12, canSetState:false, isFalling:false, name: "exploding"},
19-
UMBRELLA : {id:13, canSetState:false, isFalling:true, name: "flying 1"},
20-
PREUMBRELLA: {id:14, canSetState:false, isFalling:true, name: "flying 2"},
21-
BOMBING : {id:15, canSetState:true, isFalling:false, name: "exploding"},
22-
SPLATTING: {id:16, canSetState:false, isFalling:false, name: "splatting"},
23-
EXITING : {id:17, canSetState:true, isFalling:false, name: "leaving"},
7+
UNKNOWN : {id:0, canSetState:false, isFalling:false, canFall:true, name: "unknown"},
8+
WALKING : {id:1, canSetState:true, isFalling:false, canFall:true, name: "walking"},
9+
FALLING : {id:3, canSetState:false, isFalling:true, canFall:true, name: "fall"},
10+
FLYING : {id:4, canSetState:false, isFalling:true, canFall:true, name: "falling"},
11+
DIGGING : {id:5, canSetState:true, isFalling:false, canFall:true, name: "digging"},
12+
BLOCKING : {id:6, canSetState:false, isFalling:false, canFall:true, name: "blocking"},
13+
BUILDING : {id:7, canSetState:true, isFalling:false, canFall:true, name: "build"},
14+
BASHING : {id:8, canSetState:true, isFalling:false, canFall:true, name: "bush"},
15+
MINING : {id:9, canSetState:true, isFalling:false, canFall:true, name: "mining"},
16+
CLIMBING : {id:10, canSetState:false, isFalling:false, canFall:true, name: "climbing"},
17+
OHNO : {id:11, canSetState:false, isFalling:false, canFall:true, name: "Oh No"},
18+
EXPLODING: {id:12, canSetState:false, isFalling:false, canFall:true, name: "exploding"},
19+
UMBRELLA : {id:13, canSetState:false, isFalling:true, canFall:true, name: "flying 1"},
20+
PREUMBRELLA: {id:14, canSetState:false, isFalling:true, canFall:true, name: "flying 2"},
21+
BOMBING : {id:15, canSetState:true, isFalling:false, canFall:true, name: "exploding"},
22+
SPLATTING: {id:16, canSetState:false, isFalling:false, canFall:true, name: "splatting"},
23+
EXITING : {id:17, canSetState:false, isFalling:false, canFall:false, name: "leaving"},
24+
DROWNING : {id:18, canSetState:false, isFalling:false, canFall:false, name: "drowning"}
2425
};
2526

2627

@@ -44,6 +45,7 @@ function Lemming(gameObject, x, y)
4445

4546
this.stateTicks++;
4647

48+
4749
//- process Triggers
4850
var triggerState = self.game.triggerHandler.trigger(self.x, self.y, gametick);
4951
if (triggerState != null)
@@ -53,20 +55,30 @@ function Lemming(gameObject, x, y)
5355
switch (triggerState)
5456
{
5557
case TRIGGERS.EXIT:
56-
self.changeState(self.STATE.EXITING);
58+
self.changeState(self.STATE.EXITING, false);
5759
break;
5860
case TRIGGERS.BLOCKER_LEFT:
5961
if ((self.state != self.STATE.BLOCKER) && (self.dir > 0)) self.dir = -1;
6062
break;
6163
case TRIGGERS.BLOCKER_RIGHT:
6264
if ((self.state != self.STATE.BLOCKER) && (self.dir < 0)) self.dir = 1;
6365
break;
66+
case TRIGGERS.DROWN:
67+
self.changeState(self.STATE.DROWNING, false);
68+
break;
6469
}
6570
}
6671

6772
if ((self.state == self.STATE.EXITING) && (this.stateTicks >= 8))
6873
{
6974
self.removeLem(true);
75+
return;
76+
}
77+
78+
if ((self.state == self.STATE.DROWNING) && (this.stateTicks >= 16))
79+
{
80+
self.removeLem(true);
81+
return;
7082
}
7183

7284
//- process explosion timeout
@@ -75,7 +87,11 @@ function Lemming(gameObject, x, y)
7587
self.ticksToDie--;
7688
if (self.ticksToDie == 0) self.state = self.STATE.OHNO;
7789
if (self.ticksToDie == -16) self.state = self.STATE.EXPLODING;
78-
if (self.ticksToDie < -16) self.removeLem();
90+
if (self.ticksToDie < -16)
91+
{
92+
self.removeLem();
93+
return;
94+
}
7995
}
8096

8197
var lineLen1 = self.game.gameTerrain.width * 4;
@@ -104,7 +120,7 @@ function Lemming(gameObject, x, y)
104120
}
105121

106122

107-
if (data[dataPos + lineLen1] == 0)
123+
if ((data[dataPos + lineLen1] == 0) && (self.state.canFall))
108124
{
109125
//- there is no ground below
110126

@@ -254,11 +270,11 @@ function Lemming(gameObject, x, y)
254270

255271
case self.STATE.MINING:
256272
self.y += 1;
257-
self.x += 1;
273+
self.x += self.dir;
258274
break;
259275

260276
case self.STATE.BASHING:
261-
self.x += 1;
277+
self.x += self.dir;
262278
break;
263279

264280

@@ -275,6 +291,7 @@ function Lemming(gameObject, x, y)
275291
case self.STATE.FALLING:
276292
case self.STATE.PREUMBRELLA:
277293
case self.STATE.UMBRELLA:
294+
case self.STATE.DROWNING:
278295
if (self.state != newState)
279296
{
280297
self.state = newState;

lemmingDrawer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function LemmingDrawer(gameObject)
3232
self.registerAnimation(state.DIGGING, 0, fr, 3, 16, 14, 16); //- digging
3333
self.registerAnimation(state.CLIMBING, 1, fr, 2, 16, 12, 8); //- climbing (r)
3434
self.registerAnimation(state.CLIMBING, -1, fr, 2, 16, 12, 8); //- climbing (l)
35-
self.registerAnimation(state.UNKNOWN, 0, fr, 2, 16, 10, 16); //- drowning
35+
self.registerAnimation(state.DROWNING, 0, fr, 2, 16, 10, 16); //- drowning
3636
self.registerAnimation(state.UNKNOWN, 1, fr, 2, 16, 12, 8); //- post-climb (r)
3737
self.registerAnimation(state.UNKNOWN, -1, fr, 2, 16, 12, 8); //- post-climb (l)
3838
self.registerAnimation(state.BUILDING, 1, fr, 3, 16, 13, 16); //- brick-laying (r)

0 commit comments

Comments
 (0)