autofire
This commit is contained in:
parent
419f858b1b
commit
5e47a5773c
1 changed files with 13 additions and 9 deletions
22
main.lua
22
main.lua
|
|
@ -11,6 +11,8 @@ function love.load()
|
||||||
shipRadius = 30
|
shipRadius = 30
|
||||||
|
|
||||||
bullets = {}
|
bullets = {}
|
||||||
|
bulletTimerLimit = 0.5
|
||||||
|
bulletTimer = bulletTimerLimit
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
|
|
@ -43,16 +45,18 @@ function love.update(dt)
|
||||||
bullet.y = (bullet.y + math.sin(bullet.angle) * bulletSpeed * dt) % arenaHeight
|
bullet.y = (bullet.y + math.sin(bullet.angle) * bulletSpeed * dt) % arenaHeight
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function love.keypressed(key)
|
bulletTimer = bulletTimer + dt
|
||||||
if key == 's' then
|
if love.keyboard.isDown('s') then
|
||||||
table.insert(bullets, {
|
if bulletTimer >= bulletTimerLimit then
|
||||||
x = shipX + math.cos(shipAngle) * shipRadius,
|
bulletTimer = 0
|
||||||
y = shipY + math.sin(shipAngle) * shipRadius,
|
table.insert(bullets, {
|
||||||
angle = shipAngle,
|
x = shipX + math.cos(shipAngle) * shipRadius,
|
||||||
timeLeft = 4,
|
y = shipY + math.sin(shipAngle) * shipRadius,
|
||||||
})
|
angle = shipAngle,
|
||||||
|
timeLeft = 4,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue