-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy_zigzag.asm
84 lines (77 loc) · 1.82 KB
/
enemy_zigzag.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
; pattern counter holds direction index 0..3
zigzag_dir_table:
; r/u l/u l/d r/d
byte #$03, #$09, #$0f, #$15
zigzag_att_table:
; r/u l/u l/d r/d
byte #$83, #$c3, #$43, #$03
zigzag_spawn: subroutine
; set direction
jsr get_next_random
lsr
and #$03
sta enemy_ram_pc,x
stx temp00
tax
lda zigzag_dir_table,x
ldx temp00
sta enemy_ram_ex,x
; set position
jmp enemy_spawn_set_x_y_rng
zigzag_cycle: subroutine
lda #$08
sta collision_0_w
sta collision_0_h
jsr enemy_handle_damage_and_death
lda wtf
and #$03
bne .dont_reset_ac
; animation
dec enemy_ram_ac,x
bpl .dont_reset_ac
; reset ac and pick new direction
lda #$05
sta enemy_ram_ac,x
; get range 0..2 from 8bit value
jsr get_next_random
lsr
clc
adc rng0
and #$80
rol
rol ; should have a value between 0 and 2 here
cmp #$02
beq .dir_sub
cmp #$01
beq .dir_add
.dir_same
jmp .ac_reset_done
.dir_add
inc enemy_ram_pc,x
jmp .ac_reset_done
.dir_sub
dec enemy_ram_pc,x
.ac_reset_done
lda enemy_ram_pc,x
and #$03
tay
lda zigzag_dir_table,y
sta enemy_ram_ex,x
ldy enemy_oam_offset
.dont_reset_ac
; set sprite
lda enemy_ram_ac,x
clc
adc #$5a ; base sprite tile
sta oam_ram_spr,y
; work out the direction
lda #<arctang_velocity_1.25
sta arctang_velocity_lo
jsr arctang_enemy_update
lda enemy_ram_pc,x
and #$03
tay
lda zigzag_att_table,y
ldy enemy_oam_offset
jsr enemy_set_palette
jmp update_enemies_handler_next