gamepad fire
This commit is contained in:
parent
18062e9ca1
commit
1b1ed94b2f
1 changed files with 15 additions and 16 deletions
|
|
@ -7,7 +7,6 @@ local function initGame()
|
|||
ship = {
|
||||
radius = 30,
|
||||
bullet = {
|
||||
timerLimit = 0.5,
|
||||
radius = 5,
|
||||
speed = 500,
|
||||
time = 4,
|
||||
|
|
@ -65,8 +64,6 @@ local function initState()
|
|||
y = 0,
|
||||
}
|
||||
},
|
||||
-- the time after which the ship can fire another bullet
|
||||
bulletTimer = game.ship.bullet.timerLimit,
|
||||
bullets = {},
|
||||
asteroids = asteroids,
|
||||
controls = {
|
||||
|
|
@ -136,19 +133,6 @@ function love.update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
state.bulletTimer = state.bulletTimer + dt
|
||||
if love.keyboard.isDown('s') then
|
||||
if state.bulletTimer >= game.ship.bullet.timerLimit then
|
||||
state.bulletTimer = 0
|
||||
table.insert(state.bullets, {
|
||||
x = state.ship.x + math.cos(state.ship.angle) * game.ship.radius,
|
||||
y = state.ship.y + math.sin(state.ship.angle) * game.ship.radius,
|
||||
angle = state.ship.angle,
|
||||
timeLeft = game.ship.bullet.time,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
for _, asteroid in ipairs(state.asteroids) do
|
||||
asteroid.x = (asteroid.x + math.cos(asteroid.angle) * game.asteroids.stages[asteroid.stage].speed * dt) %
|
||||
game.width
|
||||
|
|
@ -166,6 +150,21 @@ function love.update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
function love.gamepadpressed(joystick, button)
|
||||
if joystick ~= state.controls.joystick then
|
||||
return
|
||||
end
|
||||
if button == "b" then
|
||||
-- debounce, perhaps
|
||||
table.insert(state.bullets, {
|
||||
x = state.ship.x + math.cos(state.ship.angle) * game.ship.radius,
|
||||
y = state.ship.y + math.sin(state.ship.angle) * game.ship.radius,
|
||||
angle = state.ship.angle,
|
||||
timeLeft = game.ship.bullet.time,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
for y = -1, 1 do
|
||||
for x = -1, 1 do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue