Multiple enemy animations with AnAl

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
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Multiple enemy animations with AnAl

Post 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?
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Re: Multiple enemy animations with AnAl

Post 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

Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Re: Multiple enemy animations with AnAl

Post by GungnirDev »

Seriously guys. I got nothin'.
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
thingdeux
Prole
Posts: 1
Joined: Thu May 02, 2013 6:16 pm

Re: Multiple enemy animations with AnAl

Post 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
User avatar
adnzzzzZ
Party member
Posts: 305
Joined: Sun Dec 26, 2010 11:04 pm
Location: Porto Alegre, Brazil

Re: Multiple enemy animations with AnAl

Post by adnzzzzZ »

 
Last edited by adnzzzzZ on Tue Oct 10, 2017 6:32 pm, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Multiple enemy animations with AnAl

Post by Robin »

No .love for us. :(
Help us help you: attach a .love.
User avatar
hryx
Party member
Posts: 110
Joined: Mon Mar 29, 2010 2:28 am
Location: SF<CA<USA

Re: Multiple enemy animations with AnAl

Post 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,

Code: Select all

for i = 0, 0 do
is somewhat meaningless as thingdeux pointed out. To create 10 enemies:

Code: Select all

for i = 1, 10 do
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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests