Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@ggggnonaka

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

More than 5 years have passed since last update.

元記事

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
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ggggnonaka
業務系SEなのに、ゲームプログラム、Webを教えてます。そろそろ本業だけにしとくかなぁ。僕はもう疲れたよ。教育なんてさ...

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?