diff --git a/src/assets/characters/matty.png b/src/assets/characters/matty.png deleted file mode 100644 index 7b4f225..0000000 Binary files a/src/assets/characters/matty.png and /dev/null differ diff --git a/src/assets/characters/player.png b/src/assets/characters/player.png index 7b4f225..703e24c 100644 Binary files a/src/assets/characters/player.png and b/src/assets/characters/player.png differ diff --git a/src/assets/characters/player.xcf b/src/assets/characters/player.xcf new file mode 100644 index 0000000..843f462 Binary files /dev/null and b/src/assets/characters/player.xcf differ diff --git a/src/assets/characters/romata.png b/src/assets/characters/romata.png index f7791f7..1d59ba0 100644 Binary files a/src/assets/characters/romata.png and b/src/assets/characters/romata.png differ diff --git a/src/assets/characters/romata.xcf b/src/assets/characters/romata.xcf index fd11af5..6c30477 100644 Binary files a/src/assets/characters/romata.xcf and b/src/assets/characters/romata.xcf differ diff --git a/src/engine/animator.lua b/src/engine/animator.lua index e7bad60..cc075e6 100644 --- a/src/engine/animator.lua +++ b/src/engine/animator.lua @@ -10,5 +10,6 @@ function Animator:__init(fullWidth, fullHeight) self.walk_left = anim8.newAnimation(self.animationGrid('1-9', 2), 0.1) self.walk_down = anim8.newAnimation(self.animationGrid('1-9', 3), 0.1) self.walk_right = anim8.newAnimation(self.animationGrid('1-9', 4), 0.1) + self.play = anim8.newAnimation(self.animationGrid('1-9', 5), 0.1) end diff --git a/src/engine/controllers/gridwalker.lua b/src/engine/controllers/gridwalker.lua index 176f463..eba5dd3 100644 --- a/src/engine/controllers/gridwalker.lua +++ b/src/engine/controllers/gridwalker.lua @@ -29,10 +29,33 @@ function Gridwalker:sendKey(key) end end +function Gridwalker:findAnimation(animationName) + local foundAnimation = nil + + if animationName == 'up' then + foundAnimation = self.animator.walk_up + elseif animationName == 'down' then + foundAnimation = self.animator.walk_down + elseif animationName == 'right' then + foundAnimation = self.animator.walk_right + elseif animationName == 'left' then + foundAnimation = self.animator.walk_left + elseif animationName == 'play' then + foundAnimation = self.animator.play + end + + return foundAnimation +end + function Gridwalker:stopAnimation() self.animation:pauseAtStart() end +function Gridwalker:startAnimation(animationName) + self.animation = self:findAnimation(animationName) + self.animation:resume() +end + function Gridwalker:up() local newX = self.objectinfo.x local newY = self.objectinfo.y - self.speed @@ -72,18 +95,10 @@ end function Gridwalker:init() self.testShape = collider:addRectangle(self.objectinfo.x + self.neighbourOffsetX, self.objectinfo.y + self.neighbourOffsetY, self.collisionTestSize, self.collisionTestSize) collider:setPassive(self.testShape) - + self.animator = Animator:new(self.objectinfo.image:getWidth(), self.objectinfo.image:getHeight()) - if self.objectinfo.pose == 'up' then - self.animation = self.animator.walk_up - elseif self.objectinfo.pose == 'down' then - self.animation = self.animator.walk_down - elseif self.objectinfo.pose == 'right' then - self.animation = self.animator.walk_right - elseif self.objectinfo.pose == 'left' then - self.animation = self.animator.walk_left - end + self.animation = self:findAnimation(self.objectinfo.pose) self.animation:pauseAtStart() end diff --git a/src/engine/init.lua b/src/engine/init.lua index 5e3b33d..1ca38df 100644 --- a/src/engine/init.lua +++ b/src/engine/init.lua @@ -86,6 +86,7 @@ function Engine:initObjects() local objectinfo = love.filesystem.load(filename)() objectinfo.x = obj.x - object.width / 4 objectinfo.y = obj.y + objectinfo.name = obj.name objectinfo.controller.objectinfo = objectinfo @@ -133,3 +134,12 @@ end function Engine:showMessage(message) ui:showMessage(message) end + +function Engine:animate(objectName, animationName) + for _, object in ipairs(self.objects) do + if object.name == objectName then + object.controller:startAnimation(animationName) + break + end + end +end diff --git a/src/levels/01.lua b/src/levels/01.lua index 24ed6b8..9e7619d 100644 --- a/src/levels/01.lua +++ b/src/levels/01.lua @@ -187,18 +187,6 @@ return { opacity = 1, properties = {}, objects = { - { - name = "matty", - type = "", - shape = "rectangle", - x = 416, - y = 96, - width = 32, - height = 64, - rotation = 0, - visible = true, - properties = {} - }, { name = "player", type = "", diff --git a/src/levels/01.tmx b/src/levels/01.tmx index 38d3b6b..f6448a5 100644 --- a/src/levels/01.tmx +++ b/src/levels/01.tmx @@ -28,7 +28,6 @@ - diff --git a/src/objects/matty.lua b/src/objects/matty.lua deleted file mode 100644 index 52d9208..0000000 --- a/src/objects/matty.lua +++ /dev/null @@ -1,8 +0,0 @@ -local object = require "engine/object" -local gridwalker = require "engine/controllers/gridwalker" - -return { - spritesheet = "assets/characters/romata.png", - pose = 'down', - controller = Gridwalker() -} diff --git a/src/objects/player.lua b/src/objects/player.lua index 10d75e5..15e5a34 100644 --- a/src/objects/player.lua +++ b/src/objects/player.lua @@ -2,7 +2,7 @@ local object = require "engine/object" local gridwalker = require "engine/controllers/gridwalker" return { - spritesheet = "assets/characters/romata.png", + spritesheet = "assets/characters/player.png", pose = 'up', controller = Gridwalker(), relevantKeys = { diff --git a/src/objects/romata.lua b/src/objects/romata.lua index db379e6..b4881d5 100644 --- a/src/objects/romata.lua +++ b/src/objects/romata.lua @@ -3,6 +3,6 @@ local gridwalker = require "engine/controllers/gridwalker" return { spritesheet = "assets/characters/romata.png", - pose = 'left', + pose = 'play', controller = Gridwalker() } diff --git a/src/story.lua b/src/story.lua index 65def9c..946e72d 100644 --- a/src/story.lua +++ b/src/story.lua @@ -3,6 +3,7 @@ local story = {} function story:start(engine) engine:loadLevel('01') engine:showMessage('Du befindest dich auf einer sturmgebeutelten Insel. Wo ist denn nur die Milch?') + engine:animate('romata', 'play') end return story \ No newline at end of file