moving bullets
This commit is contained in:
parent
b692e75773
commit
0dbf971a79
1 changed files with 16 additions and 9 deletions
25
main.lua
25
main.lua
|
|
@ -13,15 +13,6 @@ function love.load()
|
||||||
bullets = {}
|
bullets = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key)
|
|
||||||
if key == 's' then
|
|
||||||
table.insert(bullets, {
|
|
||||||
x = shipX + math.cos(shipAngle) * shipRadius,
|
|
||||||
y = shipY + math.sin(shipAngle) * shipRadius,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
local turnSpeed = 10
|
local turnSpeed = 10
|
||||||
if love.keyboard.isDown('right') then
|
if love.keyboard.isDown('right') then
|
||||||
|
|
@ -40,6 +31,22 @@ function love.update(dt)
|
||||||
|
|
||||||
shipX = (shipX + shipSpeedX * dt) % arenaWidth
|
shipX = (shipX + shipSpeedX * dt) % arenaWidth
|
||||||
shipY = (shipY + shipSpeedY * dt) % arenaHeight
|
shipY = (shipY + shipSpeedY * dt) % arenaHeight
|
||||||
|
|
||||||
|
for bulletIndex, bullet in ipairs(bullets) do
|
||||||
|
local bulletSpeed = 500
|
||||||
|
bullet.x = (bullet.x + math.cos(bullet.angle) * bulletSpeed * dt) % arenaWidth
|
||||||
|
bullet.y = (bullet.y + math.sin(bullet.angle) * bulletSpeed * dt) % arenaHeight
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.keypressed(key)
|
||||||
|
if key == 's' then
|
||||||
|
table.insert(bullets, {
|
||||||
|
x = shipX + math.cos(shipAngle) * shipRadius,
|
||||||
|
y = shipY + math.sin(shipAngle) * shipRadius,
|
||||||
|
angle = shipAngle,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue