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:
parent
75eb198450
commit
ea5011642c
3 changed files with 13 additions and 7 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue