modules/world: add a basic solidity system

It'll make easier the solidity system and will reserve custom filter to 
specific objects.
This commit is contained in:
Kazhnuz 2019-04-25 17:54:51 +02:00
parent 75eb198450
commit ea5011642c
3 changed files with 13 additions and 7 deletions

View file

@ -1,9 +1,9 @@
local Base = require "gamecore.modules.world.actors.actor2D" local Base = require "gamecore.modules.world.actors.actor2D"
local Parent = Base:extend() 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 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 end
function Parent:draw() function Parent:draw()

View file

@ -3,7 +3,7 @@ local Parent = require(cwd .. "parent")
local Player = Parent:extend() local Player = Parent:extend()
function Player:new(world, x, y) 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 end
function Player:update(dt) function Player:update(dt)

View file

@ -27,11 +27,11 @@ local Actor2D = Object:extend()
-- INIT FUNCTIONS -- INIT FUNCTIONS
-- Initialise the actor and its base 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.type = type or ""
self:setManagers(world) self:setManagers(world)
self:initPhysics(x, y, w, h) self:initPhysics(x, y, w, h, isSolid)
self:initKeys() self:initKeys()
self:register() self:register()
@ -52,7 +52,7 @@ function Actor2D:setDebugColor(r,g,b)
self.debug.b = b self.debug.b = b
end end
function Actor2D:initPhysics(x, y, w, h) function Actor2D:initPhysics(x, y, w, h, isSolid)
self.x = x or 0 self.x = x or 0
self.y = y or 0 self.y = y or 0
self.w = w or 0 self.w = w or 0
@ -61,6 +61,8 @@ function Actor2D:initPhysics(x, y, w, h)
self.xsp = 0 self.xsp = 0
self.ysp = 0 self.ysp = 0
self.isSolid = isSolid or false
self:setFilter() self:setFilter()
end end
@ -93,7 +95,11 @@ end
function Actor2D:setFilter() function Actor2D:setFilter()
-- Init the bump filter -- Init the bump filter
self.filter = function(item, other) self.filter = function(item, other)
return nil if (other.isSolid) then
return "touch"
else
return "cross"
end
end end
end end