AnAl question for enemies

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

AnAl question for enemies

Post by GungnirDev »

I want to make an enemy type glow and have designed a simple animation for this using ANimations And Love (AnAl). Problem being that I could not simply assign this IMG to all enemies, so I assigned them all a dummy "null" image and drew the animation at enemy.x, enemy.y provided enemy.img == null. This technically worked, however, I now get a bug wherein the animation sometimes disappears halfway down the screen. It happens about half the time; the other half of the time it works great. Suggestions?

Here is the foe.lua code (the full game is too big, but I'm fairly certain the problem is in foe.lua)

Code: Select all

 foe = {}
	
	bullets = {}
	
function trigger()	
	spawn = math.random(1,5)
	end
	
function brigger()
	spawnboss = math.random(1,6)
end

function myswerve()
	swerve = math.random(5)
end
	
dofire = 0
	
function firing()
	dofire = 1
end

	bosshealth = 100

function foe.load()

cron.every (1, trigger)

cron.every (3, brigger)

cron.every (4, myswerve)

cron.every (3, firing)

	swerve = 3
	
	spawn = 0
	
	spawnboss = 0
	
	respawn = 0
	
	reinforce = 0
	
	shootn = 0
		
	wolv = love.graphics.newImage('shmuppics/wolverine.png')
	bdgr = love.graphics.newImage('shmuppics/honeybadger.png')
	hover = love.graphics.newImage('shmuppics/hoverguard.png')
	torpido = love.graphics.newImage('shmuppics/bullet_1.png')
	bossgun_1 = love.graphics.newImage('shmuppics/bossgun_1.png')
	bossgun_2 = love.graphics.newImage('shmuppics/bossgun_3.png')
	bossgun_3 = love.graphics.newImage('shmuppics/bossgun_3.png')
	lazor = love.graphics.newImage('shmuppics/lazor.png')
	cluster = love.graphics.newImage('shmuppics/cluster.png')
	blast = love.graphics.newImage('shmuppics/explosion.png')  
	scrap1 = love.graphics.newImage('shmuppics/scrap1.png')
	scrap2 = love.graphics.newImage('shmuppics/scrap2.png')
	scrap3 = love.graphics.newImage('shmuppics/scrap3.png')
	scrap4 = love.graphics.newImage('shmuppics/scrap4.png')
	darkship_up = love.graphics.newImage('shmuppics/darkship_up.png')
	darkship_down = love.graphics.newImage('shmuppics/darkship_down.png')
	darkship_left = love.graphics.newImage('shmuppics/darkship_left.png')
	darkship_right = love.graphics.newImage('shmuppics/darkship_right.png')
	darkship_left_super = love.graphics.newImage('shmuppics/darkship_left_super.png')
	darkship_right_super = love.graphics.newImage('shmuppics/darkship_right_super.png')
	bosshp = love.graphics.newImage('shmuppics/bosshp.png')
	redship = love.graphics.newImage('shmuppics/redship.png')
	blueship = love.graphics.newImage('shmuppics/blueship.png')
	warlord = love.graphics.newImage('shmuppics/warlord.png')
	null = love.graphics.newImage('shmuppics/null.png')
	
	glowlord = newAnimation(warlord, 136, 131, 0.2, 0)
	glowlord:setMode("bounce")
		
	enemies = {}
	
	bosses = {}
	
for i=0,2 do
    enemy = {}
    enemy.img = wolv
    enemy.width = 50
    enemy.height = 20
    enemy.x = i * (enemy.width + 100) + 100
    enemy.y = i * (enemy.height) - 400
    table.insert(enemies, enemy)
	end
	

	
end

function foe.update(dt)

glowlord:update(dt)

if bosshealth < 1 then
bosshealth = 0
end

for _, bullet in ipairs(bullets) do
	if CheckCollision(player.x, player.y, player.width, player.height, bullet.x, bullet.y, bullet.width, bullet.height) then
	playerhealth = playerhealth - 5
	end
end

shootn = shootn + 1
if shootn > 50 then
shootn = 0
end

for i,v in ipairs(bullets) do
if v.img == torpido then
v.y = v.y + 700 * dt
elseif v.img == bossgun_1 then
v.y = v.y + 1000 * dt
elseif v.img == bossgun_2 then
v.x = v.x - 800 * dt
elseif v.img == bossgun_3 then
v.x = v.x + 800 * dt
elseif v.img == lazor then
v.y = v.y + 1000 * dt
elseif v.img == cluster then
v.y = v.y + 700 * dt
if v.x > player.x and v.y < player.y then
v.x = v.x - v.y * 0.3 * dt
elseif v.x < player.x and v.y < player.y then
v.x = v.x + v.y * 0.3 * dt
		end
	end
end

remBullet = {}

for i,v in ipairs(enemies) do
if v.img == hover then
if v.aim == shootn then
	bullet = {}
	bullet.img = torpido
	bullet.x = v.x + 70
	bullet.y = v.y + 50
	bullet.width = 10
	bullet.height = 10
	table.insert(bullets, bullet) -- reset
		end
	end
	
if v.img == blueship then
if v.aim == shootn then
	bullet = {}
	bullet.img = lazor
	bullet.x = v.x + 90
	bullet.y = v.y + 50
	bullet.width = 20
	bullet.height = 60
	table.insert(bullets, bullet) -- reset
		end
	end
	
if v.img == redship then
if v.aim == shootn then

	bullet = {}
	bullet.img = cluster
	bullet.x = v.x + 90
	bullet.y = v.y + 50
	bullet.width = 1
	bullet.height = 1
	table.insert(bullets, bullet) -- reset
	
	bullet = {}
	bullet.img = cluster
	bullet.x = v.x + 25
	bullet.y = v.y + 50
	bullet.width = 1
	bullet.height = 1
	table.insert(bullets, bullet)
	
	bullet = {}
	bullet.img = cluster
	bullet.x = v.x + 50
	bullet.y = v.y + 70
	bullet.width = 1
	bullet.height = 1
	table.insert(bullets, bullet)
	
	bullet = {}
	bullet.img = cluster
	bullet.x = v.x + 75
	bullet.y = v.y + 70
	bullet.width = 1
	bullet.height = 1
	table.insert(bullets, bullet)
	
	bullet = {}
	bullet.img = cluster
	bullet.x = v.x + 100
	bullet.y = v.y + 50
	bullet.width = 1
	bullet.height = 1
	table.insert(bullets, bullet)
	
		end
	end
	
end

for i,v in ipairs(bosses) do
if v.img == darkship_down then
if v.aim == shootn then
	bullet = {}
	bullet.img = bossgun_1
	bullet.x = v.x + 70
	bullet.y = v.y + 50
	bullet.width = 10
	bullet.height = 10
	table.insert(bullets, bullet) -- reset
	end
end
	
if v.img == darkship_left then
if v.aim == shootn then
	bullet = {}
	bullet.img = bossgun_3
	bullet.x = v.x + 70
	bullet.y = v.y + 70
	bullet.width = 50
	bullet.height = 50
	table.insert(bullets, bullet) -- reset
	end
end
	
if v.img == darkship_right then
if v.aim == shootn then
	bullet = {}
	bullet.img = bossgun_2
	bullet.x = v.x + 70
	bullet.y = v.y + 70
	bullet.width = 50
	bullet.height = 50
	table.insert(bullets, bullet) -- reset
		end
	end
end

if stage == 1 then
	
	if spawn == 1 then
	for i=0,4 do
	enemy = {}
	enemy.img = wolv
	enemy.width = 70
	enemy.height = 20
	enemy.x = i * (enemy.width + 100) + 100
	enemy.y = i * (enemy.height) - 400
	enemy.aim = 100
	enemy.timer = 0
	table.insert(enemies, enemy)
	spawn = 0
	end
end
	
	if spawn == 2 then
	for i=0,5 do
	enemy = {}
	enemy.img = wolv
	enemy.width = 70
	enemy.height = 20
	enemy.x = i * (enemy.width + 200) + 200
	enemy.y = i * (enemy.height) - 400
	enemy.aim = 100
	enemy.timer = 0
	table.insert(enemies, enemy)
	spawn = 0
	end
end

	if spawn == 3 then
	for i=0,3 do
	enemy = {}
	enemy.img = wolv
	enemy.width = 70
	enemy.height = 20
	enemy.x = i * (enemy.width + 150) + 100
	enemy.y = i * (enemy.height) - 400
	enemy.aim = 100
	enemy.timer = 0
	table.insert(enemies, enemy)
	spawn = 0
	end
end	

	if spawn == 4 then
	for i=0,1 do
	enemy = {}
	enemy.img = hover
    enemy.width = 70
    enemy.height = 20
    enemy.x = i * (enemy.width + 100) - 300
    enemy.y = i * (enemy.height - 70) + 100
	enemy.aim = math.random( 1, 49 )
	enemy.timer = 0
    table.insert(enemies, enemy)
    spawn = 0
    
    end
end
    
    if spawn == 5 then
    for i=0,1 do
    enemy = {}
    enemy.img = bdgr
    enemy.width = 70
    enemy.height = 20
    enemy.x = i * (enemy.width) + 800
    enemy.y = i * (enemy.height) - 200
    enemy.aim =  100
    enemy.timer = 0
    table.insert(enemies, enemy)
    spawn = 0
		end    
	end
end

if stage == 2 then

end

if stage == 3 then

end

if stage == 4 then
	
	if spawnboss == 1 then
for i=0,0 do
	boss = {}
	boss.img = darkship_right
	boss.width = 80
    boss.height = 60
    boss.x = i * (enemy.width) + 1200
    boss.y = i * (enemy.height) + 400 + 50
    boss.aim = math.random( 1, 69 )
    table.insert(bosses, boss)
    spawnboss = 0
	end
end

if spawnboss == 2 then
for i=0,0 do
	boss = {}
	boss.img = darkship_left
	boss.width = 80
    boss.height = 60
    boss.x = i * (enemy.width) - 200
    boss.y = i * (enemy.height) + 400 + 50
    boss.aim = math.random( 1, 69 )
    table.insert(bosses, boss)
    spawnboss = 0
	end
end

if spawnboss == 3 then
for i=0,0 do
	boss = {}
	boss.img = darkship_right_super
	boss.width = 100
    boss.height = 220
    boss.x = i * (enemy.width) + 1200
    boss.y = i * (enemy.height) + swerve * 150
    table.insert(bosses, boss)
    spawnboss = 0
	end
end

if spawnboss == 4 then
for i=0,0 do
	boss = {}
	boss.img = darkship_left_super
	boss.width = 100
    boss.height = 220
    boss.x = i * (enemy.width) - 200
    boss.y = i * (enemy.height) + swerve * 150
    table.insert(bosses, boss)
    spawnboss = 0
	end
end

if spawnboss == 5 then
for i=0,0 do
	boss = {}
	boss.img = darkship_up
	boss.width = 80
    boss.height = 60
    boss.x = i * (enemy.width) + 500
    boss.y = i * (enemy.height) + 1000
    table.insert(bosses, boss)
    spawnboss = 0
	end
end

if spawnboss == 6 then
for i=0,0 do
	boss = {}
	boss.img = darkship_down
	boss.width = 80
    boss.height = 60
    boss.x = i * (enemy.width) + 500
    boss.y = i * (enemy.height) - 200
    boss.aim = math.random( 1, 49 )
    table.insert(bosses, boss)
    spawnboss = 0
	end
end
	
	if spawn == 1 then
	for i=0,2 do
	enemy = {}
	enemy.img = scrap1
	enemy.width = 80
	enemy.height = 30
	enemy.x = i * (enemy.width) + 300 * swerve
    enemy.y = i * (enemy.height + 200) - 500
    enemy.aim =  100
    enemy.timer = 0
    table.insert(enemies, enemy)
    spawn = 0
    swerve = math.random(5)
	end
end

	if spawn == 2 then
	for i=0,1 do
	enemy = {}
	enemy.img = scrap2
	enemy.width = 80
	enemy.height = 30
	enemy.x = i * (enemy.width) + swerve  + 250 * swerve
    enemy.y = i * (enemy.height + 300) - 500
    enemy.aim =  100
    enemy.timer = 0
    table.insert(enemies, enemy)
    spawn = 0
    swerve = math.random(4)	
    end
end

	if spawn == 3 then
	for i=0,0 do
	enemy = {}
	enemy.img = scrap3
	enemy.width = 80
	enemy.height = 30
	enemy.x = i * (enemy.width) + 100 * swerve
    enemy.y = i * (enemy.height + 300) - 300
    enemy.aim =  100
    enemy.timer = 0
    table.insert(enemies, enemy)
    spawn = 0
    swerve = math.random (3,5)
	end
end

	if spawn == 4 then
	for i=0,0 do
	enemy = {}
	enemy.img = scrap4
	enemy.width = 80
	enemy.height = 30
	enemy.x = i * (enemy.width + 100 * swerve) + 600
    enemy.y = i * (enemy.height + 200) - 300
    enemy.aim =  100
    enemy.timer = 0
    table.insert(enemies, enemy)
    spawn = 0
    swerve = math.random (2,4)
    	end
	end
end

if stage == 5 then

if spawn == 1 then
	for i=0,0 do
	enemy = {}
	enemy.img = blueship
	enemy.width = 80
	enemy.height = 50
	enemy.x = i * (enemy.width + 100) - 100
	enemy.y = i
	enemy.aim = math.random(30,49)
	enemy.timer = 0
	table.insert(enemies, enemy)
	spawn = 0
	end
end

if spawn == 2 then
	for i=0,0 do
	enemy = {}
	enemy.img = redship
	enemy.width = 80
	enemy.height = 50
	enemy.x = i * (enemy.width + 100) + 600
	enemy.y = i - 100
	enemy.aim = math.random(30,49)
	enemy.timer = 0
	table.insert(enemies, enemy)
	spawn = 0
	end
end

if spawn == 3 then
	for i=0,3 do
	enemy = {}
	enemy.img = wolv
	enemy.width = 70
	enemy.height = 20
	enemy.x = i * (enemy.width + 150) + 100
	enemy.y = i * (enemy.height) - 400
	enemy.aim = 100
	enemy.timer = 0
	table.insert(enemies, enemy)
	spawn = 0
	end
end	

if spawn == 4 then
	for i=0,0 do
	enemy = {}
	enemy.img = null
	enemy.width = 80
	enemy.height = 50
	enemy.x = i * (enemy.width + 100) + 600
	enemy.y = i - 100
	enemy.aim = 100
	enemy.timer = 0
	table.insert(enemies, enemy)
	spawn = 0
	end
end


end

remEnemy = {}

remBoss = {}

if gamestate == "playing" or "winstage" then

for i, v in ipairs(bullets) do
	if v.y > 920 then
	table.insert(remBullet, i)
	end
end

	for i, v in ipairs(remBullet) do
	table.remove(bullet, i)
end

for i,v in ipairs(enemies) do
	if v.img == wolv then
    v.y = v.y + dt * 300
    v.x = v.x + math.cos(game.clock) * swerve
    elseif v.img == hover then
    v.x = v.x + dt * 300
    elseif v.img == bdgr then
    v.x = v.x - dt * 500
    v.y = v.y + dt * 500
    elseif v.img == torpido then
    v.y = v.y + dt * 800
    elseif v.img == scrap1 then
    v.x = v.x - dt * 15
    v.y = v.y + dt * 100
    elseif v.img == scrap2 then
    v.x = v.x + dt * 5
    v.y = v.y + dt * 250
    elseif v.img == scrap3 then
    v.x = v.x + dt * 30
    v.y = v.y + dt * 30
    elseif v.img == scrap4 then
    v.x = v.x - dt * 50
    v.x = v.x + dt * 10
    elseif v.img == blueship then
    if v.x > player.x then
    v.x = v.x - dt * 30 * swerve
    elseif v.x < player.x then
    v.x = v.x + dt * 30 * swerve
    end
    elseif v.img == redship then
    if v.x > player.x then
    v.y = v.y + dt * 500
    v.x = v.x + dt * 100
    elseif v.x < player.x then
    v.y = v.y + dt * 400
    v.x = v.x - dt * 100
    end
    elseif v.img == null then
    v.y = v.y + dt * 500
end
	
	-- mark enemies that are not visible for removal
    if v.y > 920 then
    table.insert(remEnemy, i)
end
    if v.x > 1400 then
    table.insert(remEnemy, i)
end
    if v.x < -300 then
	table.insert(remEnemy, i)
end
                
    for i, v in ipairs(remEnemy) do
	 table.remove(enemy, i)
	end
end

	for i,v in ipairs(bosses) do
	if v.img == darkship_right then
	v.y = v.y + math.cos(game.clock) * swerve
    v.x = v.x - dt * 500
    elseif v.img == darkship_left then
	v.y = v.y + math.cos(game.clock) * swerve
    v.x = v.x + dt * 500
	elseif v.img == darkship_left_super then
	v.x = v.x + dt * 600
	elseif v.img == darkship_right_super then
	v.x = v.x - dt * 600
	elseif v.img == darkship_up then
	v.y = v.y - dt * 500
	v.x = v.x + math.cos(game.clock) * swerve
	elseif v.img == darkship_down then
	v.y = v.y + dt * 500
	end
	
	if v.y < 400 then
	table.insert(remBoss, i)
end
	if v.y > 920 then
    table.insert(remBoss, i)
end
    if v.x > 1400 then
    table.insert(remBoss, i)
end
    if v.x < -300 then
	table.insert(remBoss, i)
end

	for i, v in ipairs(remBoss) do
	table.remove(boss, v)
end
			end	
		end
	end

function foe.draw()

if enemy.img == null then
glowlord:draw(enemy.x, enemy.y)
end

love.graphics.setColor(255,100,100,200)
love.graphics.rectangle("fill", 980, 110, 20, bosshealth * 6)	

love.graphics.setColor(255,255,255,255)

love.graphics.draw(bosshp, 973, 102)


if gamestate == 'playing' then
	for i,v in ipairs(bullets) do
	love.graphics.draw (v.img, v.x, v.y)
	end
end
	

	for i,v in ipairs(enemies) do
    love.graphics.draw (v.img, v.x, v.y)
	end
	
if gamestate == 'playing' then
	for i,v in ipairs(bosses) do
	love.graphics.draw (v.img, 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: AnAl question for enemies

Post by GungnirDev »

anyone?
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
User avatar
Codex
Party member
Posts: 106
Joined: Tue Mar 06, 2012 6:49 am

Re: AnAl question for enemies

Post by Codex »

I would love to help, but I've never used Anal before. I suggest you try printing out debugging info though and trying to pinpoint the problem if you haven't already. Also, I suspect a lot of the love community is busy with Christmas holidays so you likely won't get a better answer until after the 25th-ish.

Sorry I couldn't be more help. :3
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Re: AnAl question for enemies

Post by GungnirDev »

No, that's OK.

Printing debugging info is one thing but the problem is that it doesn't appear to be a bug. I'm not getting any sort of error message; it's all in working order except that the enemy disappears halfway down the screen.
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: AnAl question for enemies

Post by GungnirDev »

anyone?
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: AnAl question for enemies

Post by Robin »

If you want help upload a .love.
Help us help you: attach a .love.
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Re: AnAl question for enemies

Post by GungnirDev »

Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests