diff --git a/imperium-porcorum.love/assets/sprites/pigs/bling-bling.lua b/imperium-porcorum.love/assets/sprites/pigs/bling-bling.lua index c3e458b..319dbbd 100644 --- a/imperium-porcorum.love/assets/sprites/pigs/bling-bling.lua +++ b/imperium-porcorum.love/assets/sprites/pigs/bling-bling.lua @@ -2,6 +2,8 @@ return { metadata = { width = 32, height = 48, + ox = 16, + oy = 12, defaultAnim = "idle" }, animations = { diff --git a/imperium-porcorum.love/assets/sprites/pigs/cochon.lua b/imperium-porcorum.love/assets/sprites/pigs/cochon.lua index 3b34e78..507b841 100644 --- a/imperium-porcorum.love/assets/sprites/pigs/cochon.lua +++ b/imperium-porcorum.love/assets/sprites/pigs/cochon.lua @@ -2,7 +2,9 @@ return { metadata = { width = 32, height = 48, - defaultAnim = "walk" + ox = 16, + oy = 12, + defaultAnim = "idle" }, animations = { ["idle"] = { diff --git a/imperium-porcorum.love/scenes/levels/entities/loot/parent.lua b/imperium-porcorum.love/scenes/levels/entities/loot/parent.lua index c7b6b55..e530def 100644 --- a/imperium-porcorum.love/scenes/levels/entities/loot/parent.lua +++ b/imperium-porcorum.love/scenes/levels/entities/loot/parent.lua @@ -5,7 +5,7 @@ local Loot = Entity:extend() function Loot:new(world, x, y, name) Loot.super.new(self, world, "loot", x, y, 16, 16) self.type = "loot" - self.sprite = name + self:setSprite(name) end function Loot:takeLoot() @@ -20,8 +20,4 @@ function Loot:update(dt) Loot.super.update(self, dt) end -function Loot:draw() - self.scene.assets.sprites[self.sprite]:drawAnimation(self.x, self.y) -end - return Loot diff --git a/imperium-porcorum.love/scenes/levels/entities/parent.lua b/imperium-porcorum.love/scenes/levels/entities/parent.lua index 719c5f7..a3b6ca3 100644 --- a/imperium-porcorum.love/scenes/levels/entities/parent.lua +++ b/imperium-porcorum.love/scenes/levels/entities/parent.lua @@ -88,8 +88,4 @@ function Entity:isInsideView() return self.camera:isInsideView(self.x, self.y, self.w, self.h) end -function Entity:draw() - -- Cette fonction en contient rien par défaut -end - return Entity diff --git a/imperium-porcorum.love/scenes/levels/entities/player.lua b/imperium-porcorum.love/scenes/levels/entities/player.lua index 5d76ae2..ab14dfa 100644 --- a/imperium-porcorum.love/scenes/levels/entities/player.lua +++ b/imperium-porcorum.love/scenes/levels/entities/player.lua @@ -1,18 +1,18 @@ local Entity = require "scenes.levels.entities.parent" local Player = Entity:extend() +local PLAYER_W, PLAYER_H = 32, 24 -- INIT functions -- Initialize the player function Player:new(world, x, y, playerID) - - local w, h = 32, 24 self.direction = 1 self.startx, self.starty = x, y - Player.super.new(self, world, "player", x - (w / 2), y - (h / 2), w, h) + Player.super.new(self, world, "player", x, y, PLAYER_W, PLAYER_H) + self.manager = self.scene.playermanager self.center = { @@ -29,6 +29,7 @@ function Player:new(world, x, y, playerID) self.currentWeapon = 1 self:setDebugColor(0,255,0) + self:setSprite(self.stats.race, PLAYER_W/2, -PLAYER_H/2) end function Player:getStats(playerID) @@ -65,7 +66,7 @@ end function Player:update(dt) self.keys = self.scene.sources[1].keys - self.scene.assets.sprites[self.stats.race]:setCustomSpeed(math.abs(self.xsp / 60)) + self:setCustomSpeed(math.abs(self.xsp / 60)) self:actionMove(dt) self:shoot(dt) @@ -86,6 +87,8 @@ function Player:update(dt) if self.y >= (height + 64) then self:die() end + + self:setAnimation() end function Player:setFilter() @@ -199,41 +202,29 @@ end -- DRAW functions -function Player:getAnimation() +function Player:setAnimation() local animation = "idle" +self:setSpriteScallingX(self.direction) + if (self.onGround) then if (self.xsp == 0) then - animation = "idle" + self:changeAnimation("idle", false) else if (self.keys["left"].isDown and (self.xsp > 0)) or (self.keys["right"].isDown and (self.xsp < 0)) then - animation = "brake" + self:changeAnimation("brake", true) else - animation = "walk" + self:changeAnimation("walk", false) end end else if (self.ysp < 0) and (self.isJumping) then - animation = "jump" + self:changeAnimation("jump", true) else - animation = "fall" + self:changeAnimation("fall", true) end end - - if not (self.scene.assets.sprites[self.stats.race]:animationExist(animation)) then - animation = "idle" - end - - self.scene.assets.sprites[self.stats.race]:changeAnimation(animation, false) - - return animation -end - -function Player:draw(dt) - local drawx, drawy = utils.math.floorCoord(self.center.x, self.center.y) - local animation = self:getAnimation() - self.scene.assets.sprites[self.stats.race]:drawAnimation(drawx, drawy, 0, self.direction, 1, 16, 36) end -- DEATH and HIT functions