chore: port actors to rect and box
This commit is contained in:
parent
82cf59588a
commit
4b66d15014
3 changed files with 19 additions and 30 deletions
|
@ -22,13 +22,15 @@
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local Rect = require "birb.objects.2D.rect"
|
||||||
|
|
||||||
local BaseActor = require("birb.modules.world.actors.mixins.base")
|
local BaseActor = require("birb.modules.world.actors.mixins.base")
|
||||||
local SpritedActor = require("birb.modules.world.actors.mixins.sprites")
|
local SpritedActor = require("birb.modules.world.actors.mixins.sprites")
|
||||||
local TimedActor = require("birb.modules.world.actors.mixins.timers")
|
local TimedActor = require("birb.modules.world.actors.mixins.timers")
|
||||||
local InputActor = require("birb.modules.world.actors.mixins.inputs")
|
local InputActor = require("birb.modules.world.actors.mixins.inputs")
|
||||||
local PhysicalActor = require("birb.modules.world.actors.mixins.physics")
|
local PhysicalActor = require("birb.modules.world.actors.mixins.physics")
|
||||||
|
|
||||||
local Actor2D = Object:extend()
|
local Actor2D = Rect:extend()
|
||||||
Actor2D:implement(BaseActor)
|
Actor2D:implement(BaseActor)
|
||||||
Actor2D:implement(SpritedActor)
|
Actor2D:implement(SpritedActor)
|
||||||
Actor2D:implement(TimedActor)
|
Actor2D:implement(TimedActor)
|
||||||
|
@ -41,8 +43,9 @@ local Hitbox = require("birb.modules.world.actors.utils.hitbox2D")
|
||||||
-- Initialise the actor and its base functions
|
-- Initialise the actor and its base functions
|
||||||
|
|
||||||
function Actor2D:new(world, type, x, y, w, h, isSolid)
|
function Actor2D:new(world, type, x, y, w, h, isSolid)
|
||||||
|
Actor2D.super.new(self, x, y, w, h)
|
||||||
self:init(world, type)
|
self:init(world, type)
|
||||||
self:initPhysics(Hitbox, x, y, 0, w, h, 0, isSolid)
|
self:initPhysics(Hitbox, isSolid)
|
||||||
self:initTimers()
|
self:initTimers()
|
||||||
self:initSprite()
|
self:initSprite()
|
||||||
self:initKeys()
|
self:initKeys()
|
||||||
|
@ -134,10 +137,6 @@ end
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the actors.
|
-- Draw the actors.
|
||||||
|
|
||||||
function Actor2D:getShape()
|
|
||||||
return (self.x), (self.y), self.w, (self.h)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:draw()
|
function Actor2D:draw()
|
||||||
self:drawStart()
|
self:drawStart()
|
||||||
local x, y = math.floor(self.x), math.floor(self.y)
|
local x, y = math.floor(self.x), math.floor(self.y)
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local cwd = (...):gsub('%.actor3D$', '') .. "."
|
local BasicBox = require "birb.objects.3D.box"
|
||||||
|
|
||||||
local BaseActor = require("birb.modules.world.actors.mixins.base")
|
local BaseActor = require("birb.modules.world.actors.mixins.base")
|
||||||
local SpritedActor = require("birb.modules.world.actors.mixins.sprites")
|
local SpritedActor = require("birb.modules.world.actors.mixins.sprites")
|
||||||
local TimedActor = require("birb.modules.world.actors.mixins.timers")
|
local TimedActor = require("birb.modules.world.actors.mixins.timers")
|
||||||
|
@ -30,7 +31,7 @@ local InputActor = require("birb.modules.world.actors.mixins.inputs")
|
||||||
local PhysicalActor = require("birb.modules.world.actors.mixins.physics")
|
local PhysicalActor = require("birb.modules.world.actors.mixins.physics")
|
||||||
local Shape3DActor = require("birb.modules.world.actors.mixins.shapes")
|
local Shape3DActor = require("birb.modules.world.actors.mixins.shapes")
|
||||||
|
|
||||||
local Actor3D = Object:extend()
|
local Actor3D = BasicBox:extend()
|
||||||
Actor3D:implement(BaseActor)
|
Actor3D:implement(BaseActor)
|
||||||
Actor3D:implement(SpritedActor)
|
Actor3D:implement(SpritedActor)
|
||||||
Actor3D:implement(TimedActor)
|
Actor3D:implement(TimedActor)
|
||||||
|
@ -38,15 +39,16 @@ Actor3D:implement(InputActor)
|
||||||
Actor3D:implement(PhysicalActor)
|
Actor3D:implement(PhysicalActor)
|
||||||
Actor3D:implement(Shape3DActor)
|
Actor3D:implement(Shape3DActor)
|
||||||
|
|
||||||
local Hitbox = require(cwd .. "utils.hitbox3D")
|
local Hitbox = require("birb.modules.world.actors.utils.hitbox3D")
|
||||||
local Boxes = require(cwd .. "utils.boxes")
|
local Boxes = require("birb.modules.world.actors.utils.boxes")
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialise the actor and its base functions
|
-- Initialise the actor and its base functions
|
||||||
|
|
||||||
function Actor3D:new(world, type, x, y, z, w, h, d, isSolid)
|
function Actor3D:new(world, type, x, y, z, w, h, d, isSolid)
|
||||||
|
Actor3D.super.new(self, x, y, z, w, h, d)
|
||||||
self:init(world, type)
|
self:init(world, type)
|
||||||
self:initPhysics(Hitbox, x, y, z, w, h, d, isSolid)
|
self:initPhysics(Hitbox, isSolid)
|
||||||
self:initTimers()
|
self:initTimers()
|
||||||
self:initSprite()
|
self:initSprite()
|
||||||
self:initShape(Boxes, true)
|
self:initShape(Boxes, true)
|
||||||
|
|
|
@ -3,15 +3,9 @@ PhysicalActor = Object:extend()
|
||||||
-- PHYSICS FUNCTIONS
|
-- PHYSICS FUNCTIONS
|
||||||
-- Raw implementation of everything common in physics
|
-- Raw implementation of everything common in physics
|
||||||
|
|
||||||
function PhysicalActor:initPhysics(hitboxObj, x, y, z, w, h, d, isSolid)
|
function PhysicalActor:initPhysics(hitboxObj, isSolid)
|
||||||
self:setCoordinate(x, y, z)
|
|
||||||
|
|
||||||
self.isSolid = isSolid or false
|
self.isSolid = isSolid or false
|
||||||
|
|
||||||
self.w = w or 0
|
|
||||||
self.h = h or 0
|
|
||||||
self.d = d or 0
|
|
||||||
|
|
||||||
self.xsp = 0
|
self.xsp = 0
|
||||||
self.ysp = 0
|
self.ysp = 0
|
||||||
self.zsp = 0
|
self.zsp = 0
|
||||||
|
@ -29,12 +23,6 @@ function PhysicalActor:initPhysics(hitboxObj, x, y, z, w, h, d, isSolid)
|
||||||
self:addUpdateFunction(self.autoMove)
|
self:addUpdateFunction(self.autoMove)
|
||||||
end
|
end
|
||||||
|
|
||||||
function PhysicalActor:setCoordinate(x, y, z, w, h, d)
|
|
||||||
self.x = x or self.x
|
|
||||||
self.y = y or self.y
|
|
||||||
self.z = z or self.z
|
|
||||||
end
|
|
||||||
|
|
||||||
function PhysicalActor:setBounceFactor(newBounceFactor)
|
function PhysicalActor:setBounceFactor(newBounceFactor)
|
||||||
self.bounceFactor = newBounceFactor or 0
|
self.bounceFactor = newBounceFactor or 0
|
||||||
end
|
end
|
||||||
|
@ -57,7 +45,9 @@ function PhysicalActor:getFuturePosition(dt)
|
||||||
local dx, dy, dz
|
local dx, dy, dz
|
||||||
dx = self.x + self.xsp * dt
|
dx = self.x + self.xsp * dt
|
||||||
dy = self.y + self.ysp * dt
|
dy = self.y + self.ysp * dt
|
||||||
|
if (self.z ~= nil) then
|
||||||
dz = self.z + self.zsp * dt
|
dz = self.z + self.zsp * dt
|
||||||
|
end
|
||||||
|
|
||||||
return dx, dy, dz
|
return dx, dy, dz
|
||||||
end
|
end
|
||||||
|
@ -65,8 +55,10 @@ end
|
||||||
function PhysicalActor:applyFriction(dt)
|
function PhysicalActor:applyFriction(dt)
|
||||||
self.xsp = utils.math.toZero(self.xsp, self.xfrc * dt)
|
self.xsp = utils.math.toZero(self.xsp, self.xfrc * dt)
|
||||||
self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
|
self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
|
||||||
|
if (self.z ~= nil) then
|
||||||
self.zsp = utils.math.toZero(self.zsp, self.zfrc * dt)
|
self.zsp = utils.math.toZero(self.zsp, self.zfrc * dt)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function PhysicalActor:solveAllCollisions(cols)
|
function PhysicalActor:solveAllCollisions(cols)
|
||||||
for i, col in ipairs(cols) do
|
for i, col in ipairs(cols) do
|
||||||
|
@ -89,10 +81,6 @@ end
|
||||||
-- Handle coordinate
|
-- Handle coordinate
|
||||||
-- Will be replaced by functions inside Actors or Rects/Point
|
-- Will be replaced by functions inside Actors or Rects/Point
|
||||||
|
|
||||||
function PhysicalActor:getCenter()
|
|
||||||
return (self.x + (self.w / 2)), (self.y + (self.h / 2)), (self.z + (self.d / 2))
|
|
||||||
end
|
|
||||||
|
|
||||||
function PhysicalActor:getViewCenter()
|
function PhysicalActor:getViewCenter()
|
||||||
return self:getCenter()
|
return self:getCenter()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue