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, distAttack = false,
turns = 2, turns = 2,
hudHeight = 24,
giveExp = 20, giveExp = 20,
giveRings = 30, 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) love.graphics.setColor(1, 1, 1, 1)
end 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() function Battler:validateAction()
end end

View file

@ -8,13 +8,15 @@ function Ennemy:new(world, x, y, owner)
self.isEnnemy = true self.isEnnemy = true
self.actionPerTurn = 2 self.actionPerTurn = 2
self:initSprite()
self.direction = -1
end end
function Ennemy:draw() function Ennemy:draw()
Ennemy.super.draw(self) self:drawSprite(0, -self.z)
local x, y = self.world.map:gridToPixel(self.x, self.y, true) 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 if (self.isSelected) then
local height = 32 local height = 32
@ -26,4 +28,12 @@ function Ennemy:getStats()
return self.data.stats return self.data.stats
end 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 return Ennemy

View file

@ -206,12 +206,8 @@ end
-- ASSETS FUNCTIONS -- ASSETS FUNCTIONS
-- Load and play assets needed by the character -- Load and play assets needed by the character
function Hero:initSprite() function Hero:getSpritePath()
self.assets:addSprite(self.owner.name, "datas/gamedata/characters/" .. self.owner.name .. "/sprites") return "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")
end end
function Hero:animationEnded(animation) function Hero:animationEnded(animation)