-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollision.asm
More file actions
89 lines (85 loc) · 2.59 KB
/
collision.asm
File metadata and controls
89 lines (85 loc) · 2.59 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
; Collisions detection
CHECK_PLR_COLLISION
lda $d01e
and #%00000001 ; Some HW detected collision with player sprite?
beq CHECK_PLR_COLLISION_EXIT ; No -> Exit.
jsr SPR_COLL_DETECT ; Check which sprite collided with player.
bne CHECK_PLR_SPRITE_01 ; If .X==$00 no collision detected (which is almost impossible...)
CHECK_PLR_COLLISION_EXIT
rts
CHECK_PLR_SPRITE_01
cpx #$01 ; Check if sprite X is in "collision area"
bne CHECK_PLR_SPRITE_02 ; No -> check next sprite
; Do something here...
rts
CHECK_PLR_SPRITE_02
cpx #$02
bne CHECK_PLR_SPRITE_03
; Do something here...
rts
CHECK_PLR_SPRITE_03
cpx #$03
bne CHECK_PLR_SPRITE_04
; Do something here...
rts
CHECK_PLR_SPRITE_04
cpx #$04
bne CHECK_PLR_SPRITE_05
; Do something here...
rts
CHECK_PLR_SPRITE_05
cpx #$05
bne CHECK_PLR_SPRITE_06
; Do something here...
rts
CHECK_PLR_SPRITE_06
cpx #$06
bne CHECK_PLR_SPRITE_07
; Do something here...
rts
CHECK_PLR_SPRITE_07
cpx #$07
bne CHECK_PLR_SPRITE_EXIT
; Do something here...
CHECK_PLR_SPRITE_EXIT
rts
;---------------------------------------
; Sprite collided detect
; If .X<>$00 = Sprite collided with player
; Plr = spr $00
; From $01 enemies sprites.
;-------------------
SPR_COLL_DETECT
jsr start_fly_eat
ldx #$07
SPR_COLL_LOOP
lda SPRITE_0_Y,X ; Load Enemy Y position
sec
sbc SPRITE_0_Y ; Subtract Player Y position
bpl CHECK_Y_NO_MINUS
eor #$FF ; Invert result sign
CHECK_Y_NO_MINUS
cmp #$15 ; Check for enemy sprite distance Y
bcs CHECK_PLR_NO_COLL
lda SPRITE_0_X,X ; Load Enemy X position
sec
sbc SPRITE_0_X ; Subtract Player X position
bpl CHECK_NO_MINUS
eor #$FF ; Invert result sign
CHECK_NO_MINUS
cmp #$17 ; Check for enemy sprite distance X
lda SPRITEMSB
eor SPRITEMSB,X
sbc #$00
bcs CHECK_PLR_NO_COLL
rts
CHECK_PLR_NO_COLL
dex ; Goes to next sprite/enemy
bne SPR_COLL_LOOP
rts
;---------------------------------------
; Sprites data tables examples
;-------------------
SPRITEMSB
BYTE $00, $00, $00, $00, $00, $00, $00, $00
;-------------------------------------------------------------------------------