LoginSignup
0
0

More than 5 years have passed since last update.

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

Posted at

元記事

その4にy方向を追加します。

main.lua
-- tutorial #1
-- the 3 golden love function, lua tables, keyboard input, draw circle

function love.load()
 hero = {} -- new table for the hero
 hero.x = 300    -- x,y coordinates of the hero
 hero.y = 450
 hero.speed = 100
end

function love.update(dt)
 if love.keyboard.isDown("left") then
   hero.x = hero.x - hero.speed*dt
 elseif love.keyboard.isDown("right") then
   hero.x = hero.x + hero.speed*dt
 elseif love.keyboard.isDown("up") then
   hero.y = hero.y - hero.speed*dt
 elseif love.keyboard.isDown("down") then
   hero.y = hero.y + hero.speed*dt   
 end
end

function love.draw()
 -- let's draw some ground
 love.graphics.setColor(0,255,0,255)
 love.graphics.rectangle("fill", 0,465,800,150)

 -- let's draw our hero
 love.graphics.setColor(255,255,0,255)
 love.graphics.rectangle("fill", hero.x,hero.y, 30,15)
end

Zip

作業ディレクトリで以下コマンド発行
zip -r ../${PWD##*/}.love *

Run

はい出来ました。
スクリーンショット 2014-12-22 19.52.44.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