feat: add sprites to ennemies

Fix #24
This commit is contained in:
Kazhnuz 2020-08-04 22:19:11 +02:00
parent d6b62a41e2
commit fb9d86999f
6 changed files with 51 additions and 8 deletions

View file

@ -7,6 +7,8 @@ return {
distAttack = false,
turns = 2,
hudHeight = 24,
giveExp = 20,
giveRings = 30,
}

View file

@ -0,0 +1,25 @@
return {
metadata = {
height = 64,
width = 64,
ox = 32,
oy = 32,
defaultAnim = "idle"
},
animations = {
["idle"] = {
startAt = 1,
endAt = 4,
loop = 1,
speed = 12,
pauseAtEnd = false,
},
["walk"] = {
startAt = 5,
endAt = 8,
loop = 5,
speed = 12,
pauseAtEnd = false,
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

@ -46,6 +46,16 @@ function Battler:draw()
love.graphics.setColor(1, 1, 1, 1)
end
function Battler:initSprite()
if (self.assets.sprites[self.owner.name] == nil) then
self.assets:addSprite(self.owner.name, self:getSpritePath())
end
self.assets.sprites[self.owner.name]:setCustomSpeed(16)
self:setSprite(self.owner.name, 32, 48, true)
self:cloneSprite()
self:changeAnimation("idle")
end
function Battler:validateAction()
end

View file

@ -8,13 +8,15 @@ function Ennemy:new(world, x, y, owner)
self.isEnnemy = true
self.actionPerTurn = 2
self:initSprite()
self.direction = -1
end
function Ennemy:draw()
Ennemy.super.draw(self)
self:drawSprite(0, -self.z)
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
self.owner:drawHUD(x - 12, y - 38)
self.owner:drawHUD(x - 12, y - self.owner.abstract.data.hudHeight)
if (self.isSelected) then
local height = 32
@ -26,4 +28,12 @@ function Ennemy:getStats()
return self.data.stats
end
-- ASSETS FUNCTIONS
-- Load and play assets needed by the character
function Ennemy:getSpritePath()
return "datas/gamedata/ennemies/" .. self.owner.category .. "/" .. self.owner.name .. "/sprites"
end
return Ennemy

View file

@ -206,12 +206,8 @@ end
-- ASSETS FUNCTIONS
-- Load and play assets needed by the character
function Hero:initSprite()
self.assets:addSprite(self.owner.name, "datas/gamedata/characters/" .. self.owner.name .. "/sprites")
self.assets.sprites[self.owner.name]:setCustomSpeed(16)
self:setSprite(self.owner.name, 32, 48, true)
self:cloneSprite()
self:changeAnimation("idle")
function Hero:getSpritePath()
return "datas/gamedata/characters/" .. self.owner.name .. "/sprites"
end
function Hero:animationEnded(animation)