Need help with multiple objects

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
smijjy
Prole
Posts: 2
Joined: Tue Jul 29, 2014 3:57 pm

Need help with multiple objects

Post by smijjy »

I've just started this coding games business so sorry for my noobness :P

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)

:P
User avatar
Cucurbitacée
Prole
Posts: 47
Joined: Fri Dec 14, 2012 10:22 am
Location: Frankfurt am Main

Re: Need help with multiple objects

Post by Cucurbitacée »

Hi,

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
Hope that helps.
smijjy
Prole
Posts: 2
Joined: Tue Jul 29, 2014 3:57 pm

Re: Need help with multiple objects

Post by smijjy »

Thanks, now I can finally get on with coding another part of the game! :)
Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests