-
Notifications
You must be signed in to change notification settings - Fork 53
/
game-leavemealone.html
340 lines (296 loc) · 12.9 KB
/
game-leavemealone.html
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<html>
<head>
<script type="text/javascript" src="akihabara/gbox.js"></script>
<script type="text/javascript" src="akihabara/iphopad.js"></script>
<script type="text/javascript" src="akihabara/trigo.js"></script>
<script type="text/javascript" src="akihabara/toys.js"></script>
<script type="text/javascript" src="akihabara/help.js"></script>
<script type="text/javascript" src="akihabara/tool.js"></script>
<script type="text/javascript" src="akihabara/gamecycle.js"></script>
<style>BODY { -webkit-user-select:none; margin:0px}</style>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
</head>
<body>
</body>
<script>
// ---
// Copyright (c) 2010 Francesco Cottone, http://www.kesiev.com/
// ---
// Game-specific
var maingame;
var dialogues={}; // Loaded by external resources. Must be global.
var tilemaps={}; // Loaded by external resources. Must be global.
var mapmeta={}; // Loaded by external resources. Must be global.
var mapobjects={}; // Loaded by external resources. Must be global.
var audioserver;
var currentstage; // The stage that is currently playing
function go() {
gbox.setGroups(["background","player","foes","sparks","gamecycle"]);
gbox.setAudioChannels({bgmusic:{volume:0.8},sfx:{volume:1.0}});
maingame=gamecycle.createMaingame("gamecycle","gamecycle");
// Game intro
maingame.gameIntroAnimation=function(reset){
if (reset) {
toys.resetToy(this,"intro-animation");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
return toys.dialogue.render(this,"intro-animation",dialogues.intro);
}
}
// Game ending
maingame.gameEndingIntroAnimation=function(reset){
if (reset) {
toys.resetToy(this,"intro-animation");
maingame.hud.hideWidgets(["stage","time","timelabel"]); // Hides the timer and the stage label for the ending
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
return toys.dialogue.render(this,"intro-animation",dialogues.ending);
}
}
// Change level
maingame.changeLevel=function(level) {
if (level==null) level="stage1"; // First stage
currentstage=level;
maingame.hud.setValue("stage","value",currentstage); // Level name on the hud!
gbox.createCanvas("tileslayer",{w:tilemaps[currentstage].w,h:tilemaps[currentstage].h});
gbox.blitTilemap(gbox.getCanvasContext("tileslayer"),tilemaps[currentstage]);
this.newLife();
}
// New life
maingame.newLife=function(up) {
// Cleanup the level.
gbox.trashGroup("foes");
gbox.purgeGarbage(); // Since we're starting, we can purge all now
// Apply some common tilemap handlers to the map. Are the same for all the stages.
tilemaps[currentstage].tileIsSolidCeil=function(obj,t){ return (obj.group=="foes"?false:t==0) };
tilemaps[currentstage].tileIsSolidFloor=function(obj,t){ return t==0 };
// Add the stage objects, according to the configured mapobjects
var current;
for (var i=0;i<mapobjects[currentstage].items.length;i++) {
current=mapobjects[currentstage].items[i];
switch (current.objecttype) {
case "player": {
toys.platformer.spawn(gbox.getObject("player","player"),help.mergeWithModel(current,{accx:0,accy:0})); // Apply to the defined object the model with no acceleration. Notes that the "objecttype" parameter is also merged to the object but ignored.
break;
}
default: { // All the other objects are enemies. Depending on the ID, different enemies are spawn.
maingame.addEnemy(current.objecttype,current); // Data are directly taken from the resources data.
break;
}
}
}
toys.resetToy(maingame,"gametimer"); // Start the timer
gbox.hitAudio("ingame"); // Start the music
}
// Title intro
maingame.gameTitleIntroAnimation=function(reset) {
if (reset) {
gbox.playAudio("default-music");
toys.resetToy(this,"bouncer");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
toys.logos.bounce(this,"bouncer",{image:"logo",x:gbox.getScreenHW()-gbox.getImage("logo").hwidth,y:-gbox.getImage("logo").height,accy:0,audiobounce:"hit",floory:gbox.getScreenHH()});
}
},
// End level animation
maingame.endlevelIntroAnimation=function(reset) {
if (reset) {
toys.resetToy(this,"framecounter");
toys.resetToy(this,"aftercounter");
} else {
gbox.blitText(gbox.getBufferContext(),{font:"big",text:"STAGE CLEAR!",valign:gbox.ALIGN_MIDDLE,halign:gbox.ALIGN_CENTER,dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH()});
if (this.hud.getValue("time","value")) { // If there is time left...
if (toys.timer.every(this,"framecounter",2)) { // Every 2 frames...
gbox.hitAudio("beep");
this.hud.addValue("time","value",-1); // for every second...
this.hud.addValue("score","value",10); // Give 10 points to player 1
}
return false; // Keep here for more bonuses
} else return toys.timer.after(this,"aftercounter",15); // If there isn't more time, quit after 10 frames
}
},
// Games conditions
maingame.gameEvents=function() {
// Tick the timer
if (toys.timer.real(this,"gametimer",{countdown:30,critical:5,audiocritical:"beep"}))
gbox.getObject("player","player").kill(); // time is up
else
maingame.hud.setValue("time","value",toys.getToyValue(this,"gametimer","time")); // Updates timer
if (gbox.groupIsEmpty("foes"))
if (mapmeta[currentstage].nextLevel)
maingame.gotoLevel(mapmeta[currentstage].nextLevel);
else
maingame.gameIsCompleted();
}
// Game is over when...
maingame.gameIsOver=function() {
return maingame.hud.getValue("lives","value")==0;
}
// Custom method
maingame.addEnemy=function(type,data) {
switch (type) {
case "squid": {
gbox.addObject({
group:"foes",
tileset:"enemy-goo",
score:100,
initialize:function() {
toys.platformer.initialize(this,{
frames:{
still:{ speed:1, frames:[0] },
walking:{ speed:4, frames:[0,1] },
jumping:{ speed:1, frames:[0] },
falling:{ speed:1, frames:[0] },
die: { speed:1,frames:[0] }
},
x:data.x,
y:data.y,
jumpaccy:10,
side:data.side
});
},
first:function() {
if (gbox.objectIsVisible(this)) {
// Counter
this.counter=(this.counter+1)%10;
toys.platformer.applyGravity(this); // Apply gravity
toys.platformer.auto.horizontalBounce(this); // Bounces horizontally if hit the sideways walls
if (this.touchedfloor) // If touching the floor...
toys.platformer.auto.goomba(this,{moveWhileFalling:true,speed:2}); // goomba movement
else // Else...
this.accx=0; // Stay still (i.e. jump only vertically)
toys.platformer.auto.dontFall(this,tilemaps[currentstage],"map"); // prevent from falling from current platform
toys.platformer.verticalTileCollision(this,tilemaps[currentstage],"map"); // vertical tile collision (i.e. floor)
toys.platformer.horizontalTileCollision(this,tilemaps[currentstage],"map"); // horizontal tile collision (i.e. walls)
if (toys.platformer.canJump(this)&&toys.timer.randomly(this,"jumper",{base:50,range:50})) this.accy=-this.jumpaccy; // Jump randomly (the toy is resetted the first call)
toys.platformer.handleAccellerations(this); // gravity/attrito
toys.platformer.setFrame(this); // set the right animation frame
var pl=gbox.getObject("player","player");
if (pl.collisionEnabled())
if (help.isSquished(this,pl)) {
gbox.hitAudio("hit");
pl.multiplier++;
var mp=help.multiplier(pl.multiplier);
maingame.hud.addValue("score","value",this.score*mp);
gbox.trashObject(this);
toys.platformer.bounce(pl,{jumpsize:10});
toys.generate.sparks.bounceDie(this,"sparks",null,{jump:6,flipv:true});
toys.generate.sparks.popupText(this,"sparks",null,{font:"big",jump:6,text:this.score+(mp>1?"x"+mp:"")+" pts.",keep:10});
} else
if (gbox.collides(this,pl,2))
pl.kill(this);
}
},
blit:function() {
if (gbox.objectIsVisible(this))
gbox.blitTile(gbox.getBufferContext(),{tileset:this.tileset,tile:this.frame,dx:this.x,dy:this.y,camera:this.camera,fliph:this.side,flipv:this.flipv});
}
});
break;
}
}
}
maingame.initializeGame=function() {
// Build hud
maingame.hud.setWidget("label",{widget:"label",font:"small",value:"1UP",dx:10,dy:10,clear:true});
maingame.hud.setWidget("score",{widget:"label",font:"small",value:0,dx:30,dy:25,prepad:10,padwith:" ",clear:true});
maingame.hud.setWidget("lives",{widget:"symbols",minvalue:0,value:3-maingame.difficulty,maxshown:3,tileset:"tiledfont",tiles:[10],dx:42,dy:10,gapx:8,gapy:0});
maingame.hud.setWidget("timelabel",{widget:"label",font:"small",value:"TIME",dx:0,dy:10,dw:gbox.getScreenW(),halign:gbox.ALIGN_CENTER,clear:true});
maingame.hud.setWidget("time",{widget:"label",font:"big",value:30,dx:0,dy:20,dw:gbox.getScreenW(),halign:gbox.ALIGN_CENTER,prepad:2,padwith:"0",clear:true});
maingame.hud.setWidget("stage",{widget:"label",font:"small",value:"",postpad:7,padwith:" ",dx:0,dy:gbox.getScreenH()-8,clear:true});
gbox.addObject({
id:"player",
group:"player",
tileset:"player",
multiplier:0,
initialize:function() {
toys.platformer.initialize(this,{
frames:{
still:{ speed:1, frames:[0] },
walking:{ speed:2, frames:[1,2,3,2,1] },
jumping:{ speed:1, frames:[4] },
falling:{ speed:1, frames:[5] },
die:{speed:1,frames:[6] }
}
});
},
collisionEnabled:function() {
return !maingame.gameIsHold()&&!this.killed;
},
kill:function(by){
this.killed=true;
gbox.hitAudio("die");
maingame.hud.addValue("lives","value",-1); // Decreases lives
toys.generate.sparks.bounceDie(this,"sparks",null,{jump:6,flipv:false});
maingame.playerDied({wait:50});
},
first:function() {
// Counter
this.counter=(this.counter+1)%10;
if (!this.killed) {
toys.platformer.applyGravity(this); // Apply gravity
toys.platformer.horizontalKeys(this,{left:"left",right:"right"}); // Moves horizontally
toys.platformer.verticalTileCollision(this,tilemaps[currentstage],"map"); // vertical tile collision (i.e. floor)
toys.platformer.horizontalTileCollision(this,tilemaps[currentstage],"map"); // horizontal tile collision (i.e. walls)
toys.platformer.jumpKeys(this,{jump:"a",audiojump:"jump"}); // handle jumping
toys.platformer.handleAccellerations(this); // gravity/attrito
toys.platformer.setSide(this); // set horizontal side
toys.platformer.setFrame(this); // set the right animation frame
// Multiplier reset
if (this.touchedfloor) this.multiplier=0;
}
},
blit:function() {
if (!this.killed)
gbox.blitTile(gbox.getBufferContext(),{tileset:this.tileset,tile:this.frame,dx:this.x,dy:this.y,camera:this.camera,fliph:this.side,flipv:this.flipv});
}
});
gbox.addObject({
id:"bg",
group:"background",
blit:function() {
gbox.centerCamera(gbox.getObject("player","player"),{w:tilemaps[currentstage].w,h:tilemaps[currentstage].h});
gbox.blit(gbox.getBufferContext(),gbox.getImage("bg"),{dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),sourcecamera:true,parallaxx:0.5,parallaxy:0.5});
gbox.blit(gbox.getBufferContext(),gbox.getCanvas("tileslayer"),{dx:0,dy:0,dw:gbox.getScreenW(),dh:gbox.getScreenH(),sourcecamera:true});
}
});
}
gbox.go();
}
// BOOTSTRAP
gbox.onLoad(function () {
/*
tool.makecels({
rows:[
[
{img:"_bin/images/man 1.png"},
{img:"_bin/images/man 2.png"},
{img:"_bin/images/man 3.png"},
{img:"_bin/images/man 4.png"},
{img:"_bin/images/man 7.png"},
{img:"_bin/images/man 8.png"},
{img:"_bin/images/man 9.png"}
],
[
{img:"_bin/images/tiles 1.png"}
],
[
{img:"_bin/images/enemy1 1.png"},
{img:"_bin/images/enemy1 2.png"},
],
[
{img:"_bin/images/enemy2 1.png"},
{img:"_bin/images/enemy2 2.png"},
],
]
});
return;
*/
// Put additional licenses here!
help.akihabaraInit({title:"Leave Me Alone",splash:{footnotes:["Music by: Greenleo, Smiletron.","Full credits on ending title."]}});
audioserver="resources/audio/"
gbox.addBundle({file:"resources/leavemealone/bundle.js"}); // Audio, sprites, fonts etc. are loaded here now. Cleaner code! Btw you can still load resources from the code, like in Capman.
gbox.loadAll(go);
}, false);
</script>
</html>