-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy_death.asm
152 lines (128 loc) · 3.09 KB
/
enemy_death.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
enemy_accelerates_upwards: subroutine
inc enemy_ram_ac,x
lda enemy_ram_ac,x
lsr
lsr
lsr
sta enemy_ram_y,x
lda oam_ram_y,y
sec
sbc enemy_ram_y,x
cmp #sprite_0_y
rts
crossbones_cycle: subroutine
jsr enemy_accelerates_upwards
bcs .crossbones_death
sta oam_ram_y,y
lda #$c1
sta oam_ram_spr,y
lda #$03
sta oam_ram_att,y
bne .crossbones_done
.crossbones_death
lda sfx_noi_counter
bne .die_already
jsr sfx_ghost_snare
.die_already
jsr enemy_clear
.crossbones_done
jmp update_enemies_handler_next
clear_all_enemies: subroutine
; clears all enemy ram
ldx #$f0
lda #$00
.enemy_loop
dex
sta enemy_ram_type,x
bne .enemy_loop
; clears all enemy sprites
lda #$ff
ldx #$20
.sprite_loop
sta $0200,x
inx
bne .sprite_loop
rts
enemy_clear: subroutine
; clear OAM data
ldy enemy_oam_offset
lda #$ff
ldx #$03
.enemy_oam_loop
sta oam_ram_y,y
iny
dex
bne .enemy_oam_loop
; clear enemy data
ldx enemy_ram_offset
lda #$00
ldy #$06 ; 7 would clear _ex
.enemy_ram_loop
sta enemy_ram_type,x
inx
dey
bne .enemy_ram_loop
; enemy_ram_ex is allowed to carry over
; entities using _ex should set it on spawn
rts
enemy_death_handler: subroutine
; requires
; enemy_ram_offset
; enemy_oam_offset
; don't handle a non entity
ldx enemy_ram_offset
lda enemy_ram_type,x
beq .done
inc player_frag_counter
; track deaths of phase spawns
ldy enemy_slot_id
lda phase_spawn_table,y
beq .not_phase_spawn
lda #$00
sta phase_spawn_table,y
dec phase_kill_counter
; if less than 0 set to 0
bpl .not_phase_spawn
sta phase_kill_counter
.not_phase_spawn
ldx enemy_ram_offset
ldy enemy_oam_offset
; 4 sprite cleanup
cpx #$a0
bcc .dont_cleanup_4_sprite
lda #$04 ; move first sprite over 4 pixels
clc
adc oam_ram_x,y
sta oam_ram_x,y
lda #$04 ; move first sprite down 4 pixels
clc
adc oam_ram_y,y
sta oam_ram_y,y
; move other sprites off screen
lda #$ff
sta oam_ram_y+4,y
sta oam_ram_y+8,y
sta oam_ram_y+12,y
bne .check_for_powerup_drop
.dont_cleanup_4_sprite
; 2 sprite cleanup
cpx #$80
bcc .dont_cleanup_2_sprite
lda #$ff
sta oam_ram_y+4,y
.dont_cleanup_2_sprite
.check_for_powerup_drop
; starglasses
lda enemy_ram_type,x
cmp #starglasses_id
bne .not_starglasses
; spawn powerup
jmp powerup_from_starglasses
.not_starglasses
jsr sfx_enemy_death
; change it into crossbones!
lda #crossbones_id
sta enemy_ram_type,x
sta enemy_ram_ac,x
.done
rts