1
0

make player wobble as he walks

This commit is contained in:
Rokas Puzonas 2022-08-13 11:50:35 +00:00
parent e40b9a959e
commit 7f26575942
3 changed files with 15 additions and 2 deletions

View File

@ -10,7 +10,11 @@ all: win32 win64 linux
love: clean_love
mkdir -p build
cd src && zip -9 -r ../build/$(name).love .
cd src && zip -9 -r ../build/$(name).love . \
-x *.tiled-project \
-x *.tiled-session \
-x *.tsx \
-x *.tmx \
win32: clean_windows download-love-win32 love
mkdir -p build/win32/$(name)

View File

@ -106,8 +106,10 @@ function Player:update(dt)
if e.acc.x ~= 0 or e.acc.y ~= 0 then
e.sprite.variant = "walk"
e.sprite.wobble = true
else
e.sprite.variant = "idle"
e.sprite.wobble = false
end
if e.acc.x < 0 then

View File

@ -39,6 +39,7 @@ function Sprite:draw()
if not e.hidden then
local variant = sprite.variants[e.sprite.variant or "default"]
if variant and e.sprite.frame then
local rotation = nil
local frame = variant[e.sprite.frame]
if not frame then
frame = variant[1]
@ -47,11 +48,17 @@ function Sprite:draw()
if e.sprite.flip then
sx = -1
end
if e.sprite.wobble then
rotation = math.sin(love.timer.getTime()*10)*0.15
end
love.graphics.draw(
frame.image,
e.pos.x,
e.pos.y,
0, sx, 1,
rotation,
sx, 1,
sprite.width/2, sprite.height/2
)
end