-
Notifications
You must be signed in to change notification settings - Fork 1
/
astro_ships_code.asm
323 lines (264 loc) · 9.63 KB
/
astro_ships_code.asm
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
//////////////////////////////////////////////////////////////////////////////
// astro_ships_code.asm
// Copyright(c) 2021 Neal Smith.
// License: MIT. See LICENSE file in root directory.
//////////////////////////////////////////////////////////////////////////////
#importonce
#import "../nv_c64_util/nv_c64_util_macs_and_data.asm"
#import "astro_sprite_data.asm"
#import "../nv_c64_util/nv_sprite_extra_code.asm"
#import "astro_vars_data.asm"
#import "../nv_c64_util/nv_sprite_raw_collisions_code.asm"
// max and min speed for ships when inc/dec speed
.const SHIP_MAX_SPEED = 5
.const SHIP_MIN_SPEED = -5
//////////////////////////////////////////////////////////////////////////////
// namespace with everything related to ship sprite
.namespace ship_1
{
.var info = nv_sprite_info_struct("ship_1", 0,
22, 50, 3, 1, // init x, y, VelX, VelY
sprite_ship,
sprite_extra,
1, 0, 1, 0, // bounce on top, left, bottom, right
0, 0, 75, 0, // min/max top, left, bottom, right
0, // sprite enabled
6, 4, 19, 16) // hitbox left, top, right, bottom
.var sprite_num = info.num
.label x_loc = info.base_addr + NV_SPRITE_X_OFFSET
.label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET
.label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET
.label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET
.label data_ptr = info.base_addr + NV_SPRITE_DATA_PTR_OFFSET
.label base_addr = info.base_addr
// the extra data that goes with the sprite
sprite_extra:
nv_sprite_extra_data(info)
// will be $FF (no collision) or sprite number of sprite colliding with
collision_sprite: .byte 0
// score for this ship in BCD
score: .word 0
LoadExtraPtrToRegs:
lda #>info.base_addr
ldx #<info.base_addr
rts
// subroutine to set the sprites location based on its address in extra block
SetLocationFromExtraData:
lda #>info.base_addr
ldx #<info.base_addr
jsr NvSpriteSetLocationFromExtra
rts
// subroutine to setup the sprite so that its ready to be enabled and displayed
Setup:
lda #>info.base_addr
ldx #<info.base_addr
jsr NvSpriteSetupFromExtra
rts
// subroutine to move the sprite in memory only (the extra data)
// this will not update the sprite registers to actually move the sprite, but
// to do that just call SetShipeLocFromMem
MoveInExtraData:
//lda #>info.base_addr
//ldx #<info.base_addr
//jsr NvSpriteMoveInExtra
//rts
nv_sprite_move_any_direction_sr(info)
Enable:
lda #>info.base_addr
ldx #<info.base_addr
nv_sprite_extra_enable_sr()
Disable:
lda #>info.base_addr
ldx #<info.base_addr
nv_sprite_extra_disable_sr()
// Accum must have MSB of new data_ptr
// X Reg must have LSB of new data_ptr
SetDataPtr:
{
stx data_ptr
sta data_ptr+1
// Accum: MSB of address of nv_sprite_extra_data
// X Reg: LSB of address of the nv_sprite_extra_data
lda #>info.base_addr
ldx #<info.base_addr
jsr NvSpriteSetDataPtrFromExtra
rts
}
LoadEnabledToA:
lda info.base_addr + NV_SPRITE_ENABLED_OFFSET
rts
SetBounceAllOn:
nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE)
SetWrapAllOn:
nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP)
//////////////////////////////////////////////////////////////////////////////
// subroutine to check for collisions with the ship (sprite 0)
CheckShipCollision:
lda sprite_collision_reg_value
//nv_debug_print_labeled_byte_mem(0, 0, temp_label, 10, sprite_collision_reg_value, true, false)
sta nv_a8
nv_sprite_raw_check_collision(info.num)
lda nv_b8
sta ship_1.collision_sprite
//jsr DebugShipCollisionSprite
rts
temp_label: .text @"coll reg: \$00"
DecVelX:
{
//nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_1.x_vel, true, false)
dec ship_1.x_vel // decrement ship speed
bpl DoneDecVelX // if its not zero yet then skip setting to max
inc ship_1.x_vel
DoneDecVelX:
rts
}
IncVelX:
{
//nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_1.x_vel, true, false)
lda ship_1.x_vel // decrement ship speed
cmp #SHIP_MAX_SPEED // if its not zero yet then skip setting to max
beq DoneIncVelX
inc ship_1.x_vel
DoneIncVelX:
rts
}
//////////////////////////////////////////////////////////////////////////////
// x and y reg have x and y screen loc for the char to check the sprite
// location against. it doesn't matter what character is at the location
// this just checks the location for overlap with sprite location
CheckOverlapChar:
nv_sprite_check_overlap_char(info, rect2)
rts
SetColorDead:
nv_sprite_set_raw_color_immed(sprite_num, NV_COLOR_GREY)
rts
SetColorAlive:
lda #>info.base_addr
ldx #<info.base_addr
nv_sprite_set_color_from_extra_sr()
label_vel_x_str: .text @"vel x: \$00"
rect1: .word $0000, $0000 // (left, top)
.word $0000, $0000 // (right, bottom)
rect2: .word $0000, $0000 // (left, top)
.word $0000, $0000 // (right, bottom)
}
//////////////////////////////////////////////////////////////////////////////
// namespace with everything related to ship sprite
.namespace ship_2
{
.var info = nv_sprite_info_struct("ship_2", 7, // sprite name, number
22, 210, 3, 1, // init x, y, VelX, VelY
sprite_ship,
sprite_extra,
1, 0, 1, 0, // bounce on top, left, bottom, right
200, 0, 0, 0, // min/max top, left, bottom, right
0, // sprite enabled
6, 4, 19, 16) // hitbox left, top, right, bottom
.var sprite_num = info.num
.label x_loc = info.base_addr + NV_SPRITE_X_OFFSET
.label y_loc = info.base_addr + NV_SPRITE_Y_OFFSET
.label x_vel = info.base_addr + NV_SPRITE_VEL_X_OFFSET
.label y_vel = info.base_addr + NV_SPRITE_VEL_Y_OFFSET
.label data_ptr = info.base_addr + NV_SPRITE_DATA_PTR_OFFSET
.label base_addr = info.base_addr
.label sprite_extra_addr = info.base_addr
// the extra data that goes with the sprite
sprite_extra:
nv_sprite_extra_data(info)
// will be $FF (no collision) or sprite number of sprite colliding with
collision_sprite: .byte 0
// score for this ship in BCD
score: .word 0
LoadExtraPtrToRegs:
lda #>info.base_addr
ldx #<info.base_addr
rts
// subroutine to set the sprites location based on its address in extra block
SetLocationFromExtraData:
lda #>info.base_addr
ldx #<info.base_addr
jsr NvSpriteSetLocationFromExtra
rts
// subroutine to setup the sprite so that its ready to be enabled and displayed
Setup:
lda #>info.base_addr
ldx #<info.base_addr
jsr NvSpriteSetupFromExtra
rts
// subroutine to move the sprite in memory only (the extra data)
// this will not update the sprite registers to actually move the sprite, but
// to do that just call SetShipeLocFromMem
MoveInExtraData:
//lda #>info.base_addr
//ldx #<info.base_addr
//jsr NvSpriteMoveInExtra
//rts
nv_sprite_move_any_direction_sr(info)
Enable:
lda #>info.base_addr
ldx #<info.base_addr
nv_sprite_extra_enable_sr()
Disable:
lda #>info.base_addr
ldx #<info.base_addr
nv_sprite_extra_disable_sr()
// Accum must have MSB of new data_ptr
// X Reg must have LSB of new data_ptr
SetDataPtr:
{
stx data_ptr
sta data_ptr+1
// Accum: MSB of address of nv_sprite_extra_data
// X Reg: LSB of address of the nv_sprite_extra_data
lda #>info.base_addr
ldx #<info.base_addr
jsr NvSpriteSetDataPtrFromExtra
rts
}
LoadEnabledToA:
lda info.base_addr + NV_SPRITE_ENABLED_OFFSET
rts
SetBounceAllOn:
nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_BOUNCE)
SetWrapAllOn:
nv_sprite_set_all_actions_sr(info, NV_SPRITE_ACTION_WRAP)
//////////////////////////////////////////////////////////////////////////////
// subroutine to check for collisions with the ship (sprite 0)
CheckShipCollision:
lda sprite_collision_reg_value
//nv_debug_print_labeled_byte_mem(0, 0, temp_label, 10, sprite_collision_reg_value, true, false)
sta nv_a8
nv_sprite_raw_check_collision(info.num)
lda nv_b8
sta ship_2.collision_sprite
rts
DecVelX:
{
//nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_2.x_vel, true, false)
dec ship_2.x_vel // decrement ship speed
bpl DoneShip2DecVelX // if its not zero yet then skip setting to max
inc ship_2.x_vel
DoneShip2DecVelX:
rts
}
IncVelX:
{
//nv_debug_print_labeled_byte_mem(10, 0, label_vel_x_str, 7, ship_2.x_vel, true, false)
lda ship_2.x_vel // decrement ship speed
cmp #SHIP_MAX_SPEED // if its not zero yet then skip setting to max
beq DoneShip2IncVelX
inc ship_2.x_vel
DoneShip2IncVelX:
rts
}
SetColorDead:
nv_sprite_set_raw_color_immed(sprite_num, NV_COLOR_GREY)
rts
SetColorAlive:
//lda #>info.base_addr
//ldx #<info.base_addr
//nv_sprite_set_color_from_extra_sr()
nv_sprite_set_raw_color_immed(sprite_num, NV_COLOR_BROWN)
rts
label_vel_x_str: .text @"vel x: \$00"
}