Multiple enemies

In the game I’m trying to write I would like to have multiple enemies each with their own set of attributes (enemy type, life, speed etc). What is the easiest way of storing the details of any active enemies (adding them as new ones are spawned and deleting them as they are killed)?

One of the guys I work with wondered if Lua has a ‘type’ function similar to that in Blitzbasic which would be perfect for what I need. The closest I can find is the display group, but I can’t see how that can store the different attributes of each child member.

Thanks. [import]uid: 7841 topic_id: 10284 reply_id: 310284[/import]

maybe you can try adding a function for each type of enemy
local function SpawnEnemy1()
–create the enemy and insert it to table with its parameters --like speed , helth …etc

end
local function SpawnEnemy2()
end
local function SpawnEnemy3()
end
–call this function in the appropriate time - eg. after hitting
local function DelEnemy()
–iterate through the tables of the enemy you have and see --whether the enemy object is out of the screen or has been --killed …etc and then delete it
end

it can be done through various way but this what i would do in your case

Regards [import]uid: 46546 topic_id: 10284 reply_id: 37522[/import]

@appletreeman,
did you try creating a class called enemies. In LUA, the easiest way would be to create a table

eachEnemy = {}
eachEnemy.type = ALIEN_SPACESHIP
eachEnemy.Life=10
eachEnemy.Speed=20

and so on like a type structure

I am not going into too much detail, hope you get the idea.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 10284 reply_id: 37597[/import]

Still not sure how I’m going to work this. A 3D array would work, and I’m guessing tables in Lua are like arrays, but is it possible to have one like a 3D array?

Not tried creating a class either as I’ve no idea about them. Are there any good easily understood tutorials about tables and/or classes to have a look at as the Corona docs don’t really go into a great deal of detail.

Cheers. [import]uid: 7841 topic_id: 10284 reply_id: 37811[/import]