Page 1 of 1
Multiple enemy animations with AnAl
Posted: Wed Apr 24, 2013 8:13 pm
by GungnirDev
I'm trying to do spawncode in order to spawn a number of animated enemies, all with their own hit points. It has not been a problem as I did this in my last game, Invictus, with the basic table method, but only with standard images and not animations.
Could someone show me an example of how you would do this using AnAl for the enemies?
Re: Multiple enemy animations with AnAl
Posted: Sat May 04, 2013 4:30 am
by GungnirDev
This is the relevant code which I am using. For some reason it will only draw the most recent enemy spawned even though it is obvious that several enemies exist on screen. At first I thought it was a problem with AnAl but it refuses to draw anything, even sprites that are not animations.
Code: Select all
foes = {}
foe = {}
if spawnwheel == 1 then
for i=0,0 do
foe.id = wheel
foe.x = i * (foe.width + 100) + 50
foe.y = i * (foe.height + 100) + 50
foe.width = 150
foe.height = 120
foe.live = true
foe.hp = 10
foe.grav = 0
foe.pattern = swarm
foe.attacking = true
foe.speed = 5
foe.dir = "left"
table.insert(foes, foe)
spawnwheel = 0
end
...
for i,v in pairs(foes) do
if v.live == true then
love.graphics.rectangle("fill", v.x, v.y, 0 + v.hp, 5)
love.graphics.draw (placeholder, v.x, v.y)
if v.id == wheel then
wanyudo:draw(v.x, v.y)
end
end
end
Re: Multiple enemy animations with AnAl
Posted: Mon May 06, 2013 7:03 pm
by GungnirDev
Seriously guys. I got nothin'.
Re: Multiple enemy animations with AnAl
Posted: Tue May 07, 2013 4:12 am
by thingdeux
I can't see all of your code but if I'm reading this right...you've told your program to only create one enemy twice.
You enclosed your if statement in a block that says if spawnwheel == 1 -- and you set spawnwheel to 0 at the end of the for statement. (So if there was a for statement before this it wouldn't run again)
And your for statement is only doing one pass:
for i = 0, 0 do --- This will only run once so you won't get any additional enemies.
If you did:
for i =1, 2 do -- that would create two enemies
for i =1, 4 do -- that would create four enemies
Re: Multiple enemy animations with AnAl
Posted: Tue May 07, 2013 8:06 am
by adnzzzzZ
Re: Multiple enemy animations with AnAl
Posted: Wed May 08, 2013 2:49 pm
by Robin
No .love for us.
Re: Multiple enemy animations with AnAl
Posted: Thu May 09, 2013 8:09 am
by hryx
thesmeagle,
Robin is referring to the
forum rules. See that
big pink banner atop the forum? You should read it. (Additionally, triple-posting will make Bartbes a grumpy monkey...)
As for your code, adnzzzzZ is correct. You have created a single, global table "foe", then edited its value inside the loop. You should create a new instance for each iteration:
Code: Select all
foes = {}
for i = 1, 10 do
local foe = {}
foe.x = i * 100
...
foes[i] = foe
end
Furthermore, in this section of your code:
Code: Select all
foe.x = i * (foe.width + 100) + 50
foe.y = i * (foe.height + 100) + 50
foe.width = 150
foe.height = 120
.... you are referring to the properties .width and .height
before setting them. Reverse those operations: set foe.width and foe.height first.
Finally,
is somewhat meaningless as thingdeux pointed out. To create 10 enemies:
I'd suggest starting the loop at 1, as above. Lua treats
1 as the first numeric index of a sequential array, not 0. This will matter if you plan to use table.insert() and such.
Doing all that should fill your "foes" table with 10 unique object instances. Provide us with a .love file if you'd like help actually pertaining to the animation problem.