/[projet1]/users/twilighte/Stormlord/MapCode.s
Defence Force logotype

Contents of /users/twilighte/Stormlord/MapCode.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (show annotations)
Thu Oct 7 20:50:23 2010 UTC (8 years, 8 months ago) by dbug
File size: 9867 byte(s)
Added Stormlord
1 ;MapCode.s
2 ;3 types of NPC exist in Stormlord..
3 ;1) NPC like Raindrops, Balls - Initialised at map draw at specific point/s from block
4 ;2) NPC like Bees - Spawned at map draw to exist at specific x/y
5 ;3) NPC like Dragons, Eggs - Spawned in realtime in NPC_Engine but flagged to do so here in map code
6
7 ;DrawMap
8 ; Draw Screen
9 ; Draw Background buffer
10 ; Draw Collision Map
11 ; Initialise NPCs for Screen
12 DrawMap lda #128
13 sta ssnpc_Type
14
15 ;Silence all SFX
16 ldx #2
17 lda #0
18 .(
19 loop1 sta sfx_Status,x
20 dex
21 bpl loop1
22 .)
23 ;Silence sound
24 sta ay_Volume
25 sta ay_Volume+1
26 sta ay_Volume+2
27
28 lda #255
29 sta ObjectIndex
30 sta NPCUltimateIndex
31
32 lda #5
33 sta MapGrubCount
34
35 lda #00
36 sta Honeypot_Found
37 sta BeesPresentHere
38
39 jsr InitialiseScreenSpecificNPC
40
41 lda #<Stormlord_Map
42 sta map
43 lda #>Stormlord_Map
44 sta map+1
45
46 lda #0
47 sta dm_CursorY
48 .(
49 loop2 lda #0
50 sta dm_CursorX
51 lda MapX
52 sta dm_MapIndex
53
54 loop1 ldy dm_MapIndex
55 lda (map),y
56
57 sta MomentaryBlock
58
59 jsr CheckBlock4NPC
60
61 jsr CheckBlock4Object
62
63 jsr PlotBlock2Screen
64
65 jsr PlotBlock2BGBuff
66
67 jsr PlotBlock2CMAP
68
69 ; lda NPCUltimateIndex
70 ; bmi skip777
71 ;skip776 nop
72 ; jmp skip776
73 ;skip777
74 inc dm_CursorX
75 inc dm_CursorX
76
77 inc dm_MapIndex
78
79 lda dm_CursorX
80 cmp #38
81 bcc loop1
82
83 inc map+1
84
85 inc dm_CursorY
86 inc dm_CursorY
87
88 lda dm_CursorY
89 cmp #18
90 bcc loop2
91 .)
92 rts
93
94 ;Some NPC are generated based on the Screen and level
95 ; Eggwasp
96 ; Dragon
97 InitialiseScreenSpecificNPC
98 ldx #00
99 .(
100 loop1 lda NPCScreenSpecificLevelID,x
101 bmi skip3
102 cmp LevelID
103 bne skip1
104 lda MapX
105 cmp NPCScreenSpecificMapX,x
106 beq skip2
107 skip1 inx
108 jmp loop1
109 skip3 rts
110 skip2 ;Setup this NPC
111 lda NPCScreenSpecificSetupVectorLo,x
112 sta vector1+1
113 lda NPCScreenSpecificSetupVectorHi,x
114 sta vector1+2
115 vector1 jmp $dead
116 .)
117
118
119 NPCScreenSpecificLevelID
120 .byt 0 ;Level 1 Bonus screen
121
122 .byt 1 ;Level 2 Dragon
123 .byt 1 ;Level 2 Eggwasp
124 .byt 1 ;Level 2 Eggwasp
125 .byt 1 ;Level 2 Bonus screen
126
127 ; .byt 2 ;Level 3 Dragon
128 ; .byt 2 ;Level 3 Eggwasps
129 .byt 2 ;Level 3 Bonus screen
130 .byt 128
131
132 NPCScreenSpecificMapX
133 .byt 237
134
135 .byt $9A
136 .byt $62
137 .byt $54
138 .byt 237
139
140 ; .byt $38
141 ; .byt $70
142 .byt 237
143 NPCScreenSpecificSetupVectorLo
144 .byt <SetupFairies
145
146 .byt <SetupDragon
147 .byt <SetupEggwasp
148 .byt <SetupEggwasp
149 .byt <SetupFairies
150
151 ; .byt <SetupDragon
152 ; .byt <SetupEggwasp
153 .byt <SetupFairies
154
155 NPCScreenSpecificSetupVectorHi
156 .byt >SetupFairies
157
158 .byt >SetupDragon
159 .byt >SetupEggwasp
160 .byt >SetupEggwasp
161 .byt >SetupFairies
162
163 ; .byt >SetupDragon
164 ; .byt >SetupEggwasp
165 .byt >SetupFairies
166
167
168 CheckBlock4NPC
169 lda MomentaryBlock
170 ldx #5
171 .(
172 loop1 cmp NPCBlockTrigger,x
173 beq skip1
174 dex
175 bpl loop1
176 rts
177 skip1 ;Found Block - Branch to initialise
178 lda NPCBlockInitialiseVectorLo,x
179 sta vector1+1
180 lda NPCBlockInitialiseVectorHi,x
181 sta vector1+2
182 vector1 jmp $dead
183 .)
184
185
186 NPCBlockTrigger
187 .byt 1 ;Web - Spider
188 .byt 4 ;Launcher - Ball
189 .byt 16 ;Blue Vase- Bees
190 .byt $5D ;Honeypot - Overides Bee Origin
191 .byt 34 ;Cloud - Rain Drops
192 .byt 8 ;Ledge - Grub
193 NPCBlockInitialiseVectorLo
194 .byt <SetupSpider
195 .byt <SetupBall
196 .byt <SetupBees
197 .byt <OverrideBeeOrigin
198 .byt <SetupRaindrops
199 .byt <SetupGrub
200 NPCBlockInitialiseVectorHi
201 .byt >SetupSpider
202 .byt >SetupBall
203 .byt >SetupBees
204 .byt >OverrideBeeOrigin
205 .byt >SetupRaindrops
206 .byt >SetupGrub
207
208 CheckBlock4Object
209 lda MomentaryBlock
210 ldx #6
211 .(
212 loop1 cmp ObjectBlockTrigger,x
213 beq skip1
214 dex
215 bpl loop1
216 rts
217 skip1 ;Found Block - Branch to initialise
218 lda ObjectBlockInitialiseVectorLo,x
219 sta vector1+1
220 lda ObjectBlockInitialiseVectorHi,x
221 sta vector1+2
222 vector1 jmp $dead
223 .)
224
225 ObjectBlockTrigger
226 .byt $28 ;,$29,$34,$35 ;Door
227 .byt $41 ;,$42 ;Trampolene
228 .byt $5B ;,$5C ;Key
229 .byt $5D ;,$5E ;Honeypot
230 .byt $68 ;,$69 ;Umbrella
231 .byt $6A ;,$6B ;Shoes
232 .byt $12 ;,$13,$1E,$1F ;Fairy
233 ObjectBlockInitialiseVectorLo
234 .byt <InitDoor ;,<InitDoor,<InitDoor,<InitDoor
235 .byt <InitTrampolene ;,<InitTrampolene
236 .byt <InitKey ;,<InitKey
237 .byt <InitHoneypot ;,<InitHoneypot
238 .byt <InitUmbrella ;,<InitUmbrella
239 .byt <InitShoes ;,<InitShoes
240 .byt <InitFairy ;,<InitFairy,<InitFairy,<InitFairy
241 ObjectBlockInitialiseVectorHi
242 .byt >InitDoor ;,>InitDoor,>InitDoor,>InitDoor
243 .byt >InitTrampolene ;,>InitTrampolene
244 .byt >InitKey ;,>InitKey
245 .byt >InitHoneypot ;,>InitHoneypot
246 .byt >InitUmbrella ;,>InitUmbrella
247 .byt >InitShoes ;,>InitShoes
248 .byt >InitFairy ;,>InitFairy,>InitFairy,>InitFairy
249
250 ;dm_CursorX
251 ;dm_CursorY
252 ;MomentaryBlock
253 PlotBlock2Screen
254 lda dm_CursorX
255 ldy dm_CursorY
256 clc
257 adc Mult240Lo,y
258 sta screen
259 lda #$A0
260 adc Mult240Hi,y
261 sta screen+1
262
263 ;Offset screen by 30 rows
264 lda screen
265 sec
266 adc #<30*40
267 sta screen
268 lda screen+1
269 adc #>30*40
270 sta screen+1
271
272 ;multiply block by 24(x16 + x8)
273 jsr CalcBlockAddress
274
275 ldx #12
276 .(
277 loop2 ldy #1
278
279 loop1 lda (graphic),y
280 sta (screen),y
281 dey
282 bpl loop1
283
284 lda #2
285 jsr AddGraphic
286 jsr nl_screen
287
288 dex
289 bne loop2
290 .)
291 rts
292
293 CalcBlockAddress
294 ldx #00
295 stx TempHi
296 lda MomentaryBlock
297 asl
298 rol TempHi
299 asl
300 rol TempHi
301 asl
302 rol TempHi
303 sta graphic
304 ldx TempHi
305 stx graphic+1
306 asl
307 rol TempHi
308 adc graphic
309 tax ;sta TempLo
310 lda TempHi
311 adc graphic+1
312 sta graphic+1
313 txa
314 adc #<GraphicBlock00
315 sta graphic
316 lda graphic+1
317 adc #>GraphicBlock00
318 sta graphic+1
319 rts
320
321 PlotBlock2BGBuff
322 lda dm_CursorX
323 ldy dm_CursorY
324 clc
325 adc Mult240Lo,y
326 sta bgbuff
327 lda #>BackgroundBuffer
328 adc Mult240Hi,y
329 sta bgbuff+1
330
331 jsr CalcBlockAddress
332
333 ldx #12
334 .(
335 loop2 ldy #1
336
337 loop1 lda (graphic),y
338 sta (bgbuff),y
339 dey
340 bpl loop1
341
342 lda #2
343 jsr AddGraphic
344 lda #40
345 jsr AddBGBuff
346
347 dex
348 bne loop2
349 .)
350 rts
351
352 PlotBlock2CMAP
353 lda dm_CursorX
354 ldy dm_CursorY
355 sec
356 adc Mult40Lo,y
357 sta cmap
358 lda #>CollisionMap
359 adc Mult40Hi,y
360 sta cmap+1
361
362 ldx MomentaryBlock
363 lda Block2CollisionValue,x
364
365 ;Each block consumes 2x2 cells
366 ldx #3
367 .(
368 loop1 ldy Offset2x2,x
369 sta (cmap),y
370 dex
371 bpl loop1
372 .)
373 rts
374
375 ;These require Object_ tables to be set up (indexed by ObjectIndex)
376 ;Object_BlockID
377 ;Object_MapLo
378 ;Object_MapHi
379 ;Object_X
380 ;Object_Y
381
382 InitFairy
383 InitDoor
384 InitTrampolene
385 InitHoneypot
386 InitKey
387 InitUmbrella
388 InitShoes
389 inc ObjectIndex
390 ldx ObjectIndex
391 lda MomentaryBlock
392 sta Object_BlockID,x
393 tay
394 lda Block2CollisionValue,y
395 sta Object_CollisionValue,x
396 lda dm_CursorX
397 sta Object_X,x
398 lda dm_CursorY
399 sta Object_Y,x
400 lda map
401 clc
402 adc dm_MapIndex
403 sta Object_MapLo,x
404 lda map+1
405 adc #00
406 sta Object_MapHi,x
407 rts
408
409 SetupSpider
410 jsr FetchNewNPCIndex
411 .(
412 bcs skip1
413
414 lda #NPCA_SPIDER
415 sta NPC_Activity,y
416
417 ;Progress indicates frame index
418 lda #00
419 sta NPC_Progress,y
420
421 lda #2
422 sta NPC_Direction,y
423
424 lda dm_CursorX
425 adc #1
426 sta NPC_ScreenX,y
427 sta NPC_ScreenXOrigin,y
428
429 lda dm_CursorY
430 jsr Mult6
431 clc
432 adc #30
433 ora #1
434 sta NPC_ScreenY,y
435 sta NPC_ScreenYOrigin,y
436 skip1 rts
437 .)
438
439 Mult6 asl
440 .(
441 sta vector1+1
442 asl
443 vector1 adc #00
444 .)
445 rts
446
447 SetupBall
448 jsr FetchNewNPCIndex
449 .(
450 bcs skip1
451 ;Record Launchers First Ball Screen Location and xy
452 lda #NPCA_BALLRISING
453 sta NPC_Activity,y
454 lda #00
455 sta NPC_Progress,y
456
457 lda dm_CursorX
458 clc
459 adc #01
460 sta NPC_ScreenX,y
461 sta NPC_ScreenXOrigin,y
462 lda dm_CursorY
463 jsr Mult6
464 clc
465 adc #20
466 sta NPC_ScreenY,y
467 sta NPC_ScreenYOrigin,y
468 skip1 rts
469 .)
470
471 SetupBees ;Don't setup bees if on bonus screen
472 lda MapX
473 cmp #237
474 .(
475 beq skip2
476
477 ;Set up SFX
478 ; lda #SFX_BEES
479 ; jsr KickSFX
480
481 lda Honeypot_Found
482 bne skip1
483
484 ; Honeypot not found (yet) so initialise Bee Origin as Vase position
485 lda dm_CursorX
486 jsr Mult6
487 sta BeeOriginX
488 lda dm_CursorY
489 jsr Mult6
490 clc
491 adc #30
492 sta BeeOriginY
493 skip1 ;Now setup NPCs
494 ldx #3
495 stx BeesPresentHere
496
497 loop1 jsr FetchNewNPCIndex
498 bcs skip2
499 lda #NPCA_BEE
500 sta NPC_Activity,y
501 ;Set progress to Random index in 256 SineTable
502 jsr GetRandomNumber
503 sta NPC_Progress,y
504 ;Set initial X and Y so that we don't fuck up screen at start
505 lda BeeOriginX
506 sta NPC_ScreenX,y
507 lda BeeOriginY
508 sta NPC_ScreenY,y
509 dex
510 bpl loop1
511 skip2 rts
512 .)
513
514
515 OverrideBeeOrigin
516 lda #1
517 sta Honeypot_Found
518 lda dm_CursorX
519 jsr Mult6
520 sta BeeOriginX
521 lda dm_CursorY
522 jsr Mult6
523 clc
524 adc #30
525 sta BeeOriginY
526 rts
527 SetupRaindrops
528 ;Generate 4 raindrops at 2 bytes apart
529 ldx #1
530 .(
531 loop1 jsr FetchNewNPCIndex
532 bcs skip1
533
534 lda #NPCA_RAINDROP
535 sta NPC_Activity,y
536
537 tya
538 ora #1
539 asl
540 sta NPC_Progress,y
541
542 txa
543 asl
544 adc dm_CursorX
545 sta NPC_ScreenX,y
546 ; lda dm_CursorX
547 sta NPC_ScreenXOrigin,y
548
549 lda dm_CursorY
550 jsr Mult6
551 clc
552 adc #37
553 ora #1
554 sta NPC_ScreenY,y
555 sta NPC_ScreenYOrigin,y
556
557 dex
558 bpl loop1
559 skip1 rts
560 .)
561
562 SetupGrub
563 ;Only mark the first 5 ledges
564 lda MapGrubCount
565 .(
566 beq skip1
567 dec MapGrubCount
568 ;Use this ledge to launch a grub
569 jsr FetchNewNPCIndex
570 bcs skip1
571
572 lda #NPCA_GRUBPEEP
573 sta NPC_Activity,y
574 lda #50 ;Hesitancy level for grub
575 sta NPC_Progress,y
576 lda #2 ;Face right
577 sta NPC_Direction,y
578 lda #4 ;Speed of look
579 sta NPC_Special,y
580
581 lda dm_CursorX
582 clc
583 adc #01
584 sta NPC_ScreenX,y
585 sta NPC_ScreenXOrigin,y
586 lda dm_CursorY
587 jsr Mult6
588 clc
589 adc #25
590 and #$FE
591 sta NPC_ScreenY,y
592 sta NPC_ScreenYOrigin,y
593 skip1 rts
594 .)
595
596 SetupDragon
597 lda #00
598 sta ssnpc_Type
599 lda #1
600 sta DelayBetweenRRNPC
601 rts
602
603 SetupEggwasp
604 lda #1
605 sta DelayBetweenRRNPC
606 sta ssnpc_Type
607 rts
608
609 SetupFairies
610 lda #02
611 sta ssnpc_Type
612 lda #1
613 sta DelayBetweenRRNPC
614 rts
615
616 ssnpc_Type .byt 0
617
618 FetchNewNPCIndex
619 ;We must limit the number of NPC to 12 or under
620 ldy NPCUltimateIndex
621 .(
622 bmi skip2
623 cpy #11
624 bcs skip1
625 skip2 inc NPCUltimateIndex
626 ldy NPCUltimateIndex
627 clc
628 skip1 rts
629 .)

  ViewVC Help
Powered by ViewVC 1.1.26