Total beginner lost in its first "separated" program [Solved]
Posted: Tue Nov 15, 2016 7:00 pm
Hi, I'm trying to make my first simple game separating the elements (player, enemies... ), but I see I'm lost in the first step. I'm trying to only draw a rectangle as a player on a black window, and these are the three files I'm working with.
conf.lua
main.lua
jugador/Jugador.lua
And this is the result I get when I start the program:
Sorry to be so clumsy.
conf.lua
Code: Select all
function love.conf(t)
t.window.title = "Juego de prueba"
t.window.width = 800
t.window.height = 600
--t.console = true
t.modules.touch = false
end
Code: Select all
require("jugador/Jugador")
function love.load()
Jugador:new()
end
function love.update(dt)
Jugador:update(dt)
end
function love.draw()
Jugador:draw()
end
--function love.quit()
-- body...
--end
Code: Select all
local Jugador = {}
function Jugador:new()
Jugador.x = 0
Jugador.y = 550
Jugador.speed = 10
end
function Jugador:update(dt)
if love.keyboard.isDown("right") then
Jugador.x = Jugador.x + Jugador.speed
end
if love.keyboard.isDown("left") then
Jugador.x = Jugador.x - Jugador.speed
end
if love.keyboard.isDown("down") then
Jugador.y = Jugador.y + Jugador.speed
end
if love.keyboard.isDown("up") then
Jugador.y = Jugador.y - Jugador.speed
end
end
function Jugador:draw()
love.graphics.rectangle("fill", Jugador.x, Jugador.y, 80, 20)
end
Code: Select all
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
Error: main.lua:6: attempt to index global 'Jugador' (a nil value)
stack traceback:
main.lua:6: in function 'load'
[string "boot.lua"]:440: in function <[string "boot.lua"]:436>
[C]: in function 'xpcall'