require "socket" -- para o tempo en milisengundos require("entidades/pastor") require("entidades/ovella") 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 = {} -- 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") cercado = love.graphics.newImage("img/cercado.png") -- fonte local f = love.graphics.newFont(12) love.graphics.setFont(f) -- entidades player = Pastor:new(width/2, height/2) -- ovellas con posicios aleatorias 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 cercadoX = (love.graphics.getWidth() - cercado:getWidth()) / 2 cercadoY = (love.graphics.getHeight() - cercado:getHeight()) / 2 love.graphics.draw(cercado, cercadoX, cercadoY) -- 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 player object player:update(dt) -- update ovella object for i = 1, #ovellas,1 do --itera sobre cada ovella na tabla ovellas[i]:update(player) end end