Attacking Functions.Please Help![.love]
Posted: Sat Dec 24, 2011 6:46 pm
I have made a flat grass plane, and put two zombies and steve(my character) inside of it. To draw the zombies I use..
and inside of love draw I put..
I will put my .love up for everyone to look at. But the problem is with the way I make the player attack the zombies. The code for the enemy attacking the player is at the bottom of "tables.lua" under the "enemy_attack" function. And the Code for steve attacking the enemy is in controlls.lua.
For some reason you can only attack the second zombie drawn. I think I know why though. I'm pretty sure it has to do with this little bit of code right here..
sence there are two "v"'s I'm pretty sure it's messing that up. So how would I re-write that?
Any and all help is appreciated:)
P.S. use "a,d" to move, "w" to fly(temp), and "J" to attack
Code: Select all
function spawnZombie(x,y,speed,health,detection)
table.insert(enemies, {x = x, y = y, speed = speed, health = health, detection = detection, pic = love.graphics.newImage("pics/zombie.png")})
end
Code: Select all
for i,v in ipairs(enemies) do
love.graphics.draw(v.pic, v.x, v.y)
end
For some reason you can only attack the second zombie drawn. I think I know why though. I'm pretty sure it has to do with this little bit of code right here..
Code: Select all
if key == "j" and
side == right and
steve.x > v.x - steve.reach and
steve.x < v.x + steve.reach then
v.health = v.health - steve.damage
v.x = v.x - 30
v.y = v.y - 15
end
Any and all help is appreciated:)
P.S. use "a,d" to move, "w" to fly(temp), and "J" to attack