Love2D:ゲームエンジンその6
元記事
http://yal.cc/love2d-shooting-things/
シューティングの原型
main.lua
player = {
x = 100,
y = 100,
speed = 200,
heat = 0,
heatp = 0.1
}
bullets = { }
function love.update(dt)
if love.keyboard.isDown('a') then player.x = player.x - dt * player.speed end
if love.keyboard.isDown('d') then player.x = player.x + dt * player.speed end
if love.keyboard.isDown('w') then player.y = player.y - dt * player.speed end
if love.keyboard.isDown('s') then player.y = player.y + dt * player.speed end
player.heat = math.max(0, player.heat - dt)
if love.mouse.isDown('l') and player.heat <= 0 then
local direction = math.atan2(love.mouse.getY() - player.y, love.mouse.getX() - player.x)
table.insert(bullets, {
x = player.x,
y = player.y,
dir = direction,
speed = 400
})
player.heat = player.heatp
end
-- update bullets:
local i, o
for i, o in ipairs(bullets) do
o.x = o.x + math.cos(o.dir) * o.speed * dt
o.y = o.y + math.sin(o.dir) * o.speed * dt
if (o.x < -10) or (o.x > love.graphics.getWidth() + 10)
or (o.y < -10) or (o.y > love.graphics.getHeight() + 10) then
table.remove(bullets, i)
end
end
end
function love.draw()
-- draw player:
love.graphics.setColor(0, 255, 0, 255)
love.graphics.circle('fill', player.x, player.y, 15, 8)
-- draw bullets:
love.graphics.setColor(0, 0, 255, 255)
local i, o
for i, o in ipairs(bullets) do
love.graphics.circle('fill', o.x, o.y, 10, 8)
end
end
function love.load()
love.graphics.setBackgroundColor(0, 0, 0)
end
Zip
作業ディレクトリで以下コマンド発行
zip -r ../${PWD##*/}.love *
Run
Author And Source
この問題について(Love2D:ゲームエンジンその6), 我々は、より多くの情報をここで見つけました https://qiita.com/ggggnonaka/items/a2e5793ca86e9c693e47著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .