-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameBullets.asm
More file actions
533 lines (430 loc) · 13.3 KB
/
Copy pathgameBullets.asm
File metadata and controls
533 lines (430 loc) · 13.3 KB
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
; Sprite top left corner to char coordinates:
; int((spr_x-24)/8), int((spr_y-50)/8)
;===============================================================================
; Constants
BulletsMax = 6
Bullet1stCharacter = 123
Temp1stCharacter = 245
BulletMaxLife = 32
;===============================================================================
; Variables
bulletsXHighCurrent byte 0
bulletsXLowCurrent byte 0
bulletsYCurrent byte 0
bulletsXCharCurrent byte 0
;bulletsXOffsetCurrent byte 0
bulletsYCharCurrent byte 0
;bulletsColorCurrent byte 0
bulletsVelXCurrent byte 0
;bulletsVelYCurrent byte 0
bulletsOldCharCurrent byte 0
;bulletsOldColorCurrent byte 0
;bulletsOldToggleCurrent byte 0
;bulletIndexCurrent byte 0
bulletDestCharCurrent byte 0
bulletSourceCharCurrent byte 0
;bulletLifetimeCurrent byte 0
bulletsSpriteFrame dcb BulletsMax, 0
bulletsActive dcb BulletsMax, 0
bulletsSource dcb BulletsMax, 255
bulletsXChar dcb BulletsMax, 0
bulletsYChar dcb BulletsMax, 0
bulletsXHigh dcb BulletsMax, 0
bulletsXLow dcb BulletsMax, 0
bulletsY dcb BulletsMax, 0
bulletsXOffset dcb BulletsMax, 0
;bulletsColor dcb BulletsMax, 0
bulletsVelX dcb BulletsMax, 0
bulletsVelY dcb BulletsMax, 0
bulletsOldChar dcb BulletsMax, 0
;bulletsOldColor dcb BulletsMax, 0
bulletsOldToggle dcb BulletsMax, 0
bulletsLifetime dcb BulletsMax, 0
bulletsXFlag byte 0
bulletsYFlag byte 0
bulletsXCharCol byte 0
bulletsYCharCol byte 0
bulletsSourceCol byte 255
bulletsSourceCheck byte 0
;===============================================================================
; Macros/Subroutines
defm GAMEBULLETS_FIRE_AAAVAAAA ; /1 = X position high byte(Address)
; /2 = X position low byte (Address)
; /3 = Y position (Address)
; /4 = Color (Value)
; /5 = X velocity
; /6 = Y velocity
; /7 = Source Sprite (Address)
; /8 = Sprite Frame (Address)
ldx #0
@loop
lda bulletsActive,X
bne @skip
; save the current bullet in the list
lda #1
sta bulletsActive,X
lda /1
sta bulletsXHigh,X
lda /2
sta bulletsXLow,X
lda /3
sta bulletsY,X
;lda #/4
;sta bulletsColor,X
lda /5
sta bulletsVelX,X
lda /6
sta bulletsVelY,X
lda /7
sta bulletsSource,X
lda /8
sta bulletsSpriteFrame,X
lda #0
;sta bulletsOldChar,X
;sta bulletsOldColor,X
sta bulletsLifetime,X
jsr gameBulletsFireGet
jsr gameBulletsBackup
; found a slot, quit the loop
jmp @found
@skip
; loop for each bullet
inx
cpx #BulletsMax
bne @loop
@found
stx screenDebugZero
endm
;===============================================================================
gameBulletsFireGet
;lda bulletsLifetime,X
;sta bulletLifetimeCurrent
lda bulletsXHigh,X
sta bulletsXHighCurrent
lda bulletsXLow,X
sta bulletsXLowCurrent
lda bulletsY,X
sta bulletsYCurrent
lda bulletsOldChar,X
sta bulletsOldCharCurrent
LIBSCREEN_PIXELTOCHAR_AAVAVAA bulletsXHighCurrent, bulletsXLowCurrent, 16, bulletsYCurrent, 40, bulletsXCharCurrent, bulletsYCharCurrent
lda bulletsXCharCurrent
sta bulletsXChar,X
lda bulletsYCharCurrent
sta bulletsYChar,X
rts
gameBulletsGet
;lda bulletsLifetime,X
;sta bulletLifetimeCurrent
lda bulletsXHigh,X
sta bulletsXHighCurrent
lda bulletsXLow,X
sta bulletsXLowCurrent
lda bulletsY,X
sta bulletsYCurrent
;lda bulletsColor,X
;sta bulletsColorCurrent
lda bulletsVelX,X
sta bulletsVelXCurrent
;lda bulletsVelY,X
;sta bulletsVelYCurrent
lda bulletsOldChar,X
sta bulletsOldCharCurrent
;lda bulletsOldColor,X
;sta bulletsOldColorCurrent
;lda bulletsOldToggle,X
;sta bulletsOldToggleCurrent
;stx bulletIndexCurrent
lda bulletsXChar,X
sta bulletsXCharCurrent
lda bulletsYChar,X
sta bulletsYCharCurrent
rts
;===============================================================================
gameBulletsBackup
lda screenTwoActive
sta bulletsOldToggle,X
beq @setSecondary
LIBSCREEN_TWO_SETCHARPOSITION_AA bulletsXCharCurrent, bulletsYCharCurrent
jmp @setDone
@setSecondary
LIBSCREEN_SETCHARPOSITION_AA bulletsXCharCurrent, bulletsYCharCurrent
@setDone
lda (ZeroPageLow),Y
sta bulletsOldChar,X
sta bulletsOldCharCurrent
LIBSCREEN_SETCHAR_A bulletDestCharCurrent ;bulletsXOffsetCurrent
rts
;===============================================================================
gameBulletsRestore
lda screenTwoActive
cmp bulletsOldToggle,X
bne @skipRestore
lda screenTwoActive
beq @resetSecondary
LIBSCREEN_TWO_SETCHARPOSITION_AA bulletsXCharCurrent, bulletsYCharCurrent
jmp @resetDone
@resetSecondary
LIBSCREEN_SETCHARPOSITION_AA bulletsXCharCurrent, bulletsYCharCurrent
@resetDone
LIBSCREEN_SETCHAR_A bulletsOldCharCurrent
;LIBSCREEN_SETCOLORPOSITION_AA bulletsXCharCurrent, bulletsYCharCurrent
;LIBSCREEN_SETCHAR_A bulletsOldColorCurrent
@skipRestore
rts
;===============================================================================
gameBulletsUpdate
ldx #0
buloop
lda bulletsActive,X
bne buok
jmp skipBulletUpdate
buok
; get the current bullet from the list
jsr gameBulletsGet
jsr gameBulletsRestore
; apply vertical velocity
clc
lda bulletsYCurrent
adc bulletsVelY,X
sta bulletsYCurrent
sta bulletsY,X
; apply horizontal velocity
lda bulletsSpriteFrame,X
cmp #13
bcs @leftMove
@rightMove
LIBMATH_ADD16BIT_AAVAAA bulletsXHighCurrent, BulletsXLowCurrent, 0, bulletsVelXCurrent, bulletsXHighCurrent, BulletsXLowCurrent
jmp @doneMove
@leftMove
LIBMATH_SUB16BIT_AAVAAA bulletsXHighCurrent, BulletsXLowCurrent, 0, bulletsVelXCurrent, bulletsXHighCurrent, BulletsXLowCurrent
@doneMove
lda bulletsXHighCurrent
sta bulletsXHigh,X
lda bulletsXLowCurrent
sta bulletsXLow,X
LIBSCREEN_PIXELTOCHAR_AAVAVAA bulletsXHighCurrent, bulletsXLowCurrent, 16, bulletsYCurrent, 40, bulletsXCharCurrent, bulletsYCharCurrent
lda bulletsYCharCurrent
cmp #1
bcc @deadBullet
cmp #22
bcs @deadBullet
lda bulletsXCharCurrent
cmp #1
bcc @deadBullet
cmp #39
bcs @deadBullet
lda bulletsLifetime,X
cmp #BulletMaxLife
beq @deadBullet
inc bulletsLifetime,X
jmp @dirdone
@deadBullet
lda #0
sta bulletsActive,X
lda #255
sta bulletsSource,X
jmp skipBulletUpdate
@dirdone
; set the bullet color
;LIBSCREEN_SETCOLORPOSITION_AA bulletsXCharCurrent, bulletsYCharCurrent
;lda (ZeroPageLow),Y
;sta bulletsOldColor,X
;LIBSCREEN_SETCHAR_A bulletsColorCurrent
; set the bullet character
clc
txa
adc #Temp1stCharacter
sta bulletDestCharCurrent
jsr gameBulletsBackup
lda bulletsYCharCurrent
sta bulletsYChar,X
cmp #12
bcc @scrollBackground
lda screenScrollXValue
jmp @scrollScreen
@scrollBackground
lda backgroundScrollXValue
@scrollScreen
lsr
adc #Bullet1stCharacter
sta bulletSourceCharCurrent
GAMEBULLETS_BLEND_AAA bulletsOldCharCurrent, bulletSourceCharCurrent, bulletDestCharCurrent
lda bulletsXCharCurrent
sta bulletsXChar,X
skipBulletUpdate
inx
cpx #BulletsMax
beq @finished
jmp buloop
@finished
rts
;===============================================================================
defm GAMEBULLETS_BLEND_AAA ; /1 = Source char index (Address)
; /2 = Blend char index (Address)
; /3 = Dest char index (Address)
inc EXTCOL
lda /1
sta ZeroPageParam1
lda /2
sta ZeroPageParam2
lda /3
sta ZeroPageParam3
stx ZeroPageParam4
jsr gameBulletsBlend
ldx ZeroPageParam4
dec EXTCOL
endm
gameBulletsBlend
; load base char
ldx ZeroPageParam1
lda CharRAMLow,X ; load low address byte
sta ZeroPageLow
;sta screenDebugZero
lda CharRAMHigh,X ; load high address byte
sta ZeroPageHigh
;sta screenDebugOne
; load additional char
ldx ZeroPageParam2
lda CharRAMLow,X ; load low address byte
sta ZeroPageLow2
lda CharRAMHigh,X ; load high address byte
sta ZeroPageHigh2
; target character
ldx ZeroPageParam3
lda CharRAMLow,X ; load low address byte
sta ZeroPageLow3
;sta screenDebugZero
lda CharRAMHigh,X ; load high address byte
sta ZeroPageHigh3
;sta screenDebugOne
; bullets use only the two middle rows of a char, so no need to blend the other bytes
ldy #0
lda (ZeroPageLow),Y
;ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
ldy #1
lda (ZeroPageLow),Y
;ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
ldy #2
lda (ZeroPageLow),Y
;ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
ldy #3
lda (ZeroPageLow),Y
ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
ldy #4
lda (ZeroPageLow),Y
ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
ldy #5
lda (ZeroPageLow),Y
;ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
ldy #6
lda (ZeroPageLow),Y
;ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
ldy #7
lda (ZeroPageLow),Y
;ora (ZeroPageLow2),Y
sta (ZeroPageLow3),Y
rts
;===============================================================================
defm GAMEBULLETS_COLLIDED_AAAV ; /1 = XChar (Address)
; /2 = YChar (Address)
; /3 = Check sprite (Address)
lda /1
sta bulletsXCharCol
lda /2
sta bulletsYCharCol
lda /3
sta bulletsSourceCol
jsr gameBullets_Collided
endm
gameBullets_Collided
ldx #0
@loop
; skip this bullet if not active
lda bulletsActive,X
cmp #0
beq @skip
; skip this bullet if from current sprite
lda bulletsSource,X
cmp bulletsSourceCol
beq @skip
lda #0
sta bulletsYFlag
; skip if currentbullet YChar != YChar
ldy bulletsYChar,X
cpy bulletsYCharCol
bne @yminus1
lda #1
sta bulletsYFlag
jmp @doneYCheck
@yminus1
; skip if currentbullet YChar-1 != YChar
;dey
;cpy bulletsYCharCol
;bne @yplus1
;lda #1
;sta bulletsYFlag
;jmp @doneYCheck
@yplus1
; skip if currentbullet YChar+1 != YChar
;iny
;iny
;cpy bulletsYCharCol
;bne @doneYCheck
;lda #1
;sta bulletsYFlag
@doneYCheck
lda bulletsYFlag
beq @skip
lda #0
sta bulletsXFlag
; skip if currentbullet XChar != XChar
ldy bulletsXChar,X
cpy bulletsXCharCol
bne @xminus1
lda #1
sta bulletsXFlag
jmp @doneXCheck
@xminus1
; skip if currentbullet XChar-1 != XChar
;dey
;cpy bulletsXCharCol
;bne @xplus1
;lda #1
;sta bulletsXFlag
;jmp @doneXCheck
@xplus1
; skip if currentbullet XChar+1 != XChar
;iny
;iny
;cpy bulletsXCharCol
;bne @doneXCheck
;lda #1
;sta bulletsXFlag
@doneXCheck
lda bulletsXFlag
beq @skip
; collided
lda #0
sta bulletsActive,X ; disable bullet
jsr gameBulletsGet
; why is this here?
jsr gameBulletsRestore
lda #1 ; set as collided
jmp @collided
@skip
; loop for each bullet
inx
cpx #BulletsMax
bne @loop
; set as not collided
lda #0
@collided
rts