BEES! How to Create (Virtually) Unlimited Monsters

TurtleRescueNES

Active member
As requested in the Facebook group, here is a quick tutorial on how to spawn (near) unlimited monsters, and why that is not a good idea. :)

In my example, which will appear in my "Turtle Rescue" game, I will use a beehive that spawns bees. You may use this for other purposes. For my tutorial, I will use "beehive" to identify the monster that spawns, and "bees" to identify the spawned monster.

Before we begin, create your beehive and bee monsters. They should be in the same monster tileset. Bees will be set up to behave as any normal monster. They are fully capable to function on their own. Your beehive is a placeholder for right now. We'll apply additional functionality to it later. Remember bounding boxes, health settings and to make them monster types!

Assign the beehive to a monster group. It is actually not required to assign the bees to the same monster group as the beehive, but for testing purposes, you should add them as well.

Create a test screen, assign your new monster group to the screen's Day Monsters. Place a bee and a beehive on the screen. For testing purposes, you should place your player on the same screen as well.

Export and test your game. Nothing special should be happening at this point, You just want to confirm your bee is behaving as expected, and your beehive just appears. It's not supposed to do anything yet.

Now we need to get down and dirty with code... well, not really. There's not all that much, really.

First, create two user defined constants in Project Settings:

MON_SPAWN_MAX -- Value: 5 -- The number of monsters that will appear on the screen when the beehive stops generating bees. You can change this later.
MON_SPAWN_ID -- Value: ## -- The unique ID number of your bee monster. To determine this, go to your Monster Graphic Banks, Monsters list, and starting with 16, count the number of monsters down your list that your bee appears. For example, if your bee is the 5th monster, the ID value will be 20.

Now for the code itself!
Create a new SpawnMonsters.asm file in your AiScripts folder

Insert the following code:

Code:
;; JTS Spawn Monsters
;; In this case, spawn bees from beehive monster


    LDA monsterCounter
    CMP #MON_SPAWN_MAX  
    BCS labDoNotSpawn
    

    labSpawnBees:


    TXA
    STA tempx
    
    ;; get offset
    LDA Object_x_hi,x
    CLC
    ADC #$04 ;; arbitrary...would put an 8x8 proj in the center of a 16x16 object
    STA temp1
    CLC
    ADC #$04 ;; arbitrary...would put a 8x8 proj in the center of a 16x16 object
    LDA Object_y_hi,x
    STA temp2
 ;;   Use one of the two commands below based on your version
 ;;   CreateObject temp1, temp2, #MON_SPAWN_ID, #$00   ;Use this line for 4.0.X
 CreateObject temp1, temp2, #MON_SPAWN_ID, #$00, currentNametable    ;Use this line for 4.1.X

     
    labDoNotSpawn:  
    LDX tempx

Save your ASM file.

Open Project Settings / Script Settings and assign your SpawnMonsters.asm to an open AI Action script.
You can also rename this AI script on the Project Labels tab, then Action Types

Now that the script is done, it is a good idea to export and test your game again. Nothing will have changed, but given that we've added new code, it is an excellent time to make sure it hasn't broken our game.

Now let's start to make that beehive a monster spawning machine!!!

Reopen your beehive monster. Is should have two action states.

Action State 0 will have a timer. In my case, I used 6. You may use whatever you want and can change it later. This controls the pace the bees will appear. No action is placed on this state. Select "Advance" for the EndAction setting.

On Action State 1, select the new action to reflect the new SpawnMonsters AI behavior. Change the EndAction to GoToFirst.
This is what will tell the beehive to create a bee, then loop over again. The bee will not appear if the screen already has MON_SPAWN_MAX number of monsters onscreen. Kill off a bee, and another will spawn. The only way for the player to stop the bees is to destroy the beehive.

Build your game, and all should work as you expect. In my GIF below, I show that you could generate far more than five bees, but it would be unwise. The NES will eventually slow down, and also the player is going to get overwhelmed. So place a reasonable max to make everyone happy.

Good luck!

UPDATE: Thanks to vanderblade for helping test this. I created this on a different module than what many are using, so your experience may vary.
 

Attachments

  • ezgif-3-572aa1409c80.gif
    ezgif-3-572aa1409c80.gif
    336 KB · Views: 4,542

Bucket Mouse

Active member
You just made an entire game genre (think Gauntlet) possible.

Sometimes you don't want endless monsters, though, you want a set number to spawn (beyond four) and then the generator to stop. What would you do in that case?

My guess is instead of selecting "Go To First" you would select "stop," "SpawnMonsters," "stop," and on until you had the number you wanted.
 

TurtleRescueNES

Active member
Bucket Mouse said:
You just made an entire game genre (think Gauntlet) possible.

Sometimes you don't want endless monsters, though, you want a set number to spawn (beyond four) and then the generator to stop. What would you do in that case?

My guess is instead of selecting "Go To First" you would select "stop," "SpawnMonsters," "stop," and on until you had the number you wanted.

That would absolutely work. Keep in mind you would be limited to the number of action steps, which would be 8.
 

Bucket Mouse

Active member
jsherman said:
Bucket Mouse said:
You just made an entire game genre (think Gauntlet) possible.

Sometimes you don't want endless monsters, though, you want a set number to spawn (beyond four) and then the generator to stop. What would you do in that case?

My guess is instead of selecting "Go To First" you would select "stop," "SpawnMonsters," "stop," and on until you had the number you wanted.

That would absolutely work. Keep in mind you would be limited to the number of action steps, which would be 8.

Wait, how many monsters does SpawnMonsters generate per turn? if it's just one, then it would just make four.....making the whole exercise pointless. Never mind, this wouldn't work.

How would you adapt the script to turn off after a number has been reached, instead of regenerating to keep the same number?
 

vanderblade

Active member
When testing this, I get the following compiler error:

Routines\Basic\ModuleScripts\AiScripts\SpawnMonsters.asm(25):CreateObject(36): Unknown label.
demo.txt written.

I created the MON_SPAWN_ID constant and set it to 58. My spawning monster is the 43rd monster, so that means 42 + 16, right?

Any ideas why this might be happening?
 

Bucket Mouse

Active member
vanderblade said:
When testing this, I get the following compiler error:

Routines\Basic\ModuleScripts\AiScripts\SpawnMonsters.asm(25):CreateObject(36): Unknown label.
demo.txt written.

I created the MON_SPAWN_ID constant and set it to 58. My spawning monster is the 43rd monster, so that means 42 + 16, right?

Any ideas why this might be happening?

They want hexadecimal numbers. 43 in hex is 2B.
Use this converter I just Googled to get your numbers: http://www.statman.info/conversions/hexadecimal.html
 

Bucket Mouse

Active member
vanderblade said:
When testing this, I get the following compiler error:

Routines\Basic\ModuleScripts\AiScripts\SpawnMonsters.asm(25):CreateObject(36): Unknown label.
demo.txt written.

I created the MON_SPAWN_ID constant and set it to 58. My spawning monster is the 43rd monster, so that means 42 + 16, right?

Any ideas why this might be happening?

They want hexadecimal numbers. 43 in hex is 2B.

I would link you to a hex conversion form here, but posting links means getting mod approval first. Just google "Hexadecimal conversion."
 

vanderblade

Active member
I guess I'm confused.

Why, in Joe's example, does he have the value of 20? That's not a hexidecimal, since 20 in hexidecimal is A1.
 

TurtleRescueNES

Active member
Actually, the NESMaker constants are stored in decimal format, so that is how you enter them in the Project settings. They are converted at compilation to hex.

I see the issue. My version of CreateObject wants four parameters. Your module likely wants five due to the scrolling engine.

See if this works:
CreateObject temp1, temp2, #MON_SPAWN_ID, #$00, #$00
 

vanderblade

Active member
Follow-up after more testing:

My spawned monsters don't follow their action steps. They just stand there and are immune to the projectile weapon. I can kill them with the melee weapon, though.

If I put these monsters in a room as normal, they work as intended. Interesting...

Is this because of my particular module again?
 

TurtleRescueNES

Active member
Okay, one other try. Sorry, I'm on a different module so I cannot verify this easily.

CreateObject temp, temp1, #MON_SPAWN_ID, #$00, currentNametable

It's possible that the monster cannot move without the nametable declaration. But I'm not sure how all that works. If this doesn't work, maybe someone else can chime in.
 

vanderblade

Active member
That works. Just had to change the temps to the following (like your original script)

CreateObject temp1, temp2, #MON_SPAWN_ID, #$00, currentNametable

The MON_SPAWN_MAX doesn't seem to limit monster creation, but everything else is working as intended. Thanks!
 

dale_coop

Moderator
Staff member
vanderblade said:
When testing this, I get the following compiler error:

Routines\Basic\ModuleScripts\AiScripts\SpawnMonsters.asm(25):CreateObject(36): Unknown label.
demo.txt written.

I created the MON_SPAWN_ID constant and set it to 58. My spawning monster is the 43rd monster, so that means 42 + 16, right?

Any ideas why this might be happening?

In the script, try replacing:
Code:
 CreateObject temp1, temp2, #MON_SPAWN_ID, #$00
with:
Code:
 CreateObject temp1, temp2, #MON_SPAWN_ID, #$00, currentNametable
 

TurtleRescueNES

Active member
Thanks for confirming. I updated my original post.
As for the limit not working, it must be a difference in how "monsterCounter" behaves in your module. I may look into it this weekend.
 
Top Bottom