88 lines
2.1 KiB
Lua
88 lines
2.1 KiB
Lua
require "socket" -- para o tempo en milisengundos
|
|
require("entidades/pastor")
|
|
require("entidades/ovella")
|
|
require("entidades/cercado")
|
|
inspect = require 'lib.inspect'
|
|
|
|
-- configuracion
|
|
OVELLAS = 6
|
|
DISTANCIA = 70
|
|
|
|
function love.conf(t)
|
|
t.console = true --activa salida por consola para debug con print()
|
|
end
|
|
|
|
-- globales
|
|
ovellas = {}
|
|
world = love.physics.newWorld(0,0,true)
|
|
|
|
-- inicia os recursos, execútase ó cargar o xogo
|
|
function love.load()
|
|
local width, height, flags = love.window.getMode();
|
|
local BORDER = 100; -- pixeles de borde para non xenerar ovellas nos marxes
|
|
|
|
-- imaxes
|
|
background = love.graphics.newImage("img/fondo.png")
|
|
|
|
-- fonte
|
|
local f = love.graphics.newFont(12)
|
|
love.graphics.setFont(f)
|
|
|
|
-- entidades
|
|
cercado = Cercado:new(width/2, height/2)
|
|
player = Pastor:new(width/2, height/2)
|
|
for i=1,OVELLAS do
|
|
-- print(i)
|
|
math.randomseed(os.time()+i)
|
|
local x = math.random(1 + BORDER, width - BORDER);
|
|
local y = math.random(1 + BORDER, height - BORDER);
|
|
-- print(x, y)
|
|
ovella = Ovella:new(i, x, y)
|
|
table.insert(
|
|
ovellas,
|
|
ovella
|
|
)
|
|
end
|
|
end
|
|
|
|
-- dibuxa
|
|
function love.draw()
|
|
-- fondo
|
|
for i = 0, love.graphics.getWidth() / background:getWidth() do
|
|
for j = 0, love.graphics.getHeight() / background:getHeight() do
|
|
love.graphics.draw(background, i * background:getWidth(), j * background:getHeight())
|
|
end
|
|
end
|
|
|
|
-- cercado
|
|
cercado:draw()
|
|
|
|
-- pastor
|
|
player:draw()
|
|
|
|
-- ovellas
|
|
for i = 1, #ovellas,1 do --itera sobre cada ovella na tabla
|
|
-- print(inspect(ovellas[i]))
|
|
ovellas[i]:draw()
|
|
end
|
|
|
|
love.graphics.print("Ovellas recollidas: 0", 10, 10)
|
|
end
|
|
|
|
function love.update(dt)
|
|
-- update world
|
|
world:update(dt)
|
|
|
|
--- update player object
|
|
player:update(dt, cercado)
|
|
-- update ovella object
|
|
for i = 1, #ovellas,1 do --itera sobre cada ovella na tabla
|
|
ovellas[i]:update(player, cercado)
|
|
end
|
|
|
|
-- QUIT!
|
|
if love.keyboard.isDown("q") then
|
|
love.event.quit()
|
|
end
|
|
end
|