Thanks for the replies. I have another question. I was wondering how to refer to "Any" table value. For example, right now I have an "enemy_direction" and a series of "if statements" that change the direction the sprite is facing. I would like to give each of my enemies a direction so that they can independently turn themselves in relevance to player position, Since right now they turn and look at the character.
So heres what I have. First a function that will change enemy direction depending on where the player is. I know it's sloppy.
Code: Select all
function CheckDirection(obj1, obj2)
if obj1.x > obj2.x + obj2.w - 1 then
enemy_direction = "right"
return false
elseif obj1.y > obj2.y + obj2.h - 1 then
enemy_direction = "down"
return false
elseif obj2.x > obj1.x + obj1.w - 1 then
enemy_direction = "left"
return false
elseif obj2.y > obj1.y + obj1.h - 1 then
enemy_direction = "up"
return false
else
return true -- Yes collision. Ouch!
end
end
and here are the if statements (i know there should be elseif's, will clean later):
Code: Select all
if enemy_direction == "right" then
enemy_state = enemy_anim.enemy_walkright
end
if enemy_direction == "left" then
enemy_state = enemy_anim.enemy_walkleft
end
if enemy_direction == "up" then
enemy_state = enemy_anim.enemy_walkup
end
if enemy_direction == "down" then
enemy_state = enemy_anim.enemy_walkdown
end
So I guess instead of there being one single "enemy_direction" I would like to add a direction to each enemy. So it would be like this:
Code: Select all
if enemies[1].dir == "down" then
enemy_state = enemy_anim.enemy_walkdown
end
But obviously I would like that to apply to ALL enemies, not just the single one. Else, I would have to rewrite that IF for every enemy.
Also after re-reading I would need to give each enemy it's own enemy_state as well. Though this would be the same as direction so It's not a problem.
I'm really tired at the moment, have been up about 30 hours now so excuse any mistakes I may have made. I've uploaded the love if you would like to check through my code. I know everything is all over the place right now, but I will of course optimize everything when I need to. Thanks again everyone!
http://dl.dropbox.com/u/7905642/zombies_00.love