Enemy spawnage
Posted: Mon Apr 07, 2014 10:42 pm
Me and my friends have been coding a game similar to the Atari game asteroids and I was having a bit of trouble spawning enemies (squares) on a time delay.
I have this much so far can any one help me along?
function love.load()
enemy = {x = 300, y = 300, angle = 0,speed = 50}
timer = 1
end
function newDirection()
-- This line allows arbitrary angles
-- enemy.angle = love.math.random()*2*math.pi
-- This line only allows up,down,left,right
enemy.angle = love.math.random(0,3)*0.5*math.pi
timer = 1
end
function moveenemy(dt)
enemy.x = enemy.x + math.cos(enemy.angle)*enemy.speed*dt
enemy.y = enemy.y + math.sin(enemy.angle)*enemy.speed*dt
end
function love.update(dt)
timer = timer - dt
if timer < 0 then
newDirection()
end
moveenemy(dt)
end
I have this much so far can any one help me along?
function love.load()
enemy = {x = 300, y = 300, angle = 0,speed = 50}
timer = 1
end
function newDirection()
-- This line allows arbitrary angles
-- enemy.angle = love.math.random()*2*math.pi
-- This line only allows up,down,left,right
enemy.angle = love.math.random(0,3)*0.5*math.pi
timer = 1
end
function moveenemy(dt)
enemy.x = enemy.x + math.cos(enemy.angle)*enemy.speed*dt
enemy.y = enemy.y + math.sin(enemy.angle)*enemy.speed*dt
end
function love.update(dt)
timer = timer - dt
if timer < 0 then
newDirection()
end
moveenemy(dt)
end