LoginSignup
0
0

More than 5 years have passed since last update.

Love2D:ゲームエンジンその6

Posted at

元記事

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

はい出来ました。
スクリーンショット 2014-12-23 6.06.56.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0