Last active
April 11, 2016 17:53
-
-
Save luizcarlos1405/79f8501472aa9add1228b854e038b02f to your computer and use it in GitHub Desktop.
LÖVE 03 - Videoaula em: https://youtu.be/CwXHz7GQoFQ
This file contains hidden or 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
function love.conf(t) | |
t.version = "0.10.1" | |
t.window.title = "Palco:dev()" | |
t.window.width = 1000 | |
t.window.height = 600 | |
t.window.borderless = true | |
t.window.fullscreen = false | |
end |
This file contains hidden or 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
Width = love.graphics.getWidth() | |
Height = love.graphics.getHeight() | |
function love.load() | |
-- Define cor de fundo | |
love.graphics.setBackgroundColor(5, 70, 110) | |
-- Define "objeto" Player | |
Player = {} | |
Player.img = love.graphics.newImage("player.png") | |
Player.w = Player.img:getWidth() | |
Player.h = Player.img:getHeight() | |
Player.x = Width / 2 | |
Player.y = Height / 2 | |
Player.ox = Player.w / 2 | |
Player.oy = Player.h / 2 | |
Player.sx = 1 | |
Player.sy = 1 | |
Player.r = 0 | |
Player.speed = 300 | |
Player.xvel = Player.speed * math.cos(math.pi / 4) | |
Player.yvel = Player.speed * math.sin(math.pi / 4) | |
end | |
function love.update(dt) | |
-- Recebe e computa controles | |
if love.keyboard.isDown("w") and love.keyboard.isDown("a") then | |
Player.y = Player.y - Player.yvel * dt | |
Player.x = Player.x - Player.xvel * dt | |
elseif love.keyboard.isDown("a") and love.keyboard.isDown("s") then | |
Player.y = Player.y + Player.yvel * dt | |
Player.x = Player.x - Player.xvel * dt | |
elseif love.keyboard.isDown("s") and love.keyboard.isDown("d") then | |
Player.y = Player.y + Player.yvel * dt | |
Player.x = Player.x + Player.xvel * dt | |
elseif love.keyboard.isDown("d") and love.keyboard.isDown("w") then | |
Player.y = Player.y - Player.yvel * dt | |
Player.x = Player.x + Player.xvel * dt | |
elseif love.keyboard.isDown("w") then | |
Player.y = Player.y - Player.speed * dt | |
elseif love.keyboard.isDown("a") then | |
Player.x = Player.x - Player.speed * dt | |
elseif love.keyboard.isDown("s") then | |
Player.y = Player.y + Player.speed * dt | |
elseif love.keyboard.isDown("d") then | |
Player.x = Player.x + Player.speed * dt | |
end | |
-- Impede que o Player saia da tela | |
if Player.y < Player.h / 2 then | |
Player.y = Player.h / 2 | |
end | |
if Player.x < Player.w / 2 then | |
Player.x = Player.w / 2 | |
end | |
if Player.y > Height - Player.h / 2 then | |
Player.y = Height - Player.h / 2 | |
end | |
if Player.x > Width - Player.w / 2 then | |
Player.x = Width - Player.w / 2 | |
end | |
end | |
function love.draw() | |
love.graphics.draw(Player.img, Player.x, Player.y, Player.r, Player.sx, Player.sy, Player.ox, Player.oy) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment