ovellas/main.lua

88 lines
2.1 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 = {}
2022-06-27 23:48:45 +02:00
world = love.physics.newWorld(0,0,true)
2022-05-28 00:05:01 +02:00
-- 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
2022-06-27 23:48:45 +02:00
-- imaxes
2022-05-28 00:05:01 +02:00
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(cercado)
2022-05-28 00:05:01 +02:00
end
2022-05-28 00:05:01 +02:00
love.graphics.print("Ovellas recollidas: 0", 10, 10)
end
function love.update(dt)
2022-06-27 23:48:45 +02:00
-- update world
world:update(dt)
2022-05-28 00:05:01 +02:00
--- update player object
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
2022-06-27 23:48:45 +02:00
-- QUIT!
if love.keyboard.isDown("q") then
love.event.quit()
end
2022-05-28 00:05:01 +02:00
end