-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmode.ts
159 lines (127 loc) · 4.36 KB
/
mode.ts
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
namespace asteroids {
export class GameModeHandler extends Sprite {
protected input: InputHandler;
constructor() {
super();
}
activated() {
Game.Instance.setInputHandler(this.input);
}
deactivated() {
}
update(force = false) {
this.input && this.input.update();
}
}
export class SplashMode extends GameModeHandler {
private lblPressStart: TextSprite;
private lblCoinPlay: TextSprite;
constructor() {
super();
this.lblPressStart = new TextSprite("PUSH START");
this.lblPressStart.xfrm.pos.y = Fx.add(Game.TOP_EDGE, Fx8(20));
this.lblPressStart.horzJust = HorizontalJustification.Center;
this.lblPressStart.vertJust = VerticalJustification.Top;
this.lblCoinPlay = new TextSprite("1 COIN 1 PLAY");
this.lblCoinPlay.xfrm.pos.y = Fx.sub(Game.BOTTOM_EDGE, Fx8(20));
this.lblCoinPlay.horzJust = HorizontalJustification.Center;
this.input = new InputHandler();
this.input.onReleased(Button.A, () => Game.Instance.startGame());
}
activated() {
super.activated();
Game.Instance.shipEnabled = false;
Game.Instance.rocksEnabled = true;
}
update(force = false) {
super.update(force);
this.lblPressStart.visible = (control.millis() % 900) > 450;
this.lblPressStart.update();
this.lblCoinPlay.update();
}
draw(offset: Vec2) {
this.lblPressStart.draw(offset);
this.lblCoinPlay.draw(offset);
}
}
export class StartPlayMode extends GameModeHandler {
private lblPlayer1: TextSprite;
constructor() {
super();
this.lblPlayer1 = new TextSprite("PLAYER 1");
this.lblPlayer1.xfrm.pos.y = Fx.add(Game.TOP_EDGE, Fx8(20));
this.lblPlayer1.horzJust = HorizontalJustification.Center;
this.lblPlayer1.vertJust = VerticalJustification.Top;
}
activated() {
super.activated();
Game.Instance.shipEnabled = false;
Game.Instance.rocksEnabled = false;
}
update(force = false) {
super.update(force);
this.lblPlayer1.update();
}
draw(offset: Vec2) {
this.lblPlayer1.draw(offset);
}
}
export class GameplayMode extends GameModeHandler {
constructor() {
super();
this.input = new InputHandler();
this.input.onDown(Button.Left, () => this.rotateLeft());
this.input.onDown(Button.Right, () => this.rotateRight());
this.input.onDown(Button.Up, () => this.thrust());
this.input.onPressed(Button.A, () => this.fire());
this.input.onPressed(Button.B, () => this.hyperspace());
}
rotateLeft() {
Game.Instance.ship.rotateLeft();
}
rotateRight() {
Game.Instance.ship.rotateRight();
}
thrust() {
Game.Instance.ship.thrust();
}
fire() {
Game.Instance.ship.fire();
}
hyperspace() {
Game.Instance.ship.hyperspace();
}
activated() {
super.activated();
Game.Instance.shipEnabled = true;
Game.Instance.rocksEnabled = true;
}
update(force = false) {
super.update(force);
}
draw(offset: Vec2) {
}
}
export class GameOverMode extends GameModeHandler {
private lblGameOver: TextSprite;
constructor() {
super();
this.lblGameOver = new TextSprite("GAME OVER");
this.lblGameOver.xfrm.pos.y = Fx.add(Game.TOP_EDGE, Fx8(20));
this.lblGameOver.horzJust = HorizontalJustification.Center;
this.lblGameOver.vertJust = VerticalJustification.Top;
}
activated() {
super.activated();
Game.Instance.shipEnabled = false;
Game.Instance.rocksEnabled = true;
}
update(force = false) {
super.update(force);
this.lblGameOver.update();
}
draw(offset: Vec2) {
this.lblGameOver.draw(offset);
}
}
}