I've just started this coding games business so sorry for my noobness
I'm working on a tower deference game, I'm trying to code the enemy's and I've run into the problem of I have no idea how to add multiples of the same enemy, what ever I try doesn't seem to work and I cant find on the internet what I need (mainly because I don't have much idea on what I'm supposed to look at), so I need help from the lovely people on the love2d forums
Here's the .love file of what I've done so far
https://drive.google.com/file/d/0Bwn9_x ... sp=sharing
if you need some other info just ask (as I've probably not included it because I'm really quite crap at this so far)
Need help with multiple objects
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Cucurbitacée
- Prole
- Posts: 47
- Joined: Fri Dec 14, 2012 10:22 am
- Location: Frankfurt am Main
Re: Need help with multiple objects
Hi,
I've just looked at your code and here is what I would do:
I've just looked at your code and here is what I would do:
- Create a table to hold the enemies, like this:
Code: Select all
enemies = {}
- In the function enemy.new, replace this instruction return enemyStat by this:
Code: Select all
table.insert(enemies, enemyStat)
- Replace the functions to update and draw the enemy by an iteration of the enemies table, for example:
Code: Select all
function enemy.draw() for i, v in ipairs(enemies) do love.graphics.draw(enemyImage, v.x, v.y) end end
Re: Need help with multiple objects
Thanks, now I can finally get on with coding another part of the game!
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests