diff --git a/sonic-radiance.love/assets/sprites/charset/perso.png b/sonic-radiance.love/assets/sprites/charset/perso.png new file mode 100644 index 0000000..0cc9985 Binary files /dev/null and b/sonic-radiance.love/assets/sprites/charset/perso.png differ diff --git a/sonic-radiance.love/scenes/overworld/actors/parent.lua b/sonic-radiance.love/scenes/overworld/actors/parent.lua index 4a7e397..7b27ac1 100644 --- a/sonic-radiance.love/scenes/overworld/actors/parent.lua +++ b/sonic-radiance.love/scenes/overworld/actors/parent.lua @@ -4,6 +4,8 @@ local Parent = Base:extend() function Parent:new(world, type, x, y, w, h, isSolid) self.scene = world.scene Parent.super.new(self, world, type, x, y, w, h, isSolid) + self.charDir = "down" + self.charset = self.world.scene.charsetManager end function Parent:draw() diff --git a/sonic-radiance.love/scenes/overworld/actors/player.lua b/sonic-radiance.love/scenes/overworld/actors/player.lua index 9e80089..7f9187d 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player.lua @@ -4,7 +4,11 @@ local Player = Parent:extend() function Player:new(world, x, y, id) Player.super.new(self, world, "player", x, y, 16, 16, true) + self.charset:addTexture("perso") +end +function Player:isMoving() + return ((math.abs(self.ysp) > 0.01) or (math.abs(self.xsp) > 0.01)) end function Player:updateStart(dt) @@ -12,20 +16,28 @@ function Player:updateStart(dt) if self.keys["up"].isDown then self.ysp = -120 + self.charDir = "up" end if self.keys["down"].isDown then self.ysp = 120 + self.charDir = "down" end if self.keys["left"].isDown then self.xsp = -120 + self.charDir = "left" end if self.keys["right"].isDown then self.xsp = 120 + self.charDir = "right" end end function Player:draw() - Player.super.draw(self) + if (self:isMoving()) then + self.charset:draw("perso", 1, self.charDir, self.x, self.y) + else + self.charset:drawStanding("perso", 1, self.charDir, self.x, self.y) + end end function Player:drawHUD(id) diff --git a/sonic-radiance.love/scenes/overworld/charsetmanager.lua b/sonic-radiance.love/scenes/overworld/charsetmanager.lua new file mode 100644 index 0000000..194cb62 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/charsetmanager.lua @@ -0,0 +1,74 @@ +local Charset = Object:extend() + +local folder = "assets/sprites/charset/" +local animation = {1, 2, 3, 2} +local directionList = {"down", "right", "up", "left"} + +function Charset:new(scene) + self.char = {} + self.list = {} + + for i=1, 2 do + for j=1, 4 do + local id = ((i-1)*4) + j + self.char[id] = self:addChar(i, j) + end + end + self.currentFrame = 0 +end + +function Charset:update(dt) + self.currentFrame = ((self.currentFrame + (dt*5)) % 4) +end + +function Charset:addChar(ii, jj) + local charx, chary = (jj-1)*(24*3), (ii-1)*(32*4) + print(charx, chary) + local char = {} + for i=1, 4 do + animatedDirection = {} + local running = {} + for j=1, 3 do + local x, y = charx + ((j-1)*24), (chary + (i-1)*32) + --print(x, y) + running[j] = love.graphics.newQuad(x, y, 24, 32, 24*12, 32*8) + end + local direction = directionList[i] + char[direction] = running + end + return char +end + +function Charset:addTexture(charsetName) + self.list[charsetName] = love.graphics.newImage(folder .. charsetName .. ".png") +end + +function Charset:getRunningFrame(charID, direction) + local char = self.char[charID] + local animatedDirection = char[direction] + local fakeFrame = math.min(math.floor(self.currentFrame) + 1, 4) + print(fakeFrame) + local trueFrame = animation[fakeFrame] + print(trueFrame) + return animatedDirection[trueFrame] +end + +function Charset:getStandingFrame(charID, direction) + local char = self.char[charID] + local animatedDirection = char[direction] + return animatedDirection[2] +end + +function Charset:draw(charsetName, charID, direction, x, y) + local drawable = self.list[charsetName] + local quad = self:getRunningFrame(charID, direction) + love.graphics.draw(drawable, quad, math.floor(x), math.floor(y), 0, 1, 1, 4, 16) +end + +function Charset:drawStanding(charsetName, charID, direction, x, y) + local drawable = self.list[charsetName] + local quad = self:getStandingFrame(charID, direction) + love.graphics.draw(drawable, quad, x, y, 0, 1, 1, 4, 16) +end + +return Charset diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 7dff1d5..48c27de 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -25,9 +25,11 @@ local Scene = require "core.modules.scenes" local MovePlayer = Scene:extend() local World = require "scenes.overworld.world" +local CharsetManager = require "scenes.overworld.charsetmanager" function MovePlayer:new() MovePlayer.super.new(self) + self.charsetManager = CharsetManager(self) World(self, "test", "map") self.world:setPlayerNumber(1) @@ -35,7 +37,7 @@ function MovePlayer:new() end function MovePlayer:update(dt) - + self.charsetManager:update(dt) end function MovePlayer:draw()