bullet recoil, use tau

This commit is contained in:
Donald Ball 2025-11-17 20:31:14 -05:00
parent f5df911707
commit 5bcf22a6f8
2 changed files with 8 additions and 13 deletions

View file

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