Until now, following tutorials of Sheepollution and Simple Game Tutorials, I could make a Pong clone and an Eyes game.
Now, I'm trying to learn by myself how to make a game with several lua files. I'm using a white square and I managed to making appear on the screen.
The game has two lua files: main.lua and square.lua (with the square I want to make move)
Unfortunately, I can't make the square move despite writing his actions on its code. I tried to fix it, but now... the square doesn't appear! What am I doing wrong?
Here's the main.lua code:
Code: Select all
require "square"
function love.load(arg)
end
function love.update( dt )
end
function love.draw()
end
Code: Select all
local square = {x = 100, y = 100, width = 50, height = 50, speed = 20}
function square.update( dt )
if love.keyboard.isDown("right") then
square.x = x + speed * dt
end
if love.keyboard.isDown("left") then
square.x = x - speed * dt
end
if love.keyboard.isDown("up") then
square.y = y - speed * dt
end
if love.keyboard.isDown("down") then
square.y = y + speed * dt
end
end
function square.draw()
love.graphics.rectangle( 'fill', x, y, width, height )
end