smol animation refactor & initial side draw
This commit is contained in:
parent
3373e367ac
commit
541c692f82
@ -3,8 +3,13 @@ local anim8 = require "lib.utils.anim8"
|
||||
--- Скорость между кадрами в анимации
|
||||
local ANIMATION_SPEED = 0.1
|
||||
|
||||
LEFT = -1
|
||||
RIGHT = 1
|
||||
|
||||
--- @class Animation
|
||||
--- @field animationTable table<string, table>
|
||||
--- @field state "idle"|"run"|"hurt"|"attack"
|
||||
--- @field side 1|-1
|
||||
local animation = {}
|
||||
|
||||
local function new(id, spriteDir)
|
||||
@ -21,6 +26,7 @@ local function new(id, spriteDir)
|
||||
end
|
||||
|
||||
anim.state = "idle"
|
||||
anim.side = RIGHT
|
||||
|
||||
anim.animationTable.idle = anim8.newAnimation(animationGrid["idle"], ANIMATION_SPEED)
|
||||
anim.animationTable.run = anim8.newAnimation(animationGrid["run"], ANIMATION_SPEED)
|
||||
|
||||
@ -27,7 +27,7 @@ function graphics:draw()
|
||||
|
||||
self.animation.animationTable[state]:draw(Tree.assets.files.sprites.character[state],
|
||||
position.x + 0.5,
|
||||
position.y + 0.5, nil, 1 / ppm, 1 / ppm, 38, 47)
|
||||
position.y + 0.5, nil, 1 / ppm * self.animation.side, 1 / ppm, 38, 47)
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
end
|
||||
|
||||
|
||||
@ -30,6 +30,11 @@ function selector:update(dt)
|
||||
if not characterId and self.id then -- временная обработка события "побежать к точке"
|
||||
local char = Tree.level.characters[self.id]
|
||||
local charPos = char.logic.mapLogic.position
|
||||
if mousePosition.x < charPos.x then
|
||||
char.graphics.animation.side = LEFT
|
||||
elseif mousePosition.x > charPos.x then
|
||||
char.graphics.animation.side = RIGHT
|
||||
end
|
||||
local path = (require "lib.pathfinder")(charPos, mousePosition)
|
||||
path:pop_front()
|
||||
print("Following path: ")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user