From ea5011642c6c732fde927bdb86b27b10cbf56483 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Thu, 25 Apr 2019 17:54:51 +0200 Subject: [PATCH] modules/world: add a basic solidity system It'll make easier the solidity system and will reserve custom filter to specific objects. --- examples/gameplay/moveplayer/actors/parent.lua | 4 ++-- examples/gameplay/moveplayer/actors/player.lua | 2 +- gamecore/modules/world/actors/actor2D.lua | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/gameplay/moveplayer/actors/parent.lua b/examples/gameplay/moveplayer/actors/parent.lua index cd03b5e..502d7b6 100644 --- a/examples/gameplay/moveplayer/actors/parent.lua +++ b/examples/gameplay/moveplayer/actors/parent.lua @@ -1,9 +1,9 @@ local Base = require "gamecore.modules.world.actors.actor2D" local Parent = Base:extend() -function Parent:new(world, type, x, y, w, h) +function Parent:new(world, type, x, y, w, h, isSolid) self.scene = world.scene - Parent.super.new(self, world, type, x, y, w, h) + Parent.super.new(self, world, type, x, y, w, h, isSolid) end function Parent:draw() diff --git a/examples/gameplay/moveplayer/actors/player.lua b/examples/gameplay/moveplayer/actors/player.lua index 1a68bc2..ac6df46 100644 --- a/examples/gameplay/moveplayer/actors/player.lua +++ b/examples/gameplay/moveplayer/actors/player.lua @@ -3,7 +3,7 @@ local Parent = require(cwd .. "parent") local Player = Parent:extend() function Player:new(world, x, y) - Player.super.new(self, world, "player", x, y, 16, 16) + Player.super.new(self, world, "player", x, y, 16, 16, true) end function Player:update(dt) diff --git a/gamecore/modules/world/actors/actor2D.lua b/gamecore/modules/world/actors/actor2D.lua index 6465db6..e751c09 100644 --- a/gamecore/modules/world/actors/actor2D.lua +++ b/gamecore/modules/world/actors/actor2D.lua @@ -27,11 +27,11 @@ local Actor2D = Object:extend() -- INIT FUNCTIONS -- Initialise the actor and its base functions -function Actor2D:new(world, type, x, y, w, h) +function Actor2D:new(world, type, x, y, w, h, isSolid) self.type = type or "" self:setManagers(world) - self:initPhysics(x, y, w, h) + self:initPhysics(x, y, w, h, isSolid) self:initKeys() self:register() @@ -52,7 +52,7 @@ function Actor2D:setDebugColor(r,g,b) self.debug.b = b end -function Actor2D:initPhysics(x, y, w, h) +function Actor2D:initPhysics(x, y, w, h, isSolid) self.x = x or 0 self.y = y or 0 self.w = w or 0 @@ -61,6 +61,8 @@ function Actor2D:initPhysics(x, y, w, h) self.xsp = 0 self.ysp = 0 + self.isSolid = isSolid or false + self:setFilter() end @@ -93,7 +95,11 @@ end function Actor2D:setFilter() -- Init the bump filter self.filter = function(item, other) - return nil + if (other.isSolid) then + return "touch" + else + return "cross" + end end end