What is the best way to handle many enemies?

J

Jacob Thrasher

Guest
In a platformer I am working on I would like to have various types of enemies, each with different abilities. I am unsure of what is the best way to go about including them so that the code runs as quickly and as smoothly as possible.

I have two things in mind:
-Creating a unique enemy object for each type of enemy and having the bullet object test for collisions with each type of enemy object. This would require a lot of collision checks, which I know slow the program.

OR

-Create one enemy object in which I can easily change the sprite indexes within in creation code. Then within the object, I would use various if statements to determine which type of enemy it is supposed to be and it would only access the necessary code for that instance. This would then require only one collision check from the bullet object, but I would also have to have a bunch of logical tests which could also slow the game down.

It is really a matter of what will be the most efficient way for GameMaker to interpret the code. This is my first game so I am pretty inexperienced. I would like to avoid as many bad practices as I can while I learn.

Thank you!
 
T

Timothy

Guest
This would then require only one collision check from the bullet object
Not true... they are still separate instances.

An option that you did not consider, is using a common parent for our different enemy objects. Either way, your collision checks will remain the same and will scale with the amount of instances you create. GMS2 does some sort of spatial partitioning to make it more efficient... RTree I think.
 

Slyddar

Member
Just create a parent object, say o_enemy_par, and make each enemy a child of that object. Then your collision code will test against that parent object.
 
Top