Created
April 1, 2015 18:59
-
-
Save dabbertorres/004f9bf873fd5e19c502 to your computer and use it in GitHub Desktop.
Love2D Interactive Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local text = "Hello World" | |
local speed = 100 | |
local pos = {x = 400, y = 300} | |
local move = {up = false, down = false, left = false, right = false} | |
function love.load() | |
love.graphics.setNewFont(12) | |
end | |
function love.draw() | |
love.graphics.print(text, pos.x, pos.y) | |
love.window.setTitle("Fancy Crap") | |
end | |
function love.keypressed(key) | |
if key == "up" then | |
move.up = true | |
elseif key == "down" then | |
move.down = true | |
elseif key == "left" then | |
move.left = true | |
elseif key == "right" then | |
move.right = true | |
elseif key == "escape" then | |
love.event.quit() | |
else | |
--do nothing | |
end | |
end | |
function love.keyreleased(key) | |
if key == "up" then | |
move.up = false | |
elseif key == "down" then | |
move.down = false | |
elseif key == "left" then | |
move.left = false | |
elseif key == "right" then | |
move.right = false | |
else | |
--do nothing | |
end | |
end | |
function love.update(dt) | |
if move.up then | |
pos.y = pos.y - speed * dt | |
end | |
if move.down then | |
pos.y = pos.y + speed * dt | |
end | |
if move.left then | |
pos.x = pos.x - speed * dt | |
end | |
if move.right then | |
pos.x = pos.x + speed * dt | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment