4.5.6 - Monster Spawning with object limits

9Panzer

Well-known member
So for a fight I'm working on I wanted two "Chickens" to spawn when the tractor crashes into the wall (watch the video, it makes more sense lol)


when creating an object generator you need to be mindful of your resources. Nesmaker has a very complicated object handling system. So when you start getting 3 or 4 objects running on the screen at once you can run into slowdown. If you don't limit the amount of objects being generated you can very easily blow up your game lol.

I'm sharing this because Its actually really handy for anyone not familiar with the NESmakers to be able to pull apart. This snippet of code is the portion that generates my chickens. It can be used in several different ways but it might be useful as a monster AI? Hopefully someone finds this useful!

runChickenProtocol:


CountObjects #%00001000 ;;count enemies onscreen
CMP #03 ;; Are there 3 badguys?
BCC +
JMP notHarey: ;We don't need more Chickens
+

CountObjects #%00001000 ;;count enemies onscreen
CMP #02 ;; Are there 2 badguys?
BCC +
JMP Spawn1: ;; We need another Chicken s Jump to Spawn1!
+

CountObjects #%00001000 ;;count enemies onscreen
CMP #01 ;;Are there 1 badguys?
BCC +
JMP Spawn2: ;; We need TWO more chickens Jump to Spawn2!
+

Spawn1:
JSR doGetRandomNumber ;; Get a random Number for us.
AND #2 ;;;between 0 - 2
STA tempA ;;; Store it in tempA


LDA tempA
CMP #00 ;;; Is the Number 0?
BNE +FirstCheck ;; No its not move to the next check
CreateObjectOnScreen #50, #180, #38, #$00, currentNametable ; Give us a chicken here!
JMP notHarey:
+FirstCheck


CMP #01 ;;; Is the Number 1?
BNE +SecondCheck ;; No its not move to the next check
CreateObjectOnScreen #75, #180, #38, #$00, currentNametable ; Give us a chicken here!
JMP notHarey:
+SecondCheck


CMP #02 ;;; Is the Number 2?
BNE +ThirdCheck ;; No its not move to the next check ... wait... its has to be. Don't lie!
CreateObjectOnScreen #100, #180, #38, #$00, currentNametable ; Give us a chicken here!
JMP notHarey:
+ThirdCheck

Spawn2:
JSR doGetRandomNumber ;; Get a random Number for us.
AND #2 ;;between 0 - 2
STA tempA ;;; Store it in tempA


LDA tempA
CMP #00 ;;; Is the Number 0?
BNE +FirstCheck ;; No its not move to the next check
CreateObjectOnScreen #50, #180, #38, #$00, currentNametable ;; ; Give us a chicken here!
CreateObjectOnScreen #60, #170, #38, #$00, currentNametable ; Give us a chicken here!
JMP notHarey:
+FirstCheck

CMP #01 ;;; Is the Number 1?
BNE +SecondCheck ;; No its not move to the next check
CreateObjectOnScreen #75, #180, #38, #$00, currentNametable ; Give us a chicken here!
CreateObjectOnScreen #85, #170, #38, #$00, currentNametable ; Give us a chicken here!
JMP notHarey:
+SecondCheck

CMP #02 ;;; Is the Number 2?
BNE +ThirdCheck ;; No its not move to the next check ... wait... its has to be. Don't lie!
CreateObjectOnScreen #100, #180, #38, #$00, currentNametable ; Give us a chicken here!
CreateObjectOnScreen #110, #170, #38, #$00, currentNametable ; Give us a chicken here!
JMP notHarey:
+ThirdCheck

RTS

notHarey:

RTS
 
Top Bottom