spinning asteroids
This commit is contained in:
parent
eae3659768
commit
63b296e19c
2 changed files with 5 additions and 4 deletions
|
|
@ -58,7 +58,7 @@ local function initState()
|
||||||
local stage = game.asteroids.stages[asteroid.stage]
|
local stage = game.asteroids.stages[asteroid.stage]
|
||||||
asteroid.speed = stage.speed
|
asteroid.speed = stage.speed
|
||||||
asteroid.facing = math.random() * phys.tau
|
asteroid.facing = math.random() * phys.tau
|
||||||
asteroid.spin = 2 + math.random() * 5
|
asteroid.spin = 0.1 + math.random() * 0.1
|
||||||
asteroid.radius = stage.radius
|
asteroid.radius = stage.radius
|
||||||
asteroid.sprite = stage.sprite
|
asteroid.sprite = stage.sprite
|
||||||
end
|
end
|
||||||
|
|
@ -141,7 +141,7 @@ function love.update(dt)
|
||||||
radius = radius,
|
radius = radius,
|
||||||
speed = speed,
|
speed = speed,
|
||||||
facing = math.random() * phys.tau,
|
facing = math.random() * phys.tau,
|
||||||
spin = 2 + math.random() * 5,
|
spin = 0.1 + math.random() * 0.1,
|
||||||
sprite = sprite,
|
sprite = sprite,
|
||||||
})
|
})
|
||||||
table.insert(state.asteroids, {
|
table.insert(state.asteroids, {
|
||||||
|
|
@ -152,7 +152,7 @@ function love.update(dt)
|
||||||
radius = radius,
|
radius = radius,
|
||||||
speed = speed,
|
speed = speed,
|
||||||
facing = math.random() * phys.tau,
|
facing = math.random() * phys.tau,
|
||||||
spin = 2 + math.random() * 5,
|
spin = 0.1 + math.random() * 0.1,
|
||||||
sprite = sprite,
|
sprite = sprite,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,13 @@ function phys.intersects(actor1, actor2)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- updates the actor's location by applying the passage of time
|
-- updates the actor's location by applying the passage of time
|
||||||
-- TODO spin
|
|
||||||
function phys.update(actor, dt)
|
function phys.update(actor, dt)
|
||||||
assert(actor.speed >= 0)
|
assert(actor.speed >= 0)
|
||||||
local dv = actor.speed * dt
|
local dv = actor.speed * dt
|
||||||
actor.x = actor.x + math.cos(actor.angle) * dv
|
actor.x = actor.x + math.cos(actor.angle) * dv
|
||||||
actor.y = actor.y + math.sin(actor.angle) * dv
|
actor.y = actor.y + math.sin(actor.angle) * dv
|
||||||
|
local dr = actor.spin * dt
|
||||||
|
actor.facing = (actor.facing + dr) % phys.tau
|
||||||
end
|
end
|
||||||
|
|
||||||
function phys.apply(actor, force)
|
function phys.apply(actor, force)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue