How do I make monster spawner tiles?

Anyone know how to make a tile spawn a monster? I can create a monster that spawns mosnters, but that causes slowdown due to object limitations. If I try to take the monster spawner code and apply it to a tile type’s script, it does nothing. Probably because the code involves grabbing the location and direction of the object trying to spawn the monsters, when this is not an object. But how would I alter it to allow the tile to spawn them?
 

baardbi

Well-known member
Anyone know how to make a tile spawn a monster? I can create a monster that spawns mosnters, but that causes slowdown due to object limitations. If I try to take the monster spawner code and apply it to a tile type’s script, it does nothing. Probably because the code involves grabbing the location and direction of the object trying to spawn the monsters, when this is not an object. But how would I alter it to allow the tile to spawn them?
Using a tile to spawn monsters can be a little tricky. It's much better to make a monster spawner object. You could use an AI like this (it will also limit monsters):

;;; Spawn a new monster
;;; (if there are less than 4 monsters on the screen)

CountObjects #%00001000 ;;; Monster object
CMP #4 ;;; Max monster objects
BCC createNewMonster
JMP maxMonsterObjects
createNewMonster:

LDA Object_x_hi,x
STA tempA

LDA Object_y_hi,x
STA tempB

;;; Spawn a monster
CreateObjectOnScreen tempA, tempB, #16, #0, camScreen ;;; 16 is the monster object to spawn
;; arg0 = x
;; arg1 = y
;; arg2 = object
;; arg3 = beginning state
;; arg4 = what screen do youw ant to create this object on?

maxMonsterObjects:

Make an invisible monster and assign this AI action to the first action step. Give it a timer like 2 or 3 (or whatever), and EndAction = Repeat.
 
Using a tile to spawn monsters can be a little tricky. It's much better to make a monster spawner object. You could use an AI like this (it will also limit monsters):



Make an invisible monster and assign this AI action to the first action step. Give it a timer like 2 or 3 (or whatever), and EndAction = Repeat.
I know how to do that, the problem is that that causes performance issues due to there being too many objects (right now I have a 3 enemy limit and one spawner object, which works fine enough, though with slight lag, but if I wanted enemies to spawn in multiple separate locations I would need additional spawners, which causes huge slowdown due to them being objects). Using tiles might be more difficult, but it would really help performance if I knew how to pull it off.
 

NightMusic

Member
I know how to do that, the problem is that that causes performance issues due to there being too many objects (right now I have a 3 enemy limit and one spawner object, which works fine enough, though with slight lag, but if I wanted enemies to spawn in multiple separate locations I would need additional spawners, which causes huge slowdown due to them being objects). Using tiles might be more difficult, but it would really help performance if I knew how to pull it off.
You're using a blank spawner? Have you tried the trick for making empty sprites not draw? That might save cpu/ram.
Try this maybe?
 
You're using a blank spawner? Have you tried the trick for making empty sprites not draw? That might save cpu/ram.
Try this maybe?
My drawing script is custom made, so by default nothing is drawn unless I manually code it in.
 

dale_coop

Moderator
Staff member
A tile script is executed only when an object collides with it.
You could use a createobject code in a tile script that would happen when the player touches it.
 
A tile script is executed only when an object collides with it.
You could use a createobject code in a tile script that would happen when the player touches it.
That creates a problem because upon collision the script will be rapidly executed until it can’t anymore. I would need to find a way to implement some kind of timer, to space out the action.
 

smilehero65

Active member
That creates a problem because upon collision the script will be rapidly executed until it can’t anymore. I would need to find a way to implement some kind of timer, to space out the action.
I have an idea, maybe create a timer that spawns the monsters in desired X and Y positions.
This timer, however, is not an object, I'm referring to the script HandleGameTimer.asm

It executes every frame, so we should be careful to not broke the game with spawns.
 

dale_coop

Moderator
Staff member
That creates a problem because upon collision the script will be rapidly executed until it can’t anymore. I would need to find a way to implement some kind of timer, to space out the action.
Of course, you would have to create the object only of not already created... or maybe set the collision data to null just after the creation of the object, ...etc
Or use a timer if it's something that should happend repeatidly (like waves of monsters).

There are a lot of ways of doing that. It really depends of your project (how are your levels, how/when do you want to create the monster objects, ... for your game)
 
Of course, you would have to create the object only of not already created... or maybe set the collision data to null just after the creation of the object, ...etc
Or use a timer if it's something that should happend repeatidly (like waves of monsters).

There are a lot of ways of doing that. It really depends of your project (how are your levels, how/when do you want to create the monster objects, ... for your game)
Even with a limit, the tile will try to spawn up to that limit all at the same time, which is terrible for visibility sake. I tried implementing code to make it spawn on a different row each time it spawns something, but when applying it to a tile, it does not work. Likely because it's spawning them way too fast. The best solution would likely be to create a timer, but I'm not sure on exactly how to do that.
 

smilehero65

Active member
Even with a limit, the tile will try to spawn up to that limit all at the same time, which is terrible for visibility sake. I tried implementing code to make it spawn on a different row each time it spawns something, but when applying it to a tile, it does not work. Likely because it's spawning them way too fast. The best solution would likely be to create a timer, but I'm not sure on exactly how to do that.
I just remembered that Joe did a tile monster spawner with a timer in the Advanced Arcade Tutorial!

NESmaker: Arcade Platformer Tutorial - Advanced
 

TheRetroBro

Active member
Using a tile to spawn monsters can be a little tricky. It's much better to make a monster spawner object. You could use an AI like this (it will also limit monsters):



Make an invisible monster and assign this AI action to the first action step. Give it a timer like 2 or 3 (or whatever), and EndAction = Repeat.
Do we count the monster objects the same way we count game objects (IE vertically player 00, Object 01 (projectile) etc etc?
 

baardbi

Well-known member
Do we count the monster objects the same way we count game objects (IE vertically player 00, Object 01 (projectile) etc etc?
Well. We count objects with the CountObjects macro. So if you want to count player weapon objects for example, you do this:

CountObjects #%00000100 ;;; Player weapon
CMP #2 ;;; Two player weapon objects

If you want to count a specific object type you can use a macro I posted here a few months ago:


And yes, like ProjectAsinus said, monster objects start at 16. So game objects are 0 - 15, and monster objects are from 16 and up.
 

TheRetroBro

Active member
Well. We count objects with the CountObjects macro. So if you want to count player weapon objects for example, you do this:

CountObjects #%00000100 ;;; Player weapon
CMP #2 ;;; Two player weapon objects

If you want to count a specific object type you can use a macro I posted here a few months ago:


And yes, like ProjectAsinus said, monster objects start at 16. So game objects are 0 - 15, and monster objects are from 16 and up.
Perfect TY for claryfying
 
Top Bottom