Ajout des derniers développement #1
5 changed files with 92 additions and 2 deletions
BIN
sonic-radiance.love/assets/sprites/charset/perso.png
Normal file
BIN
sonic-radiance.love/assets/sprites/charset/perso.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
|
@ -4,6 +4,8 @@ local Parent = Base:extend()
|
||||||
function Parent:new(world, type, x, y, w, h, isSolid)
|
function Parent:new(world, type, x, y, w, h, isSolid)
|
||||||
self.scene = world.scene
|
self.scene = world.scene
|
||||||
Parent.super.new(self, world, type, x, y, w, h, isSolid)
|
Parent.super.new(self, world, type, x, y, w, h, isSolid)
|
||||||
|
self.charDir = "down"
|
||||||
|
self.charset = self.world.scene.charsetManager
|
||||||
end
|
end
|
||||||
|
|
||||||
function Parent:draw()
|
function Parent:draw()
|
||||||
|
|
|
@ -4,7 +4,11 @@ local Player = Parent:extend()
|
||||||
|
|
||||||
function Player:new(world, x, y, id)
|
function Player:new(world, x, y, id)
|
||||||
Player.super.new(self, world, "player", x, y, 16, 16, true)
|
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
|
end
|
||||||
|
|
||||||
function Player:updateStart(dt)
|
function Player:updateStart(dt)
|
||||||
|
@ -12,20 +16,28 @@ function Player:updateStart(dt)
|
||||||
|
|
||||||
if self.keys["up"].isDown then
|
if self.keys["up"].isDown then
|
||||||
self.ysp = -120
|
self.ysp = -120
|
||||||
|
self.charDir = "up"
|
||||||
end
|
end
|
||||||
if self.keys["down"].isDown then
|
if self.keys["down"].isDown then
|
||||||
self.ysp = 120
|
self.ysp = 120
|
||||||
|
self.charDir = "down"
|
||||||
end
|
end
|
||||||
if self.keys["left"].isDown then
|
if self.keys["left"].isDown then
|
||||||
self.xsp = -120
|
self.xsp = -120
|
||||||
|
self.charDir = "left"
|
||||||
end
|
end
|
||||||
if self.keys["right"].isDown then
|
if self.keys["right"].isDown then
|
||||||
self.xsp = 120
|
self.xsp = 120
|
||||||
|
self.charDir = "right"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:draw()
|
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
|
end
|
||||||
|
|
||||||
function Player:drawHUD(id)
|
function Player:drawHUD(id)
|
||||||
|
|
74
sonic-radiance.love/scenes/overworld/charsetmanager.lua
Normal file
74
sonic-radiance.love/scenes/overworld/charsetmanager.lua
Normal file
|
@ -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
|
|
@ -25,9 +25,11 @@ local Scene = require "core.modules.scenes"
|
||||||
local MovePlayer = Scene:extend()
|
local MovePlayer = Scene:extend()
|
||||||
|
|
||||||
local World = require "scenes.overworld.world"
|
local World = require "scenes.overworld.world"
|
||||||
|
local CharsetManager = require "scenes.overworld.charsetmanager"
|
||||||
|
|
||||||
function MovePlayer:new()
|
function MovePlayer:new()
|
||||||
MovePlayer.super.new(self)
|
MovePlayer.super.new(self)
|
||||||
|
self.charsetManager = CharsetManager(self)
|
||||||
|
|
||||||
World(self, "test", "map")
|
World(self, "test", "map")
|
||||||
self.world:setPlayerNumber(1)
|
self.world:setPlayerNumber(1)
|
||||||
|
@ -35,7 +37,7 @@ function MovePlayer:new()
|
||||||
end
|
end
|
||||||
|
|
||||||
function MovePlayer:update(dt)
|
function MovePlayer:update(dt)
|
||||||
|
self.charsetManager:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function MovePlayer:draw()
|
function MovePlayer:draw()
|
||||||
|
|
Loading…
Reference in a new issue