chore: adapt the world to the new turnSystem
This commit is contained in:
parent
d8dafdfe48
commit
8512ab3c26
2 changed files with 7 additions and 121 deletions
|
@ -84,34 +84,18 @@ function maputils.maskToMap(ox, oy, shape, size, direction)
|
|||
return map
|
||||
end
|
||||
|
||||
function maputils.gridToPixel(x, y, center)
|
||||
local pixelx, pixely
|
||||
local center = center or false
|
||||
local x, y = x, y
|
||||
|
||||
if (center) then
|
||||
x = x + .5
|
||||
y = y + .5
|
||||
end
|
||||
|
||||
pixelx = maputils.CONST.STARTX + ((x-1) * 31) + ((y-1) * 10)
|
||||
pixely = maputils.CONST.STARTY + ((y-1) * 20)
|
||||
|
||||
return math.floor(pixelx), math.floor(pixely)
|
||||
end
|
||||
|
||||
function maputils.sortBattlers(a, b)
|
||||
local astats = a.actor:getStats()
|
||||
local bstats = b.actor:getStats()
|
||||
local astats = a.fighter:getStats()
|
||||
local bstats = b.fighter:getStats()
|
||||
local aspeed = astats.speed / 1.5 * a.number
|
||||
local bspeed = bstats.speed / 1.5 * b.number
|
||||
|
||||
|
||||
if (aspeed == bspeed) then
|
||||
if (a.actor.isHero == b.actor.isHero) then
|
||||
return (a.actor.id > b.actor.id)
|
||||
if (a.fighter.isHero == b.fighter.isHero) then
|
||||
return (a.fighter.id > b.fighter.id)
|
||||
else
|
||||
return a.actor.isHero
|
||||
return a.fighter.isHero
|
||||
end
|
||||
else
|
||||
return (aspeed > bspeed)
|
||||
|
|
|
@ -32,29 +32,10 @@ function World:new(scene, battlefile)
|
|||
self.ennNumber = 0
|
||||
|
||||
self.map = Map(self, "city")
|
||||
self.cursor = Cursor(self)
|
||||
|
||||
self:resetActiveGrid()
|
||||
self:resetEffectGrid()
|
||||
|
||||
self:initHeroes()
|
||||
self:initEnnemies()
|
||||
|
||||
self.isBattleActive = false
|
||||
end
|
||||
|
||||
function World:initHeroes(battlefile)
|
||||
for i, hero in ipairs(game.characters.team) do
|
||||
self:addHero(POSITIONS[i].x, POSITIONS[i].y, hero, i)
|
||||
end
|
||||
end
|
||||
|
||||
function World:initEnnemies(battlefile)
|
||||
self:addEnnemy(10, 3, "motobug")
|
||||
self:addEnnemy(10, 5, "motobug")
|
||||
self:addEnnemy(9, 4, "motobug")
|
||||
end
|
||||
|
||||
function World:registerActor(actor)
|
||||
self.globalID = self.globalID + 1
|
||||
|
||||
|
@ -90,78 +71,6 @@ function World:getActorInCase(x, y, notThisActor)
|
|||
return nil
|
||||
end
|
||||
|
||||
-- BATTLER FUNCTIONS
|
||||
-- Handle the actual battle participants
|
||||
|
||||
function World:addHero(x, y, id)
|
||||
self.heroNumber = self.heroNumber + 1
|
||||
local hero = self.obj.Hero(self, x, y, id, self.heroNumber)
|
||||
|
||||
table.insert(self.battlers, hero)
|
||||
end
|
||||
|
||||
function World:addEnnemy(x, y, id)
|
||||
self.ennNumber = self.ennNumber + 1
|
||||
local enn = self.obj.Ennemy(self, x, y, id, self.ennNumber)
|
||||
|
||||
table.insert(self.battlers, enn)
|
||||
end
|
||||
|
||||
function World:destroyBattler(actorToDestroy)
|
||||
-- remove the actor from the battler liste
|
||||
for i, actor in ipairs(self.battlers) do
|
||||
if actor == actorToDestroy then
|
||||
table.remove(self.battlers, i)
|
||||
end
|
||||
end
|
||||
|
||||
-- Also remove all actions related to the actor
|
||||
for i, action in ipairs(self.actionlist) do
|
||||
if action.actor == actorToDestroy then
|
||||
table.remove(self.actionlist, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function World:generateActionList()
|
||||
self.actionlist = {}
|
||||
|
||||
for i,v in ipairs(self.battlers) do
|
||||
for i=1, v.actionPerTurn do
|
||||
local action = {}
|
||||
action.actor = v
|
||||
action.number = i
|
||||
table.insert(self.actionlist, action)
|
||||
end
|
||||
end
|
||||
|
||||
return self.actionlist
|
||||
end
|
||||
|
||||
function World:countHeroes()
|
||||
local count = 0
|
||||
|
||||
for i, battler in ipairs(self.battlers) do
|
||||
if (battler.isHero) then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
function World:countEnnemies()
|
||||
local count = 0
|
||||
|
||||
for i, battler in ipairs(self.battlers) do
|
||||
if (battler.isEnnemy) then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
-- UPDATE FUNCTION
|
||||
-- Update all actors
|
||||
|
||||
|
@ -170,16 +79,9 @@ function World:update(dt)
|
|||
actor:update(dt)
|
||||
end
|
||||
|
||||
self.cursor:update(dt)
|
||||
self.map:update(dt)
|
||||
end
|
||||
|
||||
function World:finishBattle()
|
||||
self.isBattleActive = false
|
||||
self.actionlist = {}
|
||||
self.scene:finishBattle()
|
||||
end
|
||||
|
||||
function World:sendSignalToCurrentBattler(signal, subSignal)
|
||||
self.scene.turns:sendSignalToCurrentBattler(signal, subSignal)
|
||||
end
|
||||
|
@ -212,10 +114,10 @@ end
|
|||
|
||||
function World:draw()
|
||||
self.map:draw(self.activeGrid, self.effectGrid)
|
||||
self.cursor:drawBottom()
|
||||
--self.cursor:drawBottom()
|
||||
self:drawShadows()
|
||||
self:drawActors()
|
||||
self.cursor:drawTop()
|
||||
--self.cursor:drawTop()
|
||||
end
|
||||
|
||||
function World:drawActors()
|
||||
|
|
Loading…
Reference in a new issue