-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshoggoth.asm
361 lines (317 loc) · 6.26 KB
/
shoggoth.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
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
_shogStateMoving = 1
_shogStateStunned = 2
_shogStateDying = 3
_shogStateDead = 4
_shogsWaitFrames = 50*5
; Basic idea is you hit shoggoth with an icicle at the right of the screen to stun him
; When he's stunned, drop down the centre will drop one elder sign piece.
; When all four signs are dropped, shoggoth dies and melts downwards.
; Player can now exit this way into congratulations screen.
.initShoggoth:
{
LDX #0
STX shogSignsDropped
STX shogForceElderDraw
STX shogX
INX
STX shogMoveDelta
LDX #192
STX shogY
LDX #_shogStateMoving
STX shogState
LDX #3
.patch:
LDA shogPatchOne,X
STA screen40DataEx,X
DEX
BPL patch
.fixedUp:
RTS
}
.updateShoggoth:
{
; Update any icicles
LDA icicleDropFlag
BEQ doneIcicle
JSR updateIcicle
.doneIcicle:
LDA playerScreen
CMP #45
BNE doNothing
; Do we need to draw signs?
LDA shogDrawElderSigns
BEQ doneElderDraw
LDA shogSignsDropped
STA numElderSigns
ASL A ; *2
TAX
.sCRLoop:
LDA localElderSignPos,X
STA elderSignsPos,X
DEX
BPL sCRLoop
LDA #0
STA shogDrawElderSigns ; no need now
LDA #1
STA shogForceElderDraw
.doneElderDraw:
LDA shogState
CMP #_shogStateMoving
BNE notMoving
JMP updateMoving
.notMoving:
CMP #_shogStateDying
BNE notDying
JMP updateDying
.notDying:
CMP #_shogStateStunned
BNE doNothing ; Only remaining state is dead, so do nothing
JMP updateStunned
.doNothing:
; Do nothing
RTS
}
.drawShoggoth:
LDA #LO(shoggothData)
STA t0
LDA #HI(shoggothData)
STA t1
LDA shogX
STA t2
LDA shogY
STA t3
CLC
JSR plotSprite16x16
LDA #LO(shoggothData+128)
STA t0
LDA #HI(shoggothData+128)
STA t1
LDA shogX
CLC
ADC #16
STA t2
LDA shogY
STA t3
JSR plotSprite16x16
LDA #LO(shoggothData)
STA t0
LDA #HI(shoggothData)
STA t1
LDA shogX
CLC
ADC #32
STA t2
LDA shogY
STA t3
SEC
JSR plotSprite16x16
RTS
.updateMoving:
{
LDA shogMoveDelta
BEQ movingLeft
.movingRight:
INC shogX
LDA shogX
CMP #(16*8)-(16*4)+1
BNE shogsOut
LDA #0
STA shogMoveDelta
JMP drawShoggoth
.movingLeft:
DEC shogX
BNE shogsOut
LDA #1
STA shogMoveDelta
.shogsOut:
JMP drawShoggoth
}
.updateDying:
{
INC shogY
LDA shogY
CMP #192+16
BNE okYet
LDA #_shogStateDead
STA shogState
; unlock the collision map here
LDX #3
.patch:
LDA shogPatchTwo,X
STA screen40DataEx,X
DEX
BPL patch
; now, dynamic patch of the tilemap...
LDA #0 OR _bitColour
STA $ab7
LDA #8
STA $aaf
LDX #0
STX $a57 ; a57=0
INX
STX $aa7 ; aa7=1
LDA #_bitFlipped
STA $a4f
; And redraw the tiles..
INX ; x=2
.sMLoop:
TXA
PHA
LDA shogRedrawTiles,X
JSR redrawTile
PLA
TAX
DEX
BPL sMLoop
RTS
.okYet:
JSR drawShoggoth
LDA #(8*11)+4
JSR redrawTile
LDA #(8*11)+5
JSR redrawTile
LDA #(8*11)+6
JSR redrawTile
RTS
}
.updateStunned:
{
LDA playerPosY
CMP #192 ; if player.y == 192 (ie is on floor)...
BNE doneSignDrop
LDA playerPosX
CMP #24 ; and player.x >= 24...
BCC doneSignDrop
CMP #42 ; and player.x < 42
BCS doneSignDrop
.compare:
LDA shogSignsDropped ; now check 'shogSignsDropped' against 'shogSignWhenStun', if they are different, we can drop a sign.
CMP shogSignWhenStun
BNE doneSignDrop
.dropSign:
CLC
ADC #1
STA numElderSigns
STA shogSignsDropped
LDA #1
STA shogDrawElderSigns ; update them
; and remove a bit from elder inventory
LDA playerInventory
TAX ; save
LSR A
AND #$f0
STA t0 ; t0=new elder bits
TXA
AND #$0f
ORA t0
STA playerInventory
JSR drawElderSign
; And play a sound
LDA #LO(itemUseSound)
STA notereq
LDA #HI(itemUseSound)
STA notereq+1
.doneSignDrop:
DEC shogWaitFrames
BNE stillStunned
; when shogwait=0, set state=moving
.checkForDead:
LDA shogSignsDropped
CMP #4
BNE notDeadYet
LDA #_shogStateDying
STA shogState
JMP drawShoggoth
.notDeadYet:
LDA #_shogStateMoving
STA shogState
.stillStunned:
JMP drawShoggoth
}
.updateIcicle:
{
LDA icicleDropFrames
CMP #40 ; first pass?
BEQ skipErase
; Erase last one with an xor
LDA #LO(icicleSprite)
STA t0
LDA #HI(icicleSprite)
STA t1
LDA icicleDropX
STA t2:PHA
LDA icicleDropY
STA t3:PHA
LDA #1
STA t4
CLC
JSR plotSprite8x8
; Have we collided with a tile?
PLA:CLC:ADC #8
STA getTileY
PLA
STA getTileX
JSR getTile
LDA collData,Y
AND #_bitCollidable
BNE lastFrame
LDA getTileY
CMP #192+16
BCS lastFrame ; check end of screen
.skipErase:
LDA icicleDropY:CLC:ADC#3:STA icicleDropY
DEC icicleDropFrames
BEQ lastFrame
; Draw new one
LDA #LO(icicleSprite)
STA t0
LDA #HI(icicleSprite)
STA t1
LDA icicleDropX
STA t2
LDA icicleDropY
STA t3
LDA #1
STA t4
CLC
JSR plotSprite8x8
RTS
.lastFrame:
LDA #0
STA icicleDropFlag
LDA icicleDropY
CMP #192
BCC noCollisionIcicle
LDA icicleDropX
CMP #58+(16*2)
BCC noCollisionIcicle
; Check for shogs collision if
LDA shogState
CMP #_shogStateMoving
BNE noCollisionIcicle
LDA shogX
CMP #58
BCS hitShogs
.noCollisionIcicle:
RTS
.hitShogs:
LDA #(8*10)+3
JSR redrawTile ; blank out tile prior
LDA #16*4 ; force x pos
STA shogX
LDA #_shogStateStunned
STA shogState
LDA #_shogsWaitFrames
STA shogWaitFrames
LDA shogSignsDropped
STA shogSignWhenStun ; 24/04/2013 : Take a copy of the original number of signs so we can determine if player can drop a new sign
LDA #LO(shoggothHitSound)
STA notereq
LDA #HI(shoggothHitSound)
STA notereq+1
RTS
.shoggothHitSound:
EQUB 0 ; pitch
EQUB 1 ; pitch envelope
EQUB 1 ; vol envelope
}