-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridcommander.p8
244 lines (200 loc) · 5.32 KB
/
gridcommander.p8
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
%import syslib
%import textio
%import base
%import colors
%import charset
%import title
%import gamescreen
%import ship
%import snake
%import explosion
main {
; main variables
uword score
ubyte current_stage
ubyte player_lives
uword wave_ticks
; player move variables
ubyte player_speed = 4
ubyte player_sub_counter
; bullet move variables
ubyte bullet_frequency ; Controll frequency between shots
ubyte bullet_speed = 2
ubyte bullet_sub_counter
; remains move variables
ubyte remains_speed = 3
ubyte remains_sub_counter
; bomb move variables
ubyte bomb_speed = 2
ubyte bomb_sub_counter
; enemy move variables
ubyte enemy_speed = 6
ubyte enemy_sub_counter
; explosion animation variable
const ubyte ANIMATION_SPEED = 5
ubyte animation_sub_counter
sub start() {
base.platform_setup()
charset.load()
repeat {
game_title()
game_loop()
game_end()
}
}
sub game_title() {
title.draw()
; usage.setup() ; Add control info etc. here maybe
; Add startup delay to prevent "start" button press from
; immediately trigger start of game
sys.wait(50)
wait_key( 32, ">>> press start or space to begin <<<", 1, 23,
&colors.o_pulse, 1);
}
sub game_loop() {
gamescreen.init()
; Use to identify diagonal movement since this need to be "slower" for
; diagonal movement feel natural.
ubyte move_count
player_lives = 3
score = 0
current_stage = 0
bullet_frequency = 0
player_sub_counter = 0
bullet_sub_counter = 0
enemy_sub_counter = 0
remains_sub_counter = 0
bomb_sub_counter = 0
ship.init()
bullets.init()
snake.init()
remains.init()
drop_bomb.init()
snake.create_snake()
repeat {
ubyte time_lo = lsb(cbm.RDTIM16())
; May needed to find a better timer
if time_lo >= 1 {
cbm.SETTIM(0,0,0)
wave_ticks++
; Move bullets
bullet_sub_counter++
if bullet_sub_counter == bullet_speed {
bullets.move()
bullet_sub_counter = 0
}
; Move remains
remains_sub_counter++
if remains_sub_counter == remains_speed {
remains.do_countdowns()
remains_sub_counter = 0
}
; Move bombs
bomb_sub_counter++
if bomb_sub_counter == bomb_speed {
drop_bomb.move()
bomb_sub_counter = 0
}
; Player movement
player_sub_counter++
move_count = 0
if player_sub_counter == player_speed {
; Check joystick
joystick.pull_info()
if joystick.pushing_fire() {
if bullet_frequency == 0 {
ship.fire()
bullet_frequency = 3
} else
bullet_frequency--
}
; This joystick code isn't very efficient when we can move in
; both planes. At worst all 4 calls may be called. Consider
; rewrite that returns single value (joystick.direction_value)
; and use array to look up delay counter and x/y movements.
if joystick.pushing_left() {
ship.left()
move_count++
} else if joystick.pushing_right() {
ship.right()
move_count++
}
if joystick.pushing_up() {
ship.up()
move_count++
} else if joystick.pushing_down() {
ship.down()
move_count++
}
; Check keyboard
ubyte key = cbm.GETIN2()
when key {
'w' -> ship.up()
'd' -> ship.right()
's' -> ship.down()
'a' -> ship.left()
' ' -> ship.fire()
}
; Reduce move counter if we are moving in one plane only, we
; don't want have diagonal movement faster
if ( move_count == 1) {
player_sub_counter = 1
} else {
player_sub_counter = 0
}
}
; Enemy movement
enemy_sub_counter++
if enemy_sub_counter == enemy_speed {
snake.move_all()
enemy_sub_counter = 0
}
; Animate explosions
animation_sub_counter++
if animation_sub_counter == ANIMATION_SPEED {
animation_sub_counter = 0
explosion.animate()
}
; End game check (just for initial test)
if score == 100
return
}
}
}
sub game_end() {
}
sub wait_key(ubyte key, uword strRef, ubyte x, ubyte y,
uword colorRef, ubyte do_usage) {
ubyte time_lo = lsb(cbm.RDTIM16())
ubyte color = 0
ubyte inp = 0
while inp != key {
inp = cbm.GETIN2()
if time_lo >= 2 {
cbm.SETTIM(0,0,0)
write( colorRef[color], x, y, strRef )
color++
if color == colors.PULSE_SIZE {
color = 0
; if do_usage
; usage.draw()
}
}
; Let's also check joystick start (up)
joystick.pull_info()
if joystick.pushing_up()
return
time_lo = lsb(cbm.RDTIM16())
}
}
sub write(ubyte color, ubyte x, ubyte y, uword messageptr) {
txt.color(color)
txt.plot( x, y )
txt.print( messageptr )
}
sub add_score(uword points) {
score += points
; Add new life counter?
gamescreen.printScore()
}
}