From 6dc1dc3ace057e3f7ff63f56971fdb432734392b Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 13 May 2016 12:54:22 +0200 Subject: Animation tweaks --- animations.lua | 2 ++ player.lua | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/animations.lua b/animations.lua index b7bcf3d..83ac5af 100644 --- a/animations.lua +++ b/animations.lua @@ -1,4 +1,6 @@ -- Animations spritesheet array for `Player` +-- Basic spritesheet size is 376x26. Each frame is 24x24 and has 1px border around it. +-- From the left: idle (walk0), walk1, walk2, walk3, attack0, attack1, attack3, attack_up0, attack_up1, attack_up2, attack_down0, attack_down1, attack_down2, damage0, damage1 local animations = { idle = { [1] = love.graphics.newQuad( 1, 1, 24,24, 376,26), diff --git a/player.lua b/player.lua index 22a3900..51ad29f 100644 --- a/player.lua +++ b/player.lua @@ -1,6 +1,9 @@ -- `Player` +-- Entity controlled by a player. It has a physical body and a sprite. Can play animations and interact with other instances of the same class. -- Collision category: [2] +-- WHOLE CODE HAS FLAG OF "need a cleanup" + -- Metatable of `Player` -- nils initialized in constructor Player = { @@ -66,7 +69,7 @@ function Player:update(dt) end -- Salto - if not self.jumpdouble and self.inAir then + if not self.jumpdouble and self.inAir and (self.current == self.animations.walk or self.current == self.animations.idle) then self.rotate = (self.rotate + 17 * dt * self.facing) % 360 elseif self.rotate ~= 0 then self.rotate = 0 @@ -133,6 +136,11 @@ function Player:keypressed(key) if key == self.key_jump then if not self.inAir then self.jumpactive = true + if (self.current == self.animations.attack) or + (self.current == self.animations.attack_up) or + (self.current == self.animations.attack_down) then + self:changeAnimation("idle") + end elseif self.jumpdouble then self.jumpactive = true self.jumpdouble = false -- cgit v1.1