From e0da0e869c5f0639b792c1e435b773393126ec02 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 00:12:16 +0100 Subject: Moved animation outside of player --- animated.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ player.lua | 53 ++++++++++++++++++++++------------------------------- 2 files changed, 64 insertions(+), 31 deletions(-) create mode 100644 animated.lua diff --git a/animated.lua b/animated.lua new file mode 100644 index 0000000..c698872 --- /dev/null +++ b/animated.lua @@ -0,0 +1,42 @@ +-- `Animated` +-- Abstract class for animated entities. + +-- Metatable +Animated = { + animations = require "animations", + current--[[animations.idle]], + frame = 1, + delay = .1 +} +Animated.__index = Animated +Animated.current = Animated.animations.idle + +-- setAnimation(self, animation) +function Animated:setAnimation(animation) + self.frame = 1 + self.delay = Animated.delay -- INITIAL from metatable + self.current = self.animations[animation] +end + +-- getAnimation(self) +function Animated:getAnimation() + return self.current +end + +-- animate(self, dt) +function Animated:animate(dt) + self.delay = self.delay - dt + if self.delay < 0 then + self.delay = self.delay + Animated.delay -- INITIAL from metatable + self:nextFrame() + end +end + +-- nextFrame(self) +function Animated:nextFrame() + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + else + self:setAnimation("idle") + end +end \ No newline at end of file diff --git a/player.lua b/player.lua index d2bc6d1..b3ce86f 100644 --- a/player.lua +++ b/player.lua @@ -3,6 +3,7 @@ -- Collision category: [2] -- WHOLE CODE HAS FLAG OF "need a cleanup" +require "animated" -- Metatable of `Player` -- nils initialized in constructor @@ -24,11 +25,6 @@ Player = { alive = true, punchcd = 0.25, punchdir = 0, -- a really bad thing - -- Animation - animations = require "animations", - current = nil, - frame = 1, - delay = 0.10, -- Movement inAir = true, salto = false, @@ -46,6 +42,8 @@ Player = { -- Sounds sfx = require "sounds" } +Player.__index = Player +setmetatable(Player, Animated) -- Constructor of `Player` function Player:new (game, world, x, y, name) @@ -153,21 +151,7 @@ function Player:update(dt) end end - -- # ANIMATIONS - -- Animation - self.delay = self.delay - dt - if self.delay < 0 then - self.delay = self.delay + Player.delay -- INITIAL from metatable - -- Thank you De Morgan! - if self.current.repeated or not (self.frame == self.current.frames) then - self.frame = (self.frame % self.current.frames) + 1 - elseif isDown(controlset, "right") or isDown(controlset, "left") then - -- If nonrepeatable animation is finished and player is walking - self:changeAnimation("walk") - elseif self.current == self.animations.damage then - self:changeAnimation("idle") - end - end + self:animate(dt) -- # DEATH -- We all die in the end. @@ -240,7 +224,7 @@ function Player:controlpressed(set, action, key) if (self.current == self.animations.attack) or (self.current == self.animations.attack_up) or (self.current == self.animations.attack_down) then - self:changeAnimation("idle") + self:setAnimation("idle") end -- Remove jump self.jumpnumber = self.jumpnumber - 1 @@ -252,7 +236,7 @@ function Player:controlpressed(set, action, key) (self.current ~= self.animations.attack) and (self.current ~= self.animations.attack_up) and (self.current ~= self.animations.attack_down) then - self:changeAnimation("walk") + self:setAnimation("walk") end -- Punching @@ -262,19 +246,19 @@ function Player:controlpressed(set, action, key) if isDown(controlset, "up") then -- Punch up if self.current ~= self.animations.damage then - self:changeAnimation("attack_up") + self:setAnimation("attack_up") end self:hit("up") elseif isDown(controlset, "down") then -- Punch down if self.current ~= self.animations.damage then - self:changeAnimation("attack_down") + self:setAnimation("attack_down") end self:hit("down") else -- Punch horizontal if self.current ~= self.animations.damage then - self:changeAnimation("attack") + self:setAnimation("attack") end if f == 1 then self:hit("right") @@ -299,7 +283,7 @@ function Player:controlreleased(set, action, key) (isDown(controlset, "left") or isDown(controlset, "right")) and self.current == self.animations.walk then - self:changeAnimation("idle") + self:setAnimation("idle") end end @@ -359,10 +343,17 @@ end -- Change animation of `Player` -- idle, walk, attack, attack_up, attack_down, damage -function Player:changeAnimation(animation) - self.frame = 1 - self.delay = Player.delay -- INITIAL from metatable - self.current = self.animations[animation] +function Player:nextFrame() + local isDown = Controller.isDown + local controlset = self:getControlSet() + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + elseif isDown(controlset, "right") or isDown(controlset, "left") then + -- If nonrepeatable animation is finished and player is walking + self:setAnimation("walk") + elseif self.current == self.animations.damage then + self:setAnimation("idle") + end end -- Spawn `Effect` relative to `Player` @@ -425,7 +416,7 @@ function Player:damage(direction) local x,y = self.body:getLinearVelocity() self.body:setLinearVelocity(x,0) self.body:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) - self:changeAnimation("damage") + self:setAnimation("damage") self.combo = math.min(27, self.combo + 1) self.punchcd = 0.08 + self.combo*0.006 self:playSound(2) -- cgit v1.1 From cc48afb0a20d01c8f4098c195239f2ca51fac495 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 12:09:54 +0100 Subject: Animated class changes. --- animated.lua | 43 ++++++++++++++++++++++++++++++------------- animations.lua | 4 ++-- player.lua | 23 +++++++++++++---------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/animated.lua b/animated.lua index c698872..236b68d 100644 --- a/animated.lua +++ b/animated.lua @@ -1,42 +1,59 @@ -- `Animated` --- Abstract class for animated entities. +-- Abstract class for drawable animated entities. -- Metatable Animated = { - animations = require "animations", - current--[[animations.idle]], + animations--[[table with animations]], + current--[[animations.default]], + sprite--[[love.graphics.newImage()]], frame = 1, - delay = .1 + delay = .1, } Animated.__index = Animated -Animated.current = Animated.animations.idle --- setAnimation(self, animation) +-- Sets an Image as a sprite. +function Animated:setSprite(image) + self.sprite = image +end +-- Returns current sprite Image. +function Animated:getSprite() + return self.sprite +end + +-- Sets current animation by table key. function Animated:setAnimation(animation) self.frame = 1 self.delay = Animated.delay -- INITIAL from metatable self.current = self.animations[animation] end - --- getAnimation(self) +-- Returns current animation table. function Animated:getAnimation() return self.current end --- animate(self, dt) -function Animated:animate(dt) +-- Get frame quad for drawing. +function Animated:getQuad() + return self.current[self.frame] +end + +-- Drawing self to LOVE2D buffer. +function Animated:draw(...) + love.graphics.draw(self:getSprite(), self:getQuad(), ...) +end + +-- Animation updating. +function Animated:update(dt) self.delay = self.delay - dt if self.delay < 0 then self.delay = self.delay + Animated.delay -- INITIAL from metatable self:nextFrame() end end - --- nextFrame(self) +-- Moving to the next frame. function Animated:nextFrame() if self.current.repeated or not (self.frame == self.current.frames) then self.frame = (self.frame % self.current.frames) + 1 else - self:setAnimation("idle") + self:setAnimation("default") end end \ No newline at end of file diff --git a/animations.lua b/animations.lua index 58c4b88..881da49 100644 --- a/animations.lua +++ b/animations.lua @@ -1,8 +1,8 @@ -- 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 +-- From the left: default (walk0), walk1, walk2, walk3, attack0, attack1, attack3, attack_up0, attack_up1, attack_up2, attack_down0, attack_down1, attack_down2, damage0, damage1 local animations = { - idle = { + default = { [1] = love.graphics.newQuad( 1, 1, 24,24, 376,26), frames = 1, repeated = true diff --git a/player.lua b/player.lua index b3ce86f..66eb818 100644 --- a/player.lua +++ b/player.lua @@ -40,7 +40,9 @@ Player = { portrait_sheet = require "nautsicons", portrait_box = love.graphics.newQuad( 0, 15, 32,32, 80,130), -- Sounds - sfx = require "sounds" + sfx = require "sounds", + -- Animations table + animations = require "animations" } Player.__index = Player setmetatable(Player, Animated) @@ -63,11 +65,11 @@ function Player:new (game, world, x, y, name) o.body:setFixedRotation(true) -- Misc o.name = name or "empty" - o.sprite = newImage("assets/nauts/"..o.name..".png") + o:setSprite(newImage("assets/nauts/"..o.name..".png")) o.world = game o.punchcd = 0 -- Animation - o.current = o.animations.idle + o.current = o.animations.default o:createEffect("respawn") -- Portrait load for first object created if self.portrait_sprite == nil then @@ -108,7 +110,7 @@ function Player:update(dt) end -- Salto - if self.salto and (self.current == self.animations.walk or self.current == self.animations.idle) then + if self.salto and (self.current == self.animations.walk or self.current == self.animations.default) then self.rotate = (self.rotate + 17 * dt * self.facing) % 360 elseif self.rotate ~= 0 then self.rotate = 0 @@ -151,7 +153,7 @@ function Player:update(dt) end end - self:animate(dt) + Animated.update(self, dt) -- # DEATH -- We all die in the end. @@ -224,7 +226,7 @@ function Player:controlpressed(set, action, key) if (self.current == self.animations.attack) or (self.current == self.animations.attack_up) or (self.current == self.animations.attack_down) then - self:setAnimation("idle") + self:setAnimation("default") end -- Remove jump self.jumpnumber = self.jumpnumber - 1 @@ -283,7 +285,7 @@ function Player:controlreleased(set, action, key) (isDown(controlset, "left") or isDown(controlset, "right")) and self.current == self.animations.walk then - self:setAnimation("idle") + self:setAnimation("default") end end @@ -302,7 +304,8 @@ function Player:draw(offset_x, offset_y, scale, debug) local draw_y = (math.floor(y) + offset_y) * scale -- sprite draw love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, self.current[self.frame], draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15) + Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15) + --love.graphics.draw(self:getSprite(), self:getQuad(), draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15) -- debug draw if debug then for _,fixture in pairs(self.body:getFixtureList()) do @@ -342,7 +345,7 @@ function Player:drawHUD(x,y,scale,elevation) end -- Change animation of `Player` --- idle, walk, attack, attack_up, attack_down, damage +-- default, walk, attack, attack_up, attack_down, damage function Player:nextFrame() local isDown = Controller.isDown local controlset = self:getControlSet() @@ -352,7 +355,7 @@ function Player:nextFrame() -- If nonrepeatable animation is finished and player is walking self:setAnimation("walk") elseif self.current == self.animations.damage then - self:setAnimation("idle") + self:setAnimation("default") end end -- cgit v1.1 From 4b2f70d89a53ab03361a51cf970cede2e53cb3f6 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 12:29:40 +0100 Subject: Clean-ups in Player-Animated relations --- animated.lua | 12 ++++++++++-- player.lua | 11 +---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/animated.lua b/animated.lua index 236b68d..49fcbfa 100644 --- a/animated.lua +++ b/animated.lua @@ -11,6 +11,11 @@ Animated = { } Animated.__index = Animated +-- Cleans up reference to sprite on deletion. +function Animated:delete() + self.sprite = nil +end + -- Sets an Image as a sprite. function Animated:setSprite(image) self.sprite = image @@ -38,9 +43,12 @@ end -- Drawing self to LOVE2D buffer. function Animated:draw(...) - love.graphics.draw(self:getSprite(), self:getQuad(), ...) + local s, q = self:getSprite(), self:getQuad() + if s and q then + love.graphics.setColor(255,255,255,255) + love.graphics.draw(s, q, ...) + end end - -- Animation updating. function Animated:update(dt) self.delay = self.delay - dt diff --git a/player.lua b/player.lua index 66eb818..b6d4e3f 100644 --- a/player.lua +++ b/player.lua @@ -52,7 +52,6 @@ function Player:new (game, world, x, y, name) -- Meta local o = {} setmetatable(o, self) - self.__index = self -- Physics local group = -1-#game.Nauts o.body = love.physics.newBody(world, x, y, "dynamic") @@ -79,12 +78,6 @@ function Player:new (game, world, x, y, name) return o end --- Destructor of `Player` -function Player:delete() - -- body deletion is handled by world deletion - self.sprite = nil -end - -- Control set managment function Player:assignControlSet(set) self.controlset = set @@ -303,9 +296,7 @@ function Player:draw(offset_x, offset_y, scale, debug) local draw_x = (math.floor(x) + offset_x) * scale local draw_y = (math.floor(y) + offset_y) * scale -- sprite draw - love.graphics.setColor(255,255,255,255) - Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15) - --love.graphics.draw(self:getSprite(), self:getQuad(), draw_x, draw_y, self.rotate, self.facing*scale, 1*scale, 12, 15) + Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15) -- debug draw if debug then for _,fixture in pairs(self.body:getFixtureList()) do -- cgit v1.1 From 29a527f4dbfeae138b71ce2dd8a82aa40560c522 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 13:09:03 +0100 Subject: Added behaviours for non-animated instances --- animated.lua | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/animated.lua b/animated.lua index 49fcbfa..de16195 100644 --- a/animated.lua +++ b/animated.lua @@ -25,6 +25,12 @@ function Animated:getSprite() return self.sprite end +-- Sets new animations list. +function Animated:setAnimationsList(t) + self.animations = t + self:setAnimation("default") +end + -- Sets current animation by table key. function Animated:setAnimation(animation) self.frame = 1 @@ -38,23 +44,29 @@ end -- Get frame quad for drawing. function Animated:getQuad() - return self.current[self.frame] + if self.animations and self.current then + return self.current[self.frame] + end end -- Drawing self to LOVE2D buffer. +-- If there is no Quad, it will draw entire sprite. function Animated:draw(...) local s, q = self:getSprite(), self:getQuad() - if s and q then + if s then love.graphics.setColor(255,255,255,255) - love.graphics.draw(s, q, ...) + if q then love.graphics.draw(s, q, ...) + else love.graphics.draw(s, ...) end end end -- Animation updating. function Animated:update(dt) - self.delay = self.delay - dt - if self.delay < 0 then - self.delay = self.delay + Animated.delay -- INITIAL from metatable - self:nextFrame() + if self.animations and self.current then + self.delay = self.delay - dt + if self.delay < 0 then + self.delay = self.delay + Animated.delay -- INITIAL from metatable + self:nextFrame() + end end end -- Moving to the next frame. -- cgit v1.1 From 4d3ccfdd00bdbcd144dd8d283e1d0d4e150bd9f1 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 13:09:32 +0100 Subject: Metatable of Animated for Decoration and Ground --- decoration.lua | 3 +-- ground.lua | 17 ++++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/decoration.lua b/decoration.lua index 9552b09..609983a 100644 --- a/decoration.lua +++ b/decoration.lua @@ -28,6 +28,5 @@ function Decoration:draw(offset_x, offset_y, scale) local draw_x = (math.floor(x) + offset_x) * scale local draw_y = (math.floor(y) + offset_y) * scale -- draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, draw_x, draw_y, 0, scale, scale) + Animated.draw(self, draw_x, draw_y, 0, scale, scale) end \ No newline at end of file diff --git a/ground.lua b/ground.lua index cd2b607..50ded4f 100644 --- a/ground.lua +++ b/ground.lua @@ -3,6 +3,7 @@ -- Collision category: [1] -- WHOLE CODE HAS FLAG OF "need a cleanup" +require "animated" -- Metatable of `Ground` -- nils initialized in constructor @@ -11,13 +12,14 @@ Ground = { shape = nil, fixture = nil, world = nil, - sprite = nil } +Ground.__index = Ground +setmetatable(Ground, Animated) + -- Constructor of `Ground` function Ground:new (game, world, x, y, shape, sprite) local o = {} setmetatable(o, self) - self.__index = self o.body = love.physics.newBody(world, x, y) -- MULTIPLE SHAPES NEED TO BE REWRITED! o.shape = {} @@ -37,17 +39,11 @@ function Ground:new (game, world, x, y, shape, sprite) end end -- END HERE - o.sprite = love.graphics.newImage(sprite) + o:setSprite(love.graphics.newImage(sprite)) o.world = game return o end --- Destructor of `Ground` -function Ground:delete () - -- body deletion is handled by world deletion - self.sprite = nil -end - -- Position function Ground:getPosition() return self.body:getPosition() @@ -65,8 +61,7 @@ function Ground:draw (offset_x, offset_y, scale, debug) local draw_x = (math.floor(x) + offset_x) * scale local draw_y = (math.floor(y) + offset_y) * scale -- sprite draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, draw_x, draw_y, 0, scale, scale) + Animated.draw(self, draw_x, draw_y, 0, scale, scale) -- debug draw if debug then love.graphics.setColor(255, 69, 0, 140) -- cgit v1.1 From 7b757c58f110a577ae4a24308a2e540731ab7211 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 13:09:53 +0100 Subject: Updating Decorations and Grounds --- world.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/world.lua b/world.lua index b01948e..e594c32 100644 --- a/world.lua +++ b/world.lua @@ -231,10 +231,16 @@ function World:update(dt) self.world:update(dt) -- Camera self.camera:update(dt) - -- Nauts + -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) for _,naut in pairs(self.Nauts) do naut:update(dt) end + for _,platform in pairs(self.Platforms) do + platform:update(dt) + end + for _,decoration in pairs(self.Decorations) do + decoration:update(dt) + end -- Clouds if self.map.clouds then -- generator -- cgit v1.1 From 444eaa53c31704186cf38dbadfab1a5f014b78b4 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 13:12:27 +0100 Subject: Decoration < Animated --- decoration.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/decoration.lua b/decoration.lua index 609983a..3ca6f76 100644 --- a/decoration.lua +++ b/decoration.lua @@ -4,10 +4,11 @@ Decoration = { x = 0, y = 0 } +Decoration.__index = Decoration +setmetatable(Decoration, Animated) function Decoration:new(x, y, sprite) local o = {} setmetatable(o, self) - self.__index = self o.sprite = love.graphics.newImage(sprite) o:setPosition(x,y) return o -- cgit v1.1 From ff957be7d38a3143aa89a798184a975af00998bc Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 14:24:50 +0100 Subject: Animated platform test for Abyss small --- animated.lua | 6 ++++-- assets/platforms/alpha-small-1.png | Bin 351 -> 0 bytes assets/platforms/alpha-small.png | Bin 0 -> 821 bytes ground.lua | 3 ++- maps/alpha abyss.lua | 25 ++++++++++++++++++++++--- world.lua | 6 +++--- 6 files changed, 31 insertions(+), 9 deletions(-) delete mode 100644 assets/platforms/alpha-small-1.png create mode 100644 assets/platforms/alpha-small.png diff --git a/animated.lua b/animated.lua index de16195..160ee44 100644 --- a/animated.lua +++ b/animated.lua @@ -27,8 +27,10 @@ end -- Sets new animations list. function Animated:setAnimationsList(t) - self.animations = t - self:setAnimation("default") + if t then + self.animations = t + self:setAnimation("default") + end end -- Sets current animation by table key. diff --git a/assets/platforms/alpha-small-1.png b/assets/platforms/alpha-small-1.png deleted file mode 100644 index b3f1a01..0000000 Binary files a/assets/platforms/alpha-small-1.png and /dev/null differ diff --git a/assets/platforms/alpha-small.png b/assets/platforms/alpha-small.png new file mode 100644 index 0000000..cce324f Binary files /dev/null and b/assets/platforms/alpha-small.png differ diff --git a/ground.lua b/ground.lua index 50ded4f..1318c11 100644 --- a/ground.lua +++ b/ground.lua @@ -17,7 +17,7 @@ Ground.__index = Ground setmetatable(Ground, Animated) -- Constructor of `Ground` -function Ground:new (game, world, x, y, shape, sprite) +function Ground:new (game, world, x, y, shape, sprite, animations) local o = {} setmetatable(o, self) o.body = love.physics.newBody(world, x, y) @@ -40,6 +40,7 @@ function Ground:new (game, world, x, y, shape, sprite) end -- END HERE o:setSprite(love.graphics.newImage(sprite)) + o:setAnimationsList(animations) o.world = game return o end diff --git a/maps/alpha abyss.lua b/maps/alpha abyss.lua index a3b6153..2df6adc 100644 --- a/maps/alpha abyss.lua +++ b/maps/alpha abyss.lua @@ -1,4 +1,20 @@ -- The abyss of the alpha. +local animations_small = { + default = { + [1] = love.graphics.newQuad(0, 0, 60,20, 600,20), + [2] = love.graphics.newQuad(60, 0, 60,20, 600,20), + [3] = love.graphics.newQuad(120, 0, 60,20, 600,20), + [4] = love.graphics.newQuad(180, 0, 60,20, 600,20), + [5] = love.graphics.newQuad(240, 0, 60,20, 600,20), + [6] = love.graphics.newQuad(300, 0, 60,20, 600,20), + [7] = love.graphics.newQuad(360, 0, 60,20, 600,20), + [8] = love.graphics.newQuad(420, 0, 60,20, 600,20), + [9] = love.graphics.newQuad(480, 0, 60,20, 600,20), + [10] = love.graphics.newQuad(540, 0, 60,20, 600,20), + frames = 10, + repeated = true + } +} return { -- GENERAL name = "alpha abyss", @@ -30,19 +46,22 @@ return { x = -145, y = -50, shape = {0,0, 59,0, 59,19, 0,19}, - sprite = "assets/platforms/alpha-small-1.png" + sprite = "assets/platforms/alpha-small.png", + animations = animations_small }, { x = 85, y = -50, shape = {0,0, 59,0, 59,19, 0,19}, - sprite = "assets/platforms/alpha-small-1.png" + sprite = "assets/platforms/alpha-small.png", + animations = animations_small }, { x = -30, y = -80, shape = {0,0, 59,0, 59,19, 0,19}, - sprite = "assets/platforms/alpha-small-1.png" + sprite = "assets/platforms/alpha-small.png", + animations = animations_small } }, decorations = {} diff --git a/world.lua b/world.lua index e594c32..30359fd 100644 --- a/world.lua +++ b/world.lua @@ -93,7 +93,7 @@ function World:loadMap(name) self.map = map() -- Platforms for _,platform in pairs(self.map.platforms) do - self:createPlatform(platform.x, platform.y, platform.shape, platform.sprite) + self:createPlatform(platform.x, platform.y, platform.shape, platform.sprite, platform.animations) end -- Decorations for _,decoration in pairs(self.map.decorations) do @@ -125,8 +125,8 @@ function World:getSpawnPosition() end -- Add new platform to the world -function World:createPlatform(x, y, polygon, sprite) - table.insert(self.Platforms, Ground:new(self, self.world, x, y, polygon, sprite)) +function World:createPlatform(x, y, polygon, sprite, animations) + table.insert(self.Platforms, Ground:new(self, self.world, x, y, polygon, sprite, animations)) end -- Add new naut to the world -- cgit v1.1 From f44ce392bc511fdfd24c54a5ee24b09f8ff6836f Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 20 Jan 2017 16:07:30 +0100 Subject: Big platform added and generating animation table --- assets/platforms/alpha-big-1.png | Bin 702 -> 0 bytes assets/platforms/alpha-big.png | Bin 0 -> 3836 bytes maps/alpha abyss.lua | 31 +++++++++++++++++++------------ 3 files changed, 19 insertions(+), 12 deletions(-) delete mode 100644 assets/platforms/alpha-big-1.png create mode 100644 assets/platforms/alpha-big.png diff --git a/assets/platforms/alpha-big-1.png b/assets/platforms/alpha-big-1.png deleted file mode 100644 index 6500f73..0000000 Binary files a/assets/platforms/alpha-big-1.png and /dev/null differ diff --git a/assets/platforms/alpha-big.png b/assets/platforms/alpha-big.png new file mode 100644 index 0000000..3397022 Binary files /dev/null and b/assets/platforms/alpha-big.png differ diff --git a/maps/alpha abyss.lua b/maps/alpha abyss.lua index 2df6adc..0dd2c61 100644 --- a/maps/alpha abyss.lua +++ b/maps/alpha abyss.lua @@ -1,20 +1,26 @@ -- The abyss of the alpha. +-- Animations local animations_small = { default = { - [1] = love.graphics.newQuad(0, 0, 60,20, 600,20), - [2] = love.graphics.newQuad(60, 0, 60,20, 600,20), - [3] = love.graphics.newQuad(120, 0, 60,20, 600,20), - [4] = love.graphics.newQuad(180, 0, 60,20, 600,20), - [5] = love.graphics.newQuad(240, 0, 60,20, 600,20), - [6] = love.graphics.newQuad(300, 0, 60,20, 600,20), - [7] = love.graphics.newQuad(360, 0, 60,20, 600,20), - [8] = love.graphics.newQuad(420, 0, 60,20, 600,20), - [9] = love.graphics.newQuad(480, 0, 60,20, 600,20), - [10] = love.graphics.newQuad(540, 0, 60,20, 600,20), - frames = 10, + frames = 20, repeated = true } } +local animations_big = { + default = { + frames = 20, + repeated = true + } +} +for i=1,10 do + local a = love.graphics.newQuad(i*118-118, 0, 118,51, 1180,51) + animations_big.default[i*2-1] = a + animations_big.default[i*2] = a + local a = love.graphics.newQuad(i*60-60, 0, 60,20, 600,20) + animations_small.default[i*2-1] = a + animations_small.default[i*2] = a +end +-- Map data return { -- GENERAL name = "alpha abyss", @@ -40,7 +46,8 @@ return { x = -60, y = 0, shape = {0,0, 117,0, 101,50, 16,50}, - sprite = "assets/platforms/alpha-big-1.png" + sprite = "assets/platforms/alpha-big.png", + animations = animations_big }, { x = -145, -- cgit v1.1