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
function Battler:update(dt)
Battler.super.update(self, dt)
if (self.isActive) then
self.debugActiveTimer = self.debugActiveTimer + dt
if self.debugActiveTimer >= 0.5 then

View file

@ -13,6 +13,8 @@ function Ennemy:new(world, x, y, id, number)
self:receiveDatas()
self.hp = self.data.stats.hpmax
self.pp = self.data.stats.ppmax
self.shownHP = self.hp
end
function Ennemy:draw()
@ -27,7 +29,7 @@ function Ennemy:drawHUD()
love.graphics.setColor(0, 0, 0, 1)
gui.drawBar(x - 14, y - 38, 26, 4)
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)
love.graphics.setColor(1, 1, 1, 1)
@ -49,6 +51,7 @@ function Ennemy:setHP(value, relative)
end
self.hp = value
self.tweens:newTween(0, 0.1, {shownHP = self.hp}, 'inCubic')
if (self.hp <= 0) then
self:destroy()
end

View file

@ -55,7 +55,7 @@ end
-- Update the hero
function Hero:update(dt)
self:updateSprite(dt)
Hero.super.update(self, dt)
self.keys = self.scene:getKeys(1)
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 TweenManager = require "game.modules.tweenmanager"
-- INIT FUNCTION
-- Initilize the actor
@ -25,6 +27,9 @@ function Parent:new(world, x, y, z)
self.isEnnemy = false
self.isDestroyed = false
self.tweens = TweenManager(self)
self:setSprite()
self:register()
end
@ -39,6 +44,7 @@ end
function Parent:update(dt)
self:updateSprite(dt)
self.tweens:update(dt)
end
-- SPRITE FUNCTIONS

View file

@ -1,12 +1,15 @@
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
@ -81,28 +84,32 @@ function Cursor:update(dt)
if (self.isActive) then
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)
if (self.grid[dy][self.x] == 1) then
self.y = dy
self:addTween()
end
end
if (keys["down"].isPressed) then
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"].isPressed) then
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"].isPressed) then
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
@ -110,13 +117,14 @@ function Cursor:update(dt)
self.world:sendSignalToCurrentBattler()
end
self.tx = (self.tx) + ((self.x) - (self.tx)) * dt*30
self.ty = (self.ty) + ((self.y) - (self.ty)) * dt*30
-- test
--game
self.tweens:update(dt)
end
end
function Cursor:addTween()
self.tweens:newTween(0, 0.2, {tx = self.x, ty = self.y}, 'inCubic')
end
function Cursor:drawBottom()
if (self.isActive) then

View file

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