-
Notifications
You must be signed in to change notification settings - Fork 53
/
game-solitude.html
327 lines (283 loc) · 11.7 KB
/
game-solitude.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
<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 scroller;
var audioserver;
var dialogues={};
var faces={};
var stages={};
var enemies={};
function defaultSpark(th) { // this is a little hack: this function can be used for default bullet sparks, for smaller and smarter code
toys.generate.sparks.simple(th,"sparks",null,{animspeed:2,tileset:"spark"});
}
function go() {
gbox.setGroups(["background","player","playerbullets","foes","foesbullets","sparks","foreground","gamecycle"]);
gbox.setAudioChannels({bgmusic:{volume:0.8},sfx:{volume:1.0}});
maingame=gamecycle.createMaingame("gamecycle","gamecycle");
// No level intro animation
maingame.gameIntroAnimation=function() { return true; }
// Title intro
maingame.gameTitleIntroAnimation=function(reset) {
if (reset) {
gbox.playAudio("default-music");
toys.resetToy(this,"crosser");
toys.resetToy(this,"flash");
gbox.playGroup("foreground");
scroller=toys.shmup.generateScroller("foreground","roller",help.cloneObject(stages.attractscroller.scroller));
scroller.setSpeed(2);
scroller.setLoop(0,2560);
} else {
if (toys.getToyStatus(this,"crosser"))
toys.fullscreen.fadein(this,"flash",gbox.getBufferContext(),{fadespeed:0.05,color:gbox.COLOR_WHITE});
else
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
toys.logos.crossed(this,"crosser",{image:"logo",x:gbox.getScreenHW()-gbox.getImage("logo").hwidth,y:20,speed:2,gapx:250,alpha:0.5,audioreach:"megaexplosion"});
}
},
// Change level
maingame.changeLevel=function(level) {
if (level==null) level="stage1";
stages.currentstage=level;
// Cleanup the level.
gbox.trashGroup("foes");
gbox.trashGroup("background");
gbox.trashGroup("playerbullets");
gbox.trashGroup("foes");
gbox.trashGroup("foesbullets");
gbox.trashGroup("sparks");
gbox.trashGroup("foreground");
gbox.purgeGarbage(); // Since we're starting, we can purge all now
// This object handles the script of each level. First prepares the scroller and then does the game actions.
gbox.addObject({
id:"stagehandler",
group:"foreground",
initialize:function() {
// Since the scroller object changes itself, let's change a cloned histance instead of the original current stage.
scroller=toys.shmup.generateScroller("background","roller",help.cloneObject(stages[stages.currentstage].scroller));
},
first:function() {
stages[stages.currentstage].script(this,scroller.y,scroller.looprounds);
scroller.setX(gbox.getObject("player","player").x*0.5); // *0.5 for parallax
}
});
toys.shmup.spawn(gbox.getObject("player","player"),{x:150,y:200,weapon:0});
gbox.playAudio(stages[stages.currentstage].music);
this.newLife();
}
// Custom level handler. We will call this for passing from a stage to another. For
// flexibility, we will check if the destination stage exists. If yes, the stage is
// changed else the game ends. In your games you can just call the changeLevel, if you're
// sure that the stage exists.
maingame.myChangeLevel=function(dest) {
if (stages[dest]) // If the stage exists...
maingame.gotoLevel(dest); // Let's go there...
else // else... :)
maingame.gameIsCompleted(); // The game is completed
}
// New life
maingame.newLife=function(up) {
toys.shmup.spawn(gbox.getObject("player","player"),{health:3,invul:50,weapon:0});
}
// End level animation
maingame.endlevelIntroAnimation=function(reset) { return true }
// Game ending
maingame.gameEndingIntroAnimation=function(reset){
if (reset) {
toys.resetToy(this,"intro-animation");
} else {
gbox.blitFade(gbox.getBufferContext(),{alpha:1});
return toys.dialogue.render(this,"intro-animation",dialogues.titles);
}
}
// Game initialization
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",tiles:[0],minvalue:0,value:3-maingame.difficulty,maxshown:3,tileset:"symbols",dx:10,dy:gbox.getScreenH()-23,gapx:16,gapy:0});
// Add player
gbox.addObject({
id:"player",
group:"player",
tileset:"player",
weapon:0, // current weapon
invul:0, // Invulnerability timer
respawntimer:0, // respawn timer
powerUp:function() {
if (this.weapon<2) {
this.weapon++;
toys.generate.sparks.popupText(this,"sparks",null,{font:"bigred",jump:6,text:"POWER LV."+(this.weapon+1),keep:10});
}
},
makeInvulnerable:function(t) {
this.invul=t;
},
fireBullet:function() {
gbox.hitAudio("laser");
if (this.weapon==0) { // single shot
toys.shmup.fireBullet("playerbullets",null,{collidegroup:"foes",from:this,upper:true,tileset:"bulletbig",spark:function(th){defaultSpark(th)},frames:{speed:1,frames:[0]},accx:0,accy:-8});
} else if (this.weapon==1) { // double shot
toys.shmup.fireBullet("playerbullets",null,{collidegroup:"foes",from:this,upper:true,tileset:"bulletbig",spark:function(th){defaultSpark(th)},frames:{speed:1,frames:[0]},accx:0,accy:-8,gapx:-8});
toys.shmup.fireBullet("playerbullets",null,{collidegroup:"foes",from:this,upper:true,tileset:"bulletbig",spark:function(th){defaultSpark(th)},frames:{speed:1,frames:[0]},accx:0,accy:-8,gapx:8});
} else if (this.weapon==2) { // wide shot
toys.shmup.fireBullet("playerbullets",null,{collidegroup:"foes",from:this,upper:true,tileset:"bulletbig",spark:function(th){defaultSpark(th)},frames:{speed:1,frames:[0]},accx:0,accy:-10});
toys.shmup.fireBullet("playerbullets",null,{collidegroup:"foes",from:this,upper:true,tileset:"bulletbig",spark:function(th){defaultSpark(th)},frames:{speed:1,frames:[0]},acc:8,angle:4.9});
toys.shmup.fireBullet("playerbullets",null,{collidegroup:"foes",from:this,upper:true,tileset:"bulletbig",spark:function(th){defaultSpark(th)},frames:{speed:1,frames:[0]},acc:8,angle:4.7});
}
},
initialize:function() {
toys.shmup.initialize(this,{
bounds:{x:0,y:50,w:gbox.getScreenW(),h:gbox.getScreenH()-50},
frames:{
still:{ speed:2, frames:[0,1,2] },
hit:{speed:1,frames:[0,3]}
}
});
},
collisionEnabled:function() {
return !maingame.gameIsHold()&&!this.killed&&!this.invul;
},
kill:function(by){
/*
gbox.hitAudio("megaexplosion");
toys.generate.sparks.simple(this,"sparks",null,{animspeed:2,tileset:"explosion",accx:-2,accy:-2});
toys.generate.sparks.simple(this,"sparks",null,{animspeed:2,tileset:"explosion",accx:2,accy:-2});
toys.generate.sparks.simple(this,"sparks",null,{animspeed:2,tileset:"explosion",accx:-2,accy:2});
toys.generate.sparks.simple(this,"sparks",null,{animspeed:2,tileset:"explosion",accx:2,accy:2});
*/
this.killed=true;
this.respawntimer=20;
},
hitByBullet:function(by) { // ignore bullets if the ship is untouchable
if (this.collisionEnabled()) {
toys.shmup.hitByBullet(this,by);
this.makeInvulnerable(10);
} else return true;
},
first:function() {
// Counter
this.counter=(this.counter+1)%10;
if (!this.killed) {
toys.shmup.applyForces(this); // Apply forces
toys.shmup.controlKeys(this,{left:"left",right:"right",up:"up",down:"down"}); // Moves
toys.shmup.handleAccellerations(this);
toys.shmup.keepInBounds(this); // Keep the ship in his bounds
toys.shmup.setFrame(this); // set the right animation frame
if (this.invul) this.invul--; // the invulnerability counter
if (gbox.keyIsHit("a"))
this.fireBullet();
} else {
if (this.respawntimer) this.respawntimer--; else if (maingame.hud.getValue("lives","value")>0) {
maingame.hud.addValue("lives","value",-1);
if (maingame.hud.getValue("lives","value")==0) {
scroller.panToSpeed(0,5); // slow down the roller
maingame.playerDied({wait:10}); // trigger gameover
}
else maingame.newLife(); // respawn
}
}
},
blit:function() {
if (!this.killed) // show is not killed and invul is pair (so it blinks during invulnerability)
gbox.blitTile(gbox.getBufferContext(),{tileset:this.tileset,tile:this.frame,dx:this.x,dy:this.y,camera:this.camera,fliph:this.fliph,flipv:this.flipv,alpha:((this.invul%2)==0?1:0.5)});
}
});
}
gbox.go();
}
// BOOTSTRAP
gbox.onLoad(function () {
/*
tool.makecels({
rows:[
[
{img:"_bin/ship_1.png"},
{img:"_bin/ship_1_1.png"},
{img:"_bin/ship_1_2.png"},
{img:"_bin/ship_1.png",filter:{color:{r:255,g:255,b:255,a:255}}}
],
[
{img:"_bin/bullet_long1.png"},
{img:"_bin/bullet_long2.png"}
],
[
{img:"_bin/spark_1.png"},
{img:"_bin/spark_2.png"},
{img:"_bin/spark_3.png"}
],
[
{img:"_bin/explosion 1.png"},
{img:"_bin/explosion 2.png"},
{img:"_bin/explosion 3.png"},
{img:"_bin/explosion 4.png"},
{img:"_bin/explosion 5.png"},
{img:"_bin/explosion 6.png"}
],
[
{img:"_bin/bullet_small_1.png"},
{img:"_bin/bullet_small_2.png"}
],
[
{img:"_bin/enemy_1_1.png"},
{img:"_bin/enemy_1_2.png"},
{img:"_bin/enemy_1_1.png",filter:{color:{r:255,g:255,b:255,a:255}}}
],
[
{img:"_bin/enemy_2_1.png"},
{img:"_bin/enemy_2_2.png"},
{img:"_bin/enemy_2_3.png"},
{img:"_bin/enemy_2_1.png",filter:{color:{r:255,g:255,b:255,a:255}}}
],
[
{img:"_bin/boss_1.png"},
{img:"_bin/boss_1.png",filter:{color:{r:255,g:255,b:255,a:255}}}
],
[
{img:"_bin/powerup_1.png"},
{img:"_bin/powerup_2.png"}
],
[
{img:"_bin/ship_1_1_mini.png"}
],
[
{img:"_bin/solitude-commander_1_1.png"},
{img:"_bin/solitude-commander_1_2.png"},
{img:"_bin/solitude-commander_2_1.png"},
{img:"_bin/solitude-commander_2_2.png"},
{img:"_bin/solitude-commander_3_1.png"},
{img:"_bin/solitude-girl_1_1.png"},
{img:"_bin/solitude-girl_1_2.png"},
],
[
{img:"_bin/solitude-girl_2_1.png"},
{img:"_bin/solitude-girl_2_2.png"},
{img:"_bin/solitude-evil.png"},
]
]
});
return;*/
help.akihabaraInit({title:"Solitude",splash:{footnotes:["Musics by: AndyExpandy, Rich Vreeland, NE7.","Full credits on ending title."]}});
audioserver="resources/audio/";
gbox.addBundle({file:"resources/solitude/bundle.js"}); // Audio, sprites, fonts etc. are loaded here now. Cleaner code! Btw you can still load resources from the code, like in Capman.
// Have a look to the resource file. Solitude implements some sort of "resource unpacking" before using them.
gbox.loadAll(go);
}, false);
</script>
</html>