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?
Multiple enemy animations with AnAl
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- GungnirDev
- Party member
- Posts: 119
- Joined: Thu Jun 28, 2012 10:31 pm
Multiple enemy animations with AnAl
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
Bullets are the beauty and I don't know why
- GungnirDev
- Party member
- Posts: 119
- Joined: Thu Jun 28, 2012 10:31 pm
Re: Multiple enemy animations with AnAl
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
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
Bullets are the beauty and I don't know why
- GungnirDev
- Party member
- Posts: 119
- Joined: Thu Jun 28, 2012 10:31 pm
Re: Multiple enemy animations with AnAl
Seriously guys. I got nothin'.
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
Bullets are the beauty and I don't know why
Re: Multiple enemy animations with AnAl
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
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
Last edited by adnzzzzZ on Tue Oct 10, 2017 6:32 pm, edited 1 time in total.
Re: Multiple enemy animations with AnAl
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:
Furthermore, in this section of your code:
.... 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.
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
Code: Select all
foe.x = i * (foe.width + 100) + 50
foe.y = i * (foe.height + 100) + 50
foe.width = 150
foe.height = 120
Finally,
Code: Select all
for i = 0, 0 do
Code: Select all
for i = 1, 10 do
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.
Who is online
Users browsing this forum: Bing [Bot], t3hgreen and 2 guests