2019-08-14 16:26:23 +02:00
|
|
|
local World = Object:extend()
|
|
|
|
|
2020-08-01 13:34:39 +02:00
|
|
|
local Map = require "game.modules.drawing.parallaxBackground"
|
2019-08-14 16:26:23 +02:00
|
|
|
|
2020-08-01 13:34:39 +02:00
|
|
|
local HEIGHT = 5
|
|
|
|
local BORDER_BOTTOM = 2
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
-- INIT FUNCTIONS
|
|
|
|
-- Initialize the battle world
|
|
|
|
|
|
|
|
function World:new(scene, battlefile)
|
|
|
|
self.scene = scene
|
|
|
|
self.assets = scene.assets
|
|
|
|
|
|
|
|
self.obj = require "scenes.battlesystem.actors"
|
|
|
|
|
|
|
|
self.actors = {}
|
|
|
|
self.globalID = 0
|
|
|
|
|
2020-08-01 13:34:39 +02:00
|
|
|
self.map = Map(scene, HEIGHT, BORDER_BOTTOM, "city")
|
2021-08-07 11:57:01 +02:00
|
|
|
self.index = {}
|
2019-08-16 18:33:47 +02:00
|
|
|
|
|
|
|
self.isBattleActive = false
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function World:registerActor(actor)
|
|
|
|
self.globalID = self.globalID + 1
|
|
|
|
|
|
|
|
table.insert(self.actors, actor)
|
|
|
|
actor.id = self.globalID
|
|
|
|
end
|
|
|
|
|
2019-08-15 15:06:13 +02:00
|
|
|
function World:destroyActor(actorToDestroy)
|
|
|
|
for i, actor in ipairs(self.actors) do
|
|
|
|
if actor == actorToDestroy then
|
|
|
|
table.remove(self.actors, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
-- INFO FUNCTIONS
|
|
|
|
-- Get info from the world
|
|
|
|
|
2019-08-25 15:54:26 +02:00
|
|
|
function World:caseIsEmpty(x, y, notThisActor)
|
|
|
|
local actor = self:getActorInCase(x, y, notThisActor)
|
2019-08-14 16:26:23 +02:00
|
|
|
|
2019-08-25 15:54:26 +02:00
|
|
|
return (actor == nil)
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
|
2019-08-25 15:54:26 +02:00
|
|
|
function World:getActorInCase(x, y, notThisActor)
|
2019-08-14 16:26:23 +02:00
|
|
|
for i, actor in ipairs(self.actors) do
|
2019-08-25 15:54:26 +02:00
|
|
|
if (actor.x == x) and (actor.y == y) and (actor ~= notThisActor) then
|
2019-08-14 16:26:23 +02:00
|
|
|
core.debug:print("cbs/world", "one actor found in case <" .. x .. ";" .. y .. ">")
|
|
|
|
return actor
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2021-08-07 11:57:01 +02:00
|
|
|
function World:getActorByName(name)
|
|
|
|
return self.index[name]
|
|
|
|
end
|
|
|
|
|
2019-08-14 16:26:23 +02:00
|
|
|
-- UPDATE FUNCTION
|
|
|
|
-- Update all actors
|
|
|
|
|
|
|
|
function World:update(dt)
|
|
|
|
for i, actor in ipairs(self.actors) do
|
|
|
|
actor:update(dt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-25 10:38:06 +02:00
|
|
|
function World:sendSignalToCurrentBattler(signal, subSignal)
|
2020-05-01 14:50:21 +02:00
|
|
|
self.scene.turns:sendSignalToCurrentBattler(signal, subSignal)
|
2019-08-14 16:26:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- DRAW FUNCTION
|
|
|
|
-- Draw the world
|
|
|
|
|
|
|
|
function World:draw()
|
2020-07-19 17:02:00 +02:00
|
|
|
self.map:draw()
|
2019-08-14 16:26:23 +02:00
|
|
|
self:drawShadows()
|
|
|
|
self:drawActors()
|
|
|
|
end
|
|
|
|
|
|
|
|
function World:drawActors()
|
2021-08-07 17:21:26 +02:00
|
|
|
table.sort(self.actors, function(a, b) return (a.y < b.y) end)
|
2019-08-14 16:26:23 +02:00
|
|
|
for i, actor in ipairs(self.actors) do
|
|
|
|
actor:draw()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function World:drawShadows()
|
|
|
|
for i, actor in ipairs(self.actors) do
|
|
|
|
actor:drawShadow()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return World
|