From 46c1a53f5e8e616f48a1fee375a8721929043fe8 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 26 Jan 2020 12:28:53 +0100 Subject: [PATCH] feat:initial addition of collectible actors --- .../game/modules/world/actors/init.lua | 5 +++++ .../modules/world/actors/items/collectible.lua | 12 ++++++++++++ .../game/modules/world/actors/items/ring.lua | 17 +++++++++++++++++ .../game/modules/world/actors/player.lua | 6 ++++++ .../game/modules/world/maps/shoot.lua | 1 + .../game/modules/world/maps/tools/chunk.lua | 11 +++++++++++ .../game/modules/world/parent.lua | 4 ++++ 7 files changed, 56 insertions(+) create mode 100644 sonic-bluestreak.love/game/modules/world/actors/items/collectible.lua create mode 100644 sonic-bluestreak.love/game/modules/world/actors/items/ring.lua diff --git a/sonic-bluestreak.love/game/modules/world/actors/init.lua b/sonic-bluestreak.love/game/modules/world/actors/init.lua index 2039495..a373d68 100644 --- a/sonic-bluestreak.love/game/modules/world/actors/init.lua +++ b/sonic-bluestreak.love/game/modules/world/actors/init.lua @@ -3,6 +3,7 @@ local Obj = {} -- On charge toutes les différentes types d'acteurs local cwd = (...):gsub('%.init$', '') .. "." Obj.Player = require(cwd .. "player") +Obj.Ring = require(cwd .. "items.ring") Obj.index = {} Obj.index["player"] = Obj.Player @@ -13,4 +14,8 @@ Obj.collisions["invisible"] = require(cwd .. "collisions.invisible") Obj.collisions["floor"] = require(cwd .. "collisions.floor") Obj.collisions["textured"] = require(cwd .. "collisions.textured") +Obj.index = {} +Obj.index[01] = Obj.Ring +Obj.index[02] = Obj.Ring + return Obj diff --git a/sonic-bluestreak.love/game/modules/world/actors/items/collectible.lua b/sonic-bluestreak.love/game/modules/world/actors/items/collectible.lua new file mode 100644 index 0000000..c09c971 --- /dev/null +++ b/sonic-bluestreak.love/game/modules/world/actors/items/collectible.lua @@ -0,0 +1,12 @@ +local Parent = require "game.modules.world.actors.parent" +local Collectible = Parent:extend() + +function Collectible:new(world, x, y, z, w, h, d) + Collectible.super.new(self, world, "collectible", x, y, z, w, h, d, false) +end + +function Collectible:getPicked(player) + self:destroy() +end + +return Collectible diff --git a/sonic-bluestreak.love/game/modules/world/actors/items/ring.lua b/sonic-bluestreak.love/game/modules/world/actors/items/ring.lua new file mode 100644 index 0000000..9b6d572 --- /dev/null +++ b/sonic-bluestreak.love/game/modules/world/actors/items/ring.lua @@ -0,0 +1,17 @@ +local cwd = (...):gsub('%.ring$', '') .. "." +local Collectible = require(cwd .. "collectible") +local Ring = Collectible:extend() + +function Ring:new(world, x, y, z) + Ring.super.new(self, world, x, y, z+6, 16, 10, 16) + self:setSprite("ring", 0, 0) +end + +function Ring:getPicked(player) + --player.rings = player.rings + 1 + --player:addScore(10) + + self:destroy() +end + +return Ring diff --git a/sonic-bluestreak.love/game/modules/world/actors/player.lua b/sonic-bluestreak.love/game/modules/world/actors/player.lua index 44eebb8..94c6d4a 100644 --- a/sonic-bluestreak.love/game/modules/world/actors/player.lua +++ b/sonic-bluestreak.love/game/modules/world/actors/player.lua @@ -50,6 +50,12 @@ function Player:updateStart(dt) end end +function Player:collisionResponse(collision) + if collision.other.type == "collectible" then + collision.other.owner:getPicked(self) + end +end + function Player:animationEnded(name) end diff --git a/sonic-bluestreak.love/game/modules/world/maps/shoot.lua b/sonic-bluestreak.love/game/modules/world/maps/shoot.lua index b95a801..21f5d9d 100644 --- a/sonic-bluestreak.love/game/modules/world/maps/shoot.lua +++ b/sonic-bluestreak.love/game/modules/world/maps/shoot.lua @@ -52,6 +52,7 @@ function ShootMap:loadCollisions() --self.world:newCollision("floor", 0, 0, -16, w, h, 16) for i, chunk in ipairs(self.layout) do chunk:spawnGrounds((i-1)*31*8) + chunk:spawnObjects((i-1)*31*8) end end diff --git a/sonic-bluestreak.love/game/modules/world/maps/tools/chunk.lua b/sonic-bluestreak.love/game/modules/world/maps/tools/chunk.lua index fb316ff..ecb304e 100644 --- a/sonic-bluestreak.love/game/modules/world/maps/tools/chunk.lua +++ b/sonic-bluestreak.love/game/modules/world/maps/tools/chunk.lua @@ -29,6 +29,17 @@ function Chunk:spawnGrounds(x) end end +function Chunk:spawnObjects(x) + for i=1, 5 do + for j=1, 8 do + local id = self.data.objects[i][j] + if (id ~= 0) then + self.map.world:newObjFromIndex(id, x+(j-1)*31+12, (i-1)*20, 0) + end + end + end +end + function Chunk:draw(x) for i=1, 5 do for j=1, 8 do diff --git a/sonic-bluestreak.love/game/modules/world/parent.lua b/sonic-bluestreak.love/game/modules/world/parent.lua index 85ae9d5..f8cea6c 100644 --- a/sonic-bluestreak.love/game/modules/world/parent.lua +++ b/sonic-bluestreak.love/game/modules/world/parent.lua @@ -21,6 +21,10 @@ function ParentWorld:loadMapObjects() self:addInvisibleWalls() end +function ParentWorld:newObjFromIndex(id, x, y, z) + self.obj.index[id](self, x, y, z) +end + function ParentWorld:addInvisibleWalls() local w, h = self:getDimensions() print(w, h)