-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
89 lines (74 loc) · 1.96 KB
/
main.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
import './lib/playground.js';
import Game from './states/game.js';
import TextState from './states/text.js'
const Help = TextState([
"Move - WASD/Arrows or Left Stick",
"Aim - Mouse or Right Stick",
"Shoot - Left Mouse or Right Trigger",
"Toggle Sound - M",
"",
"Enemies drop food, bring it to 3-eyes",
"",
"Press enter, space or start", "to continue."
], 'start');
const Start = TextState([
"Keep 3-eyes alive!",
"Protect and feed it!",
"",
"Press enter, space or start", "to start.",
"",
"F1 anytime for controls."
], 'start');
const Lost = TextState([
"Aw, you lost.",
"",
"Press enter, space or start", "to restart."
], 'restart');
const Won = TextState([
"Yay, you won!",
"",
"Press enter, space or start", "to restart."
], 'restart');
const app = playground({
preload: function() { },
create: function() {
this.layer.canvas.id = 'game';
this.loadSounds("shoot.wav", "boom.wav", "bigBoom.wav", "hit.wav", "hit2.wav");
this.sound.alias('shoot_s', 'shoot', 0.2, 1);
this.sound.alias('boom_s', 'boom', 0.2, 1);
this.sound.alias('bigBoom_s', 'bigBoom', 0.2, 1);
this.sound.alias('hit_s', 'hit', 0.1, 1);
this.sound.alias('hit2_s', 'hit2', 0.2, 1);
},
ready: function() {
this.setState(Start)
},
resize: function() { },
step: function(dt) { },
render: function(dt) { },
createstate: function() { },
enterstate: function() { },
leavestate: function() { },
keydown: function(data) {
if( data.key === "f1"){
this.help();
}
},
//custom functions
help: function(){
this.setState(Help);
},
loose: function(){
this.setState(Lost);
},
win: function(){
this.setState(Won);
},
start: function(){
this.setState(Game);
},
restart: function(){
Game.create();
this.setState(Game);
}
});