From 751951f7346902d03ea5c7608a65c89b7bdbfa85 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 3 Aug 2020 10:28:18 +0200 Subject: [PATCH] feat: add the heroes style of switching characters Fix #20 --- sonic-radiance.love/core/utils/math.lua | 6 +++ sonic-radiance.love/game/characters.lua | 4 ++ .../scenes/overworld/actors/player.lua | 42 ++++++++++++++++++- sonic-radiance.love/scenes/overworld/init.lua | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/sonic-radiance.love/core/utils/math.lua b/sonic-radiance.love/core/utils/math.lua index fea382b..d108567 100644 --- a/sonic-radiance.love/core/utils/math.lua +++ b/sonic-radiance.love/core/utils/math.lua @@ -99,6 +99,12 @@ function Math.pointDirection(x1,y1,x2,y2) return angle end +function Math.lengthdir(lenght, dir) + local x = math.cos(dir) * lenght + local y = -math.sin(dir) * lenght + return x, y +end + -- STRING FUNCTIONS -- Transform into string numbers diff --git a/sonic-radiance.love/game/characters.lua b/sonic-radiance.love/game/characters.lua index a66829e..6e10658 100644 --- a/sonic-radiance.love/game/characters.lua +++ b/sonic-radiance.love/game/characters.lua @@ -147,6 +147,10 @@ function CharacterManager:getActiveCharacterData() return self.list[self.team[self.active]] end +function CharacterManager:loadSprite(assets, name) + assets:addSprite(name, "datas/gamedata/characters/" .. name .. "/sprites") +end + -- DEBUG FUNCTIONS function CharacterManager:printCharacter(id) diff --git a/sonic-radiance.love/scenes/overworld/actors/player.lua b/sonic-radiance.love/scenes/overworld/actors/player.lua index 3f8bbd0..cb71d14 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player.lua @@ -2,10 +2,25 @@ local cwd = (...):gsub('%.player$', '') .. "." local Parent = require(cwd .. "parent") local Player = Parent:extend() +local Emblem = require "game.modules.gui.emblem" + +local TweenManager = require "game.modules.tweenmanager" + function Player:new(world, x, y, id) Player.super.new(self, world, "player", x, y, 16, 16, true) self.charset:addTexture("perso") self.active = game.characters:getActiveCharacterData() + + self.emblems = {} + for i, name in ipairs(game.characters.team) do + game.characters:loadSprite(self.assets, name) + self.emblems[i] = Emblem(game.characters.list[name], self.scene) + end + + self.activeVisible = game.characters.active + self.canChangeActive = true + + self.tweens = TweenManager(self) end function Player:isMoving() @@ -32,8 +47,20 @@ function Player:updateStart(dt) self.charDir = "right" end - if self.keys["select"].isPressed then + if self.keys["select"].isPressed and self.canChangeActive then game.characters:setActiveCharacter() + self.canChangeActive = false + self.tweens:newTimer(0.3, "changeCharacter") + self.tweens:newTween(0, 0.3, {activeVisible = self.activeVisible + 1}, "inQuad") + end + + self.tweens:update(dt) +end + +function Player:timerResponse(response) + if (response == "changeCharacter") then + self.canChangeActive = true + self.activeVisible = game.characters.active self.active = game.characters:getActiveCharacterData() end end @@ -47,11 +74,22 @@ function Player:draw() end function Player:drawHUD(id) - local border = 8 + local border = 16 self.assets.images["guiRing"]:draw(border, border) local ringString = utils.math.numberToString(game.loot.rings, 3) self.assets.fonts["hudnbrs"]:print(ringString, border + 14, border + 1) --love.graphics.print(id .. " test", 4, 4) + self:drawEmblems(368, 24) +end + +function Player:drawEmblems(x, y) +for i,emblem in ipairs(self.emblems) do + local angle = ((i-self.activeVisible) * (360/#self.emblems)) - 90 + local rad = math.rad(angle) + local emblemX, emblemY = utils.math.lengthdir(18, rad) + emblem:draw(x + emblemX, y + emblemY) +end + end return Player diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 56f1326..ff7aeae 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -30,6 +30,7 @@ local CharsetManager = require "scenes.overworld.charsetmanager" function MovePlayer:new() MovePlayer.super.new(self) self.charsetManager = CharsetManager(self) + self.assets:batchImport("game.modules.gui.assets") self.assets:batchImport("scenes.overworld.assets") World(self, "test", "map")