improvement(cbs): rework the grid system

This commit is contained in:
Kazhnuz 2019-08-22 22:40:31 +02:00
parent 9c91c0a946
commit 3ab6a0e6e2
4 changed files with 76 additions and 4 deletions

View file

@ -152,6 +152,7 @@ function Hero:updateMoving(dt)
self.y = self.dy self.y = self.dy
self:changeAnimation("idle") self:changeAnimation("idle")
self.currentAction = "selectAttack" self.currentAction = "selectAttack"
self.world:resetActiveGrid()
self.scene.menu:set( self ) self.scene.menu:set( self )
end end
end end
@ -215,6 +216,7 @@ end
function Hero:receiveBackSignal() function Hero:receiveBackSignal()
self.currentAction = "selectDirection" self.currentAction = "selectDirection"
self.world.cursor:set(self.x, self.y) self.world.cursor:set(self.x, self.y)
self:changeAnimation("walk") self:changeAnimation("walk")
end end

View file

@ -26,6 +26,8 @@ function Cursor:set(x, y)
self.ty = self.y self.ty = self.y
self.isActive = true self.isActive = true
self.world:setActiveGridFromGrid(self.grid)
end end
function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity) function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity)
@ -44,6 +46,8 @@ function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity)
end end
end end
end end
self.world:setActiveGridFromGrid(self.grid)
end end
function Cursor:testPoint(x, y, whitelistedActor) function Cursor:testPoint(x, y, whitelistedActor)
@ -122,7 +126,7 @@ function Cursor:update(dt)
end end
function Cursor:addTween() function Cursor:addTween()
self.tweens:newTween(0, 0.2, {tx = self.x, ty = self.y}, 'inCubic') self.tweens:newTween(0, 0.2, {tx = self.x, ty = self.y}, 'linear')
end end
function Cursor:drawBottom() function Cursor:drawBottom()

View file

@ -135,6 +135,22 @@ function CharMenuWidget:new(scene, menu_name, label1, label2, character)
local font = scene.assets.fonts["small"] local font = scene.assets.fonts["small"]
CharMenuWidget.super.new(self, menu, font, core.lang:translate("battle", label1)) CharMenuWidget.super.new(self, menu, font, core.lang:translate("battle", label1))
self.label2 = label2 or "" self.label2 = label2 or ""
self.isSelected = false
end
function CharMenuWidget:update(dt)
CharMenuWidget.super.update(self, dt)
end
function CharMenuWidget:selectAction()
self.isSelected = true
if self.actionType == "attack" then
self.scene.world:resetActiveGrid()
self.scene.world:setEffectGrid(self.character.x + self.character.direction, self.character.y, "point", 1, 1)
else
self.scene.world:resetActiveGrid()
self.scene.world:resetEffectGrid()
end
end end
function CharMenuWidget:drawCanvas() function CharMenuWidget:drawCanvas()
@ -204,6 +220,33 @@ function SkillWidget:new(scene, menu_name, label1, label2, character)
end end
end end
function SkillWidget:selectAction()
if self.skilldata ~= nil then
if self.skilldata.target == nil then
local x = self.character.x + self.skilldata.effectArea[1]
local y = self.character.y + self.skilldata.effectArea[2]
local shape = self.skilldata.effectArea[3]
local size = self.skilldata.effectArea[4]
local direction = self.character.direction
self.scene.world:resetActiveGrid()
self.scene.world:setEffectGrid(x, y, shape, size, direction)
else
local x = self.character.x + self.skilldata.target[1]
local y = self.character.y + self.skilldata.target[2]
local shape = self.skilldata.target[3]
local size = self.skilldata.target[4]
local direction = self.character.direction
self.scene.world:setActiveGrid(x, y, shape, size, direction)
self.scene.world:resetEffectGrid()
end
else
self.scene.world:resetActiveGrid()
self.scene.world:resetEffectGrid()
end
end
function SkillWidget:drawCanvas() function SkillWidget:drawCanvas()
local h local h
local asset = love.graphics.newImage("assets/gui/attacklist.png") local asset = love.graphics.newImage("assets/gui/attacklist.png")

View file

@ -46,6 +46,9 @@ function World:new(scene, battlefile)
self.tweens = TweenManager(self) self.tweens = TweenManager(self)
self:resetActiveGrid()
self:resetEffectGrid()
self:initHeroes() self:initHeroes()
self:initEnnemies() self:initEnnemies()
self:initHUD() self:initHUD()
@ -274,14 +277,34 @@ function World:sendSignalToCurrentBattler()
self.actionlist[self.turns.current].actor:validateAction() self.actionlist[self.turns.current].actor:validateAction()
end end
-- ACTIVEGRID FUNCTIONS
-- Help to handle the activeGrid system
function World:resetActiveGrid()
self.activeGrid = maputils.newFullMap()
end
function World:setActiveGrid(ox, oy, shape, size, direction)
self.activeGrid = maputils.maskToMap(ox, oy, shape, size, direction)
end
function World:setActiveGridFromGrid(grid)
self.activeGrid = grid
end
function World:resetEffectGrid()
self.effectGrid = maputils.newEmptyMap()
end
function World:setEffectGrid(ox, oy, shape, size, direction)
self.effectGrid = maputils.maskToMap(ox, oy, shape, size, direction)
end
-- DRAW FUNCTION -- DRAW FUNCTION
-- Draw the world -- Draw the world
function World:draw() function World:draw()
local activeGrid = self.cursor:getGrid() self.map:draw(self.activeGrid, self.effectGrid)
self.map:draw(activeGrid)
self.cursor:drawBottom() self.cursor:drawBottom()
self:drawShadows() self:drawShadows()
self:drawActors() self:drawActors()