bullet recoil, use tau
This commit is contained in:
parent
f5df911707
commit
5bcf22a6f8
2 changed files with 8 additions and 13 deletions
|
|
@ -10,7 +10,7 @@ local function initGame()
|
|||
radius = 30,
|
||||
bullet = {
|
||||
radius = 5,
|
||||
recoil = -10,
|
||||
recoil = 10,
|
||||
speed = 500,
|
||||
time = 4,
|
||||
sound = love.sound.newSoundData('resources/bullet.mp3'),
|
||||
|
|
@ -104,7 +104,7 @@ function love.update(dt)
|
|||
end
|
||||
|
||||
local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate
|
||||
state.ship.facing = (state.ship.facing + spin * dt) % phys.tau
|
||||
state.ship.facing = (state.ship.facing + spin * dt)
|
||||
end
|
||||
update(state.ship, dt)
|
||||
|
||||
|
|
@ -121,8 +121,8 @@ function love.update(dt)
|
|||
if phys.intersects(bullet, asteroid) then
|
||||
table.remove(state.bullets, bulletIndex)
|
||||
if asteroid.stage > 1 then
|
||||
local angle1 = love.math.random() * (2 * math.pi)
|
||||
local angle2 = (angle1 - math.pi) % (2 * math.pi)
|
||||
local angle1 = love.math.random() * phys.tau
|
||||
local angle2 = angle1 - phys.tau / 2
|
||||
local radius = game.asteroids.stages[asteroid.stage - 1].radius
|
||||
local speed = game.asteroids.stages[asteroid.stage - 1].speed
|
||||
table.insert(state.asteroids, {
|
||||
|
|
@ -158,7 +158,7 @@ function love.update(dt)
|
|||
end
|
||||
|
||||
if #state.asteroids == 0 then
|
||||
--reset()
|
||||
reset()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -180,8 +180,7 @@ function love.gamepadpressed(joystick, button)
|
|||
}
|
||||
table.insert(state.bullets, bullet)
|
||||
bullet.sound:play()
|
||||
--state.ship.speed.x = state.ship.speed.x + math.cos(state.ship.angle) * game.ship.bullet.recoil
|
||||
--state.ship.speed.y = state.ship.speed.y + math.sin(state.ship.angle) * game.ship.bullet.recoil
|
||||
phys.apply(state.ship, { speed = game.ship.bullet.recoil, angle = state.ship.facing + phys.tau / 2 })
|
||||
end
|
||||
if button == "x" then
|
||||
print(inspect(state.ship))
|
||||
|
|
@ -198,7 +197,7 @@ function love.draw()
|
|||
love.graphics.draw(game.ship.sprite,
|
||||
state.ship.x,
|
||||
state.ship.y,
|
||||
(state.ship.facing + math.pi / 2) % (math.pi * 2),
|
||||
(state.ship.facing + phys.tau / 4) % phys.tau,
|
||||
scale,
|
||||
scale,
|
||||
game.ship.sprite:getWidth() / 2,
|
||||
|
|
|
|||
|
|
@ -18,10 +18,6 @@ function phys.update(actor, dt)
|
|||
actor.y = actor.y + math.sin(actor.angle) * dv
|
||||
end
|
||||
|
||||
function phys.rotate(actor, angle)
|
||||
actor.facing = (actor.facing + angle) % phys.tau
|
||||
end
|
||||
|
||||
function phys.apply(actor, force)
|
||||
local ax = math.cos(actor.angle) * actor.speed
|
||||
local ay = math.sin(actor.angle) * actor.speed
|
||||
|
|
@ -31,7 +27,7 @@ function phys.apply(actor, force)
|
|||
local y = ay + fy
|
||||
|
||||
local speed = math.sqrt(x ^ 2 + y ^ 2)
|
||||
local angle = math.atan2(y, x) % phys.tau
|
||||
local angle = math.atan2(y, x)
|
||||
actor.speed = speed
|
||||
actor.angle = angle
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue