-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroom.asm
176 lines (150 loc) · 2.98 KB
/
broom.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
.export BroomExecute
.export BroomDraw
.export BroomExplodeIntoStars
.include "include.branch-macros.asm"
.include "include.mov-macros.asm"
.include "include.sprites.asm"
.include "include.tiles.asm"
.include "object_list.h.asm"
.include "sprite_space.h.asm"
.include "shared_object_values.asm"
.include "draw_picture.h.asm"
.include "flash.h.asm"
.include ".b/pictures.h.asm"
.include "famitone.h.asm"
.include "sound.h.asm"
.include "score_combo.h.asm"
.importzp camera_h, camera_screen
.importzp level_complete, which_level
.importzp draw_screen
.importzp values
.import flash_priority
.import object_data_extend
.segment "CODE"
.proc BroomExecute
.scope MaybeDespawn
jsr ObjectOffscreenDespawn
bcc Okay
rts
Okay:
.endscope
.scope CollisionWithPlayer
jsr ObjectCollisionWithPlayer
bcc Next
DidCollide:
mov level_complete, #1
; Play sound effect of collecting broom.
lda #SFX_COLLECT_ITEM
jsr SoundPlay
jmp Return
Next:
.endscope
Draw:
lda level_complete
beq Ready
; Flash the broom.
and #$0f
tay
lda flash_priority,y
beq Return
Ready:
; Draw position.
lda object_h,x
clc
adc #6
sec
sbc camera_h
sta draw_h
lda object_screen,x
sbc camera_screen
sta draw_screen
ldy object_frame,x
lda broom_animate_v_offset,y
clc
adc object_v,x
sta draw_v
; Animation.
lda #PICTURE_ID_BROOM
sta draw_picture_id
MovWord draw_picture_pointer, broom_picture_data
MovWord draw_sprite_pointer, broom_sprite_data
mov draw_palette, #1
; Draw the sprites.
jsr DrawPicture
Return:
rts
.endproc
BroomDraw = BroomExecute::Draw
.proc BroomExplodeIntoStars
jsr ObjectListGetLast
Loop:
lda object_kind,x
cmp #OBJECT_KIND_BROOM
bne Increment
Explode:
lda object_v,x
clc
adc #$10
sta draw_v
lda object_h,x
clc
adc #$08
sta draw_h
mov draw_screen, {object_screen,x}
jsr ObjectFree
ldy #0
jsr CreateStar
ldy #1
jsr CreateStar
ldy #2
jsr CreateStar
ldy #3
jsr CreateStar
; Play sound of making stars
lda #SFX_MAKE_STARS
jsr SoundPlay
; Gain points for collecting the broom.
lda #20
jsr ScoreAddLow
rts
Increment:
dex
bpl Loop
rts
.endproc
.proc CreateStar
jsr ObjectAllocate
bcc Return
mov {object_kind,x}, #OBJECT_KIND_STAR
mov {object_v,x}, draw_v
mov {object_h,x}, draw_h
mov {object_screen,x}, draw_screen
jsr ObjectConstructor
; Stop music
jsr FamiToneMusicStop
Return:
rts
.endproc
broom_animate_v_offset:
.byte 0
.byte 0
.byte 1
.byte 2
.byte 3
.byte 3
.byte 2
.byte 1
OFFSET = 6
; TODO: Pictures can't correctly process broom.
PICTURE_ID_BROOM = 0
broom_picture_data:
.byte $00,$01,$02,$03,$04,$fe,$05,$06,$ff
broom_sprite_data:
; y, x, tile
.byte $00,$0a -OFFSET ,BROOM_TOP_TILE
.byte $09,$08-$08-OFFSET+$100,BROOM_MIDDLE_TILE
.byte $19,$00-$10-OFFSET+$100,BROOM_GLOW_A_TILE
.byte $19,$0a-$18-OFFSET+$100,BROOM_GLOW_B_TILE
.byte $27,$06-$20-OFFSET+$100,BROOM_GLOW_C_TILE
.byte $19,$01 -OFFSET+$100,BROOM_MOP_LEFT_TILE
.byte $19,$09-$08-OFFSET+$100,BROOM_MOP_RIGHT_TILE