improvement(cbs): add more tweens

This commit is contained in:
Kazhnuz 2019-08-16 23:04:30 +02:00
parent 618c42b3b6
commit c7e771542b
6 changed files with 36 additions and 16 deletions

View file

@ -22,6 +22,7 @@ function Battler:setActive()
end end
function Battler:update(dt) function Battler:update(dt)
Battler.super.update(self, dt)
if (self.isActive) then if (self.isActive) then
self.debugActiveTimer = self.debugActiveTimer + dt self.debugActiveTimer = self.debugActiveTimer + dt
if self.debugActiveTimer >= 0.5 then if self.debugActiveTimer >= 0.5 then

View file

@ -13,6 +13,8 @@ function Ennemy:new(world, x, y, id, number)
self:receiveDatas() self:receiveDatas()
self.hp = self.data.stats.hpmax self.hp = self.data.stats.hpmax
self.pp = self.data.stats.ppmax self.pp = self.data.stats.ppmax
self.shownHP = self.hp
end end
function Ennemy:draw() function Ennemy:draw()
@ -27,7 +29,7 @@ function Ennemy:drawHUD()
love.graphics.setColor(0, 0, 0, 1) love.graphics.setColor(0, 0, 0, 1)
gui.drawBar(x - 14, y - 38, 26, 4) gui.drawBar(x - 14, y - 38, 26, 4)
love.graphics.setColor(248/255, 160/255, 0, 1) love.graphics.setColor(248/255, 160/255, 0, 1)
local bar = math.floor(24 * (self.hp / self.data.stats.hpmax)) local bar = math.floor(24 * (self.shownHP / self.data.stats.hpmax))
gui.drawBar(x - 14, y - 37, bar, 2) gui.drawBar(x - 14, y - 37, bar, 2)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
@ -49,6 +51,7 @@ function Ennemy:setHP(value, relative)
end end
self.hp = value self.hp = value
self.tweens:newTween(0, 0.1, {shownHP = self.hp}, 'inCubic')
if (self.hp <= 0) then if (self.hp <= 0) then
self:destroy() self:destroy()
end end

View file

@ -55,7 +55,7 @@ end
-- Update the hero -- Update the hero
function Hero:update(dt) function Hero:update(dt)
self:updateSprite(dt) Hero.super.update(self, dt)
self.keys = self.scene:getKeys(1) self.keys = self.scene:getKeys(1)
if (self.currentAction == "moving") then if (self.currentAction == "moving") then

View file

@ -2,6 +2,8 @@ local Parent = Object:extend() -- On créer la classe des entitées, c'est la cl
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
local TweenManager = require "game.modules.tweenmanager"
-- INIT FUNCTION -- INIT FUNCTION
-- Initilize the actor -- Initilize the actor
@ -25,6 +27,9 @@ function Parent:new(world, x, y, z)
self.isEnnemy = false self.isEnnemy = false
self.isDestroyed = false self.isDestroyed = false
self.tweens = TweenManager(self)
self:setSprite()
self:register() self:register()
end end
@ -39,6 +44,7 @@ end
function Parent:update(dt) function Parent:update(dt)
self:updateSprite(dt) self:updateSprite(dt)
self.tweens:update(dt)
end end
-- SPRITE FUNCTIONS -- SPRITE FUNCTIONS

View file

@ -1,12 +1,15 @@
local Cursor = Object:extend() local Cursor = Object:extend()
local maputils = require "scenes.battlesystem.utils" local maputils = require "scenes.battlesystem.utils"
local TweenManager = require "game.modules.tweenmanager"
function Cursor:new(world) function Cursor:new(world)
self.world = world self.world = world
self.scene = world.scene self.scene = world.scene
self.assets = world.assets self.assets = world.assets
self.tweens = TweenManager(self)
self.x = 1 self.x = 1
self.y = 1 self.y = 1
self.isActive = false self.isActive = false
@ -81,28 +84,32 @@ function Cursor:update(dt)
if (self.isActive) then if (self.isActive) then
local keys = self.scene:getKeys(1) local keys = self.scene:getKeys(1)
if (keys["up"].isPressed) then if (keys["up"].isDown and self.y == self.ty) then
dy = math.max(self.y - 1, 1) dy = math.max(self.y - 1, 1)
if (self.grid[dy][self.x] == 1) then if (self.grid[dy][self.x] == 1) then
self.y = dy self.y = dy
self:addTween()
end end
end end
if (keys["down"].isPressed) then if (keys["down"].isDown and self.y == self.ty) then
dy = math.min(self.y + 1, 7) dy = math.min(self.y + 1, 7)
if (self.grid[dy][self.x] == 1) then if (self.grid[dy][self.x] == 1) then
self.y = dy self.y = dy
self:addTween()
end end
end end
if (keys["left"].isPressed) then if (keys["left"].isDown and self.x == self.tx) then
dx = math.max(self.x - 1, 1) dx = math.max(self.x - 1, 1)
if (self.grid[self.y][dx] == 1) then if (self.grid[self.y][dx] == 1) then
self.x = dx self.x = dx
self:addTween()
end end
end end
if (keys["right"].isPressed) then if (keys["right"].isDown and self.x == self.tx) then
dx = math.min(self.x + 1, 12) dx = math.min(self.x + 1, 12)
if (self.grid[self.y][dx] == 1) then if (self.grid[self.y][dx] == 1) then
self.x = dx self.x = dx
self:addTween()
end end
end end
@ -110,13 +117,14 @@ function Cursor:update(dt)
self.world:sendSignalToCurrentBattler() self.world:sendSignalToCurrentBattler()
end end
self.tx = (self.tx) + ((self.x) - (self.tx)) * dt*30 self.tweens:update(dt)
self.ty = (self.ty) + ((self.y) - (self.ty)) * dt*30
-- test
--game
end end
end end
function Cursor:addTween()
self.tweens:newTween(0, 0.2, {tx = self.x, ty = self.y}, 'inCubic')
end
function Cursor:drawBottom() function Cursor:drawBottom()
if (self.isActive) then if (self.isActive) then

View file

@ -4,6 +4,8 @@ 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 Cursor = require "scenes.battlesystem.cursor"
local TweenManager = require "game.modules.tweenmanager"
local POSITIONS = { local POSITIONS = {
{x = 3, y = 4}, {x = 3, y = 4},
{x = 2, y = 2}, {x = 2, y = 2},
@ -42,6 +44,8 @@ function World:new(scene, battlefile)
self.map = Map(self, "city") self.map = Map(self, "city")
self.cursor = Cursor(self) self.cursor = Cursor(self)
self.tweens = TweenManager(self)
self:initHeroes() self:initHeroes()
self:initEnnemies() self:initEnnemies()
self:initHUD() self:initHUD()
@ -187,15 +191,10 @@ function World:update(dt)
if (self.isBattleActive) then if (self.isBattleActive) then
self:updateTurns(dt) self:updateTurns(dt)
local dPosition = math.floor(self.playerHUDPosition + dt * 256)
self.playerHUDPosition = math.min(dPosition, 36)
else
local dPosition = math.floor(self.playerHUDPosition - dt * 256)
self.playerHUDPosition = math.max(dPosition, -64)
end end
self:moveBattleCursor(dt)
self.cursor:update(dt) self.cursor:update(dt)
self.tweens:update(dt)
end end
function World:moveBattleCursor(dt) function World:moveBattleCursor(dt)
@ -217,6 +216,7 @@ end
function World:startBattle() function World:startBattle()
self.isBattleActive = true self.isBattleActive = true
self.tweens:newTween(0, 0.4, {playerHUDPosition = 36}, 'inCubic')
end end
function World:recalculateTurns() function World:recalculateTurns()
@ -243,6 +243,7 @@ function World:switchActiveBattler()
self:selectNextAction() self:selectNextAction()
self.turns.changeBattler = false self.turns.changeBattler = false
self.tweens:newTween(0, 0.2, {BattlerCursor = self.turns.current}, 'inCubic')
end end
end end
@ -264,6 +265,7 @@ end
function World:finishBattle() function World:finishBattle()
self.isBattleActive = false self.isBattleActive = false
self.tweens:newTween(0, 0.4, {playerHUDPosition = -64}, 'inCubic')
self.actionlist = {} self.actionlist = {}
self.scene:finishBattle() self.scene:finishBattle()
end end