chore: drop the grid/cursor system

This commit is contained in:
Kazhnuz 2020-07-19 17:02:00 +02:00
parent 5e1ee752ac
commit a41aabbd7d
4 changed files with 1 additions and 375 deletions

View file

@ -1,214 +0,0 @@
local Cursor = Object:extend()
local maputils = require "scenes.battlesystem.utils"
local TweenManager = require "game.modules.tweenmanager"
function Cursor:new(world)
self.world = world
self.scene = world.scene
self.assets = world.assets
self.tweens = TweenManager(self)
self.x = 1
self.y = 1
self.isActive = false
self.tx = 1
self.ty = 1
self.signal = ""
self.grid = maputils.newEmptyMap()
end
function Cursor:set(x, y, signal, subSignal)
self.x = math.max(math.min(x, 12), 1)
self.y = math.max(math.min(y, 07), 1)
self.initialx = self.x
self.initialy = self.y
self:placeInGrid()
self.tx = self.x
self.ty = self.y
self.isActive = true
self.signal = signal or ""
self.subSignal = subSignal or ""
self.world:setActiveGridFromGrid(self.grid)
end
function Cursor:placeInGrid()
while (self.grid[self.y][self.x] == 0) do
core.debug:print("cursor", "testing position " .. self.x .. " " .. self.y)
-- On teste d'abord les position > initialx
if self.x >= self.initialx then
if self.x >= 12 then
-- cependant, si on est au maximum, on se place juste avant
self.x = self.initialx - 1
else
self.x = self.x + 1
end
else
if self.x <= 1 then
-- cependant, si on est au minimum, on doit tester une autre ligne
self.x = self.initialx
if self.y >= self.initialy then
-- on test d'abord les positions en dessous de la position initiales
if self.y >= 7 then
self.y = self.initialy - 1
else
self.y = self.y + 1
end
else
if self.y <= 1 then
core.debug:error("cursor", "map was empty")
else
self.y = self.y - 1
end
end
else
-- sinon, on test les positions avant
self.x = self.x - 1
end
end
end
end
function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity)
self.grid = maputils.newEmptyMap()
for y, line in ipairs(self.grid) do
for x, case in ipairs(line) do
if not maputils.isInMask(x, y, ox, oy, shape, size, direction) then
self.grid[y][x] = 0
else
if (self:testPoint(x, y, whitelistedEntity)) then
self.grid[y][x] = 1
else
self.grid[y][x] = 0
end
end
end
end
self.world:setActiveGridFromGrid(self.grid)
end
function Cursor:setGridIgnoreActor(ox, oy, shape, size, direction)
self.grid = maputils.newEmptyMap()
for y, line in ipairs(self.grid) do
for x, case in ipairs(line) do
if maputils.isInMask(x, y, ox, oy, shape, size, direction) then
self.grid[y][x] = 1
end
end
end
self.world:setActiveGridFromGrid(self.grid)
end
function Cursor:testPoint(x, y, whitelistedActor)
if ((self.world:getActorInCase(x, y) == nil) or
(self.world:getActorInCase(x, y) == whitelistedActor) and (whitelistedActor ~= nil)) and
(self.world.map:getTerrain(x, y) ~= 3) then
return true
else
return false
end
end
function Cursor:gridIsActive(x, y)
if self.grid[y] ~= nil then
return (self.grid[y][x] == 1)
else
return false
end
end
function Cursor:getGrid()
if (self.isActive) then
return self.grid
else
return maputils.newFullMap()
end
end
function Cursor:resetGrid()
self.grid = EmptyGrid
end
function Cursor:unset()
self.isActive = false
end
function Cursor:update(dt)
if (self.isActive) then
local keys = self.scene:getKeys(1)
if (keys["up"].isDown and self.y == self.ty) then
dy = math.max(self.y - 1, 1)
if (self.grid[dy][self.x] == 1) then
self.y = dy
self:addTween()
end
end
if (keys["down"].isDown and self.y == self.ty) then
dy = math.min(self.y + 1, 7)
if (self.grid[dy][self.x] == 1) then
self.y = dy
self:addTween()
end
end
if (keys["left"].isDown and self.x == self.tx) then
dx = math.max(self.x - 1, 1)
if (self.grid[self.y][dx] == 1) then
self.x = dx
self:addTween()
end
end
if (keys["right"].isDown and self.x == self.tx) then
dx = math.min(self.x + 1, 12)
if (self.grid[self.y][dx] == 1) then
self.x = dx
self:addTween()
end
end
if (keys["A"].isPressed and self.x == self.tx and self.y == self.ty) then
self.world:sendSignalToCurrentBattler(self.signal, self.subSignal)
end
self.tweens:update(dt)
end
end
function Cursor:addTween()
self.tweens:newTween(0, 0.2, {tx = self.x, ty = self.y}, 'linear')
end
function Cursor:drawBottom()
if (self.isActive) then
local x, y, frame
x, y = maputils.gridToPixel(self.tx, self.ty, true)
self.assets.sprites["cursorground"]:drawAnimation(x, y, 0, 1, 1, 14, 6)
end
end
function Cursor:drawTop()
if (self.isActive) then
local x, y
x, y = maputils.gridToPixel(self.tx, self.ty, true)
self.assets.images["cursorpeak"]:draw(x, y - 24, 0, 1, 1, 7, 26)
end
end
return Cursor

View file

@ -1,11 +1,6 @@
local Map = Object:extend() local Map = Object:extend()
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
local TweenManager = require "game.modules.tweenmanager"
local DURATION = 0.66
local OPACITY_MIN = 0
local OPACITY_MAX = 0.75
local HEIGHT = 5 local HEIGHT = 5
local BOTTOM_BORDER = 1 local BOTTOM_BORDER = 1
@ -17,11 +12,6 @@ function Map:new(world, type, terrain)
self.datas = {} self.datas = {}
self.datas.type = type or "forest" self.datas.type = type or "forest"
self.datas.terrains = terrain or maputils.newEmptyMap()
self.tweens = TweenManager(self)
self.effectOpacity = OPACITY_MIN
self:increaseOpacity()
local zones = require "datas.gamedata.maps.shoot.zones" local zones = require "datas.gamedata.maps.shoot.zones"
local datas = zones[self.datas.type] local datas = zones[self.datas.type]
@ -77,31 +67,6 @@ function Map:gridToPixel(x, y, center)
return math.floor(pixelx), math.floor(pixely) return math.floor(pixelx), math.floor(pixely)
end end
function Map:update(dt)
self.tweens:update(dt)
end
-- OPACITY FUNCTIONS
-- Simple functions to work on opacity
function Map:decreaseOpacity()
self.tweens:newTween(0, DURATION/2, {effectOpacity = OPACITY_MIN}, "inExpo")
self.tweens:newTimer(DURATION/2, "increaseOpacity")
end
function Map:increaseOpacity()
self.tweens:newTween(0, DURATION/2, {effectOpacity = OPACITY_MAX}, "inExpo")
self.tweens:newTimer(DURATION/2, "decreaseOpacity")
end
function Map:timerResponse(timer)
if timer == "increaseOpacity" then
self:increaseOpacity()
elseif timer == "decreaseOpacity" then
self:decreaseOpacity()
end
end
-- DRAW FUNCTIONS -- DRAW FUNCTIONS
-- Draw the battle map -- Draw the battle map
@ -166,17 +131,4 @@ function Map:drawBorders()
end end
end end
function Map:drawEffectGrid(effectGrid)
for i=1,7 do
for j=1,17 do
if (effectGrid[i][j] == 1) then
local x, y = maputils.gridToPixel(j, i)
love.graphics.setColor(1, 1, 1, self.effectOpacity)
self.assets.images["emptytile"]:draw(x, y)
love.graphics.setColor(1, 1, 1, 1)
end
end
end
end
return Map return Map

View file

@ -5,85 +5,6 @@ maputils.CONST = {}
maputils.CONST.STARTX = -8 maputils.CONST.STARTX = -8
maputils.CONST.STARTY = 90 maputils.CONST.STARTY = 90
function maputils.newEmptyMap()
return {
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00},
}
end
function maputils.newFullMap()
return {
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
{01,01,01,01,01,01,01,01,01,01,01,01},
}
end
function maputils.isInMask(x, y, ox, oy, shape, size, direction)
local direction = direction or 1
local shape = shape or "point"
if shape == "point" then
return ((x == ox) and (y == oy))
elseif shape == "square" then
local x1 = ox - math.floor(size/2)
local x2 = ox + math.ceil(size/2)
local y1 = oy - math.floor(size/2)
local y2 = oy + math.ceil(size/2)
return ((x >= x1) and (x <= x2) and (y >= y1) and (y <= y2))
elseif shape == "circle" then
local lenght = utils.math.pointDistance(x, y, ox, oy)
return (lenght <= size)
elseif shape == "fullheight" then
local x2 = ox + (size*direction)
return ((x >= ox) and (x <= x2))
elseif shape == "fullwidth" then
local y2 = oy + (size*direction)
return ((y >= oy) and (y <= y2))
elseif shape == "line" then
local x2 = ox + (size*direction)
return ((y == oy) and (x >= ox) and (x <= x2))
elseif shape == "column" then
local y2 = oy + (size*direction)
return ((x == ox) and (y >= oy) and (y <= y2))
elseif shape == "everything" then
return true
else
if shape == nil then
shape = "nil"
end
core.debug:warning("maputils", "shape " .. shape .. " doesn't exist")
end
end
function maputils.maskToMap(ox, oy, shape, size, direction)
local map = maputils.newEmptyMap()
for i, line in ipairs(map) do
for j, case in ipairs(line) do
local isInMask = maputils.isInMask(j, i, ox, oy, shape, size, direction)
if (isInMask) then
map[i][j] = 1
else
map[i][j] = 0
end
end
end
return map
end
function maputils.sortBattlers(a, b) function maputils.sortBattlers(a, b)
local astats = a.fighter:getStats() local astats = a.fighter:getStats()
local bstats = b.fighter:getStats() local bstats = b.fighter:getStats()

View file

@ -2,7 +2,6 @@ local World = Object:extend()
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
local Map = require "scenes.battlesystem.map" local Map = require "scenes.battlesystem.map"
local Cursor = require "scenes.battlesystem.cursor"
local TweenManager = require "game.modules.tweenmanager" local TweenManager = require "game.modules.tweenmanager"
@ -26,11 +25,6 @@ function World:new(scene, battlefile)
self.actors = {} self.actors = {}
self.globalID = 0 self.globalID = 0
self.battlers = {}
self.heroNumber = 0
self.ennNumber = 0
self.map = Map(self, "city") self.map = Map(self, "city")
self.isBattleActive = false self.isBattleActive = false
@ -78,46 +72,19 @@ function World:update(dt)
for i, actor in ipairs(self.actors) do for i, actor in ipairs(self.actors) do
actor:update(dt) actor:update(dt)
end end
self.map:update(dt)
end end
function World:sendSignalToCurrentBattler(signal, subSignal) function World:sendSignalToCurrentBattler(signal, subSignal)
self.scene.turns:sendSignalToCurrentBattler(signal, subSignal) self.scene.turns:sendSignalToCurrentBattler(signal, subSignal)
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()
self.map:draw(self.activeGrid, self.effectGrid) self.map:draw()
--self.cursor:drawBottom()
self:drawShadows() self:drawShadows()
self:drawActors() self:drawActors()
--self.cursor:drawTop()
end end
function World:drawActors() function World:drawActors()