This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscreens.js
364 lines (264 loc) · 6.67 KB
/
screens.js
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* -----
gameScreens
------ */
/*---------------------------------------------------------------------
A title screen
--------------------------------------------------------------------- */
// create a basic GUI Object
var myButton = me.GUI_Object.extend(
{
init:function(x, y)
{
settings = {}
settings.image = "main_fish";
settings.spritewidth = 64;
settings.spriteheight = 64;
// parent constructor
this.parent(x, y, settings);
},
// output something in the console
// when the object is clicked
onClick:function()
{
console.log("clicked!");
// don't propagate the event
return true;
}
});
var TitleScreen = me.ScreenObject.extend(
{
init : function()
{
this.parent(true);
// title screen image
this.title = null;
this.font = null;
this.floating = true;
},
/* ---
reset function
----*/
onResetEvent : function()
{
if (this.title == null)
{
// init stuff if not yet done
this.title = me.loader.getImage("title");
// font to display the menu items
this.font = new me.BitmapFont("kromasky_16x16", 16, 2);
this.font.set("left");
}
me.game.add(new me.ImageLayer("sea-back1", 0,0, "sea-back1", 1, 0.25));
me.game.add(new me.ImageLayer("sea-back2", 0,0, "sea-back2", 2, 0.35));
me.game.add(new me.ImageLayer("sea-back3", 0,0, "sea-back3", 3, 0.45));
// add the object at pos (10,10), z index 4
//me.game.add((new myButton(10,10)),4);
me.game.sort();
// enable the keyboard
me.input.bindKey(me.input.KEY.ENTER, "enter", true);
},
/*---
update function
---*/
update : function()
{
// enter pressed ?
if (me.input.isKeyPressed('enter'))
{
me.state.change(me.state.READY);
}
// change the viewport pos to scroll the background :)
me.game.viewport.pos.x+=1;
return true;
},
/*---
the manu drawing function
---*/
draw : function(context)
{
context.drawImage(this.title,0,40);
this.font.draw (context, "PRESS ENTER", 140, 395);
},
/*---
the manu drawing function
---*/
onDestroyEvent : function()
{
me.input.unbindKey(me.input.KEY.ENTER);
},
});
/*---------------------------------------------------------------------
A level complete screen
--------------------------------------------------------------------- */
GameOverScreen = me.ScreenObject.extend(
{
init : function()
{
this.parent(true); // next state
this.font = null;
this.background = null;
this.saveScore = false;
},
/* ---
reset function
----*/
onResetEvent : function(levelId)
{
if (this.font == null)
{
// font to display the menu items
this.font4x = new me.BitmapFont("kromasky_16x16", 16);
this.font4x.set("left",4);
this.font2x = new me.BitmapFont("kromasky_16x16", 16);
this.font2x.set("left",2);
}
this.scale = 4.0;
this.saveScore = false;
// create a new canvas
this.background = me.video.applyRGBFilter(me.video.getScreenCanvas(), "b&w");
me.input.bindKey(me.input.KEY.ENTER, "enter");
me.input.bindKey(me.input.KEY.ESC, "esc");
// game over sound
me.audio.play("gameover");
},
/*---
update function
---*/
update : function()
{
if (this.scale > 1.0)
{
this.scale -= 0.1;
}
else
{
/*
if (!this.saveScore)
{
try
{
//save our score
tapjsHighScores.save(me.gamestat.getItemValue("hiscore"), "", "no");
}
catch(e){};
this.saveScore = true;
}
*/
if (me.input.isKeyPressed('enter'))
{
me.state.change(me.state.PLAY);
}
else if (me.input.isKeyPressed('esc'))
{
me.state.change(me.state.MENU);
}
}
return true;
},
/*---
the manu drawing function
---*/
draw : function(context)
{
// draw the background
context.drawImage(this.background.canvas, 0, 0);
// save the current context
context.save();
// scale and keep centered
if (this.scale != 1.0)
me.video.scale(context, this.scale);
this.font4x.draw (context, "GAME OVER!", 5, 220);
// restore context
context.restore();
if (this.scale <= 1.0)
{
this.font2x.draw (context, "PRESS ENTER TO RETRY", 1, 300);
}
},
/*---
the manu drawing function
---*/
onDestroyEvent : function()
{
me.input.unbindKey(me.input.KEY.ENTER);
me.input.unbindKey(me.input.KEY.ESC);
}
});
/*---------------------------------------------------------------------
A credit screen
--------------------------------------------------------------------- */
InstructionScreen = me.ScreenObject.extend(
{
init : function()
{
this.parent(true); // next state
this.font = null;
this.titlefont = null;
this.floating = true;
},
/* ---
reset function
----*/
onResetEvent : function()
{
if (this.title == null)
{
// font to display the menu items
this.titlefont = new me.BitmapFont("kromasky_16x16", 16, 2);
this.titlefont.set("left");
// font to display the menu items
this.font = new me.BitmapFont("kromasky_16x16", 16, 1.5);
this.font.set("left");
}
// add the parallax background
me.game.add(new me.ImageLayer("sea-back1", 0,0, "sea-back1", 1, 0.25));
me.game.add(new me.ImageLayer("sea-back2", 0,0, "sea-back2", 2, 0.35));
me.game.add(new me.ImageLayer("sea-back3", 0,0, "sea-back3", 3, 0.45));
// enable the keyboard
me.input.bindKey(me.input.KEY.ENTER, "enter", true);
me.input.bindKey(me.input.KEY.ESC, "esc");
},
/*---
update function
---*/
update : function()
{
// enter pressed ?
if (me.input.isKeyPressed('enter'))
{
// switch back to menu
me.state.change(me.state.PLAY);
}
else if (me.input.isKeyPressed('esc'))
{
me.state.change(me.state.MENU);
}
// change the viewport pos to scroll the background :)
me.game.viewport.pos.x+=0.5;
return true;
},
/*---
the manu drawing function
---*/
draw : function(context)
{
this.titlefont.draw (context, "INSTRUCTIONS :", 100 , 10);
this.titlefont.draw (context, "--------------", 100 , 32);
this.titlefont.draw (context, "KEYS :", 100 , 100);
this.font.draw (context, "* ARROWS TO MOVE ", 100, 148);
this.font.draw (context, "* PRESS E TO EAT ", 100, 196);
this.font.draw (context, "* PRESS F TO FART", 100, 244);
this.titlefont.draw (context, "GOAL :", 100 , 300);
this.font.draw (context, "EAT AS MUCH AS YOU", 100, 348);
this.font.draw (context, "CAN, AVOID THE JELLY",100, 396);
this.font.draw (context, "FISH * * *", 100, 440);
},
/*---
the drawing function
---*/
onDestroyEvent : function()
{
me.input.unbindKey(me.input.KEY.ENTER);
me.input.unbindKey(me.input.KEY.ESC);
},
});