Updating enemys

BlitzMax Forums/BlitzMax Beginners Area/Updating enemys

Lillpeter(Posted 2005) [#1]
I´m currently trying to add enemys to my game, i guess each of them (3 different enemys) will have their own type since they are going to behave very differently, and as i create these different enemys i add them to a list wich my update and draw funtions process.

What i wonder is how i´m suposed to update all my different enemys, i mean the "eachin" command i´m using in my "for" loop only acesses one type of enemy in the list, do i have to make three "for" loops to update all of them? or is there a better way, and does the same principle apply when i check the collision, i´m i bit worried in that case becuase it´s gonna be alot of loops before everythings checked if i have to divide everything up.

As for the collision at this point i´m first looping through all enemys to see if the player collides with any of them, then i´m looping through every enemy and checks each of them against all active bullets fired by the player (i´m checking the collision maually so to speak with rectangles, not with the imagecollide commands).
I´m also wondering wich loop structure that is best suited for this as well.

Any tips would be very appreciated.


Perturbatio(Posted 2005) [#2]
Presumably all your enemies share similar methods for the most part, although the implementation may be different.

if so, create an abstract parent type and derive the enemies from that. then store them all in the same list.

i.e.
Type TBaseEnemy
     Method Update() abstract
End Type

Type TWarg extends TBaseEnemy
     Method Update()
     'update your warg
     End Method
End Type

Type TOgre extends TBaseEnemy
     Method Update()
     'update your ogre
     End Method
End Type

Type TTroll extends TBaseEnemy
     Method Update()
     'update your troll
     End Method
End Type


As for the collision at this point i´m first looping through all enemys to see if the player collides with any of them, then i´m looping through every enemy and checks each of them against all active bullets fired by the player


Wouldn't it be better to perform both checks at the same time? thereby saving yourself a loop?


Rimmsy(Posted 2005) [#3]
Perty to the rescue