Enemy/Character spawning techniques?

Blitz3D Forums/Blitz3D Programming/Enemy/Character spawning techniques?

Cubed Inc.(Posted 2012) [#1]
I've already got a system in mind but I want to make sure i'm not doing more work than I really should be.

Any help is appreciated


Rob the Great(Posted 2012) [#2]
Types, functions, and a master entity are going to be your friends in this situation. Just a simple example:
[bbcode]
Graphics3D 1024,768

SetBuffer BackBuffer()

camera = CreateCamera()

Global master_enemy = LoadMesh("Enemy.b3d")
HideEntity master_enemy

Type enemy
Field mesh
Field life#
Field AnythingElseYouNeed
End Type

While Not KeyDown(1)

CreateNewEnemy(Rnd(-100.0,100.0),0,Rnd(-100.0,100.0)

UpdateWorld
RenderWorld
Flip

Wend

Function CreateNewEnemy(xposition#,yposition#,zposition#)

e.enemy = New enemy
e\mesh = CopyEntity(master_enemy)
e\life# = 1.0
e\AnythingElseYouNeed = whatever ;just pseudo, don't take this line seriously
PositionEntity e\mesh,xposition#,ysposition#,zposition#
Return e\mesh ;If you need to keep the handle of the newly created enemy

End Function
[/bbcode]
With the example above, you can create a new enemy with a single line of code: CreateNewEnemy(x#,y#,z). If you want the new enemy to be spawned under certain circumstances, then embed the CreateNewEnemy() function in conditional If statements:
[bbcode]
;...
While Not KeyDown(1)

If Millisecs() >= time + 1000
CreateNewEnemey(x#,y#,z#)
time = Millisecs()
EndIf
;...
[/bbcode]
Then, you can create a function which updates all of the enemies at once using a For...Next loop. I hope this is what your question was aimed at.


psychicbottle(Posted 2012) [#3]
very simple, but i find things like this very very useful for keeping a nice and clean code.
nice job :]


Kryzon(Posted 2012) [#4]
I've already got a system in mind but I want to make sure i'm not doing more work than I really should be.

Any help is appreciated

What's the context of your level? how is the layout?
It's hard to elaborate a solution without this information :)


DRH(Posted 2012) [#5]
I am designing a 2d engine around a map system and camera. I use an array to store the one integer that tells the system which map object to paste on screen and which to use in collisions with the player. If you sue a similar system or one that has a camera I would suggest setting up a type called spawnpoint or something shorter. Then depending on how you want your enemies or items to appear, you can use the spawn point to interact with the camera and churn out enemies at regular intervals or just allow one with a variable to track with the spawn point to tell the spawnpoint to not create a new enemy so long as one exists with that matching number variable. when you move from room to room you can set all spawn points to activate and then delete all enemies when you leave the room. For 3d you can set it based on the player x,y,z and if your player comes near enough to a spawn point then you tell it to activate. The code is up to you cause it really depends on how you structure your engine, albeit camera based or dependent on the player's proximity or even triggered by events or room switching.