Jasoco wrote:Using this information I was able to come up with a sample enemy prototype framework to use in my future and current games.. (...)
Well, I prefer classes to prototypes, but I'll keep an eye on your evolution there. It's certainly a less beaten path than classic object orientation.
Jasoco wrote:Another question would be about checking for collisions with each other. How would I go about that the best way? Have to iterate over the table of enemies and check all of them against the current one. But how would I know which is the current self without passing the table id into the update function first so I know which one is the current one so as not to check against itself?
There are lots of approaches here. The simplest approach is certainly comparing every enemy with every other enemy, on each iteration.
The simplest way avoid "comparing against self" is doing exactly that:
if (other ~= current) then ....
The brute force approach is good enough when the number of objects being compared is more or less low. It increases its cost exponentially with each new object that you add. If you are going to have lots of entities simultaneously, you will probably want to trim down the number of comparisons that you do.
One approach is dividing the "space" into sections. You divide the screen into, say, 16 rectangular sections. Then, whenever you update the coordinates of each enemy, you also update the section on which that enemy is. And when you need to check for collisions, you only compare with the enemies on that section (there are special conditions for enemies "in between" sections).
Another approach is having a "hard map". A hard map is a 2d array representing your screen, usually at a smaller resolution. At the begining of each frame, the hardmap cells are reset to a "blank" state, for example the number 0. Then, on the update function, every enemy "draws itself" on the hard map. This is, it changes some 0s to 1s. Collision detection then is a matter of looking at the hardmap and checking for a 1. This method is the fastest but also the one with lowest resolution; there are occasions in which 2 entities draw a "1" on the hardmap but they don't really collide; they are just close. This is why this method is better for tile-based games, specially if movement is done tile-by-tile, and not incrementally.