ovellas/main.lua

80 lines
1.9 KiB
Lua
Raw Normal View History

2022-05-28 00:05:01 +02:00
require "socket" -- para o tempo en milisengundos
require("entidades/pastor")
require("entidades/ovella")
2022-05-30 20:34:58 +02:00
require("entidades/cercado")
2022-05-28 00:05:01 +02:00
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")
-- fonte
local f = love.graphics.newFont(12)
love.graphics.setFont(f)
-- entidades
2022-05-30 20:34:58 +02:00
cercado = Cercado:new(width/2, height/2)
2022-05-28 00:05:01 +02:00
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
2022-05-30 20:34:58 +02:00
cercado:draw()
2022-05-28 00:05:01 +02:00
-- 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
2022-06-01 23:34:30 +02:00
player:update(dt, cercado)
2022-05-28 00:05:01 +02:00
-- update ovella object
for i = 1, #ovellas,1 do --itera sobre cada ovella na tabla
2022-05-30 20:34:58 +02:00
ovellas[i]:update(player, cercado)
2022-05-28 00:05:01 +02:00
end
end