feat: add the heroes style of switching characters

Fix #20
This commit is contained in:
Kazhnuz 2020-08-03 10:28:18 +02:00
parent 11e40da8af
commit 751951f734
4 changed files with 51 additions and 2 deletions

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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")