chore: port actors to rect and box

This commit is contained in:
Kazhnuz 2021-05-07 19:23:34 +02:00
parent 05a8b71180
commit ff8cd856fd
5 changed files with 18 additions and 31 deletions

View file

@ -42,6 +42,7 @@ end
function Box:getShape() function Box:getShape()
local x, y, z, w, h, d = self:getArea() local x, y, z, w, h, d = self:getArea()
return x, y-z-d, w, h+d
end end
function Box:getCorners() function Box:getCorners()

View file

@ -21,6 +21,7 @@
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
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.classes.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")
@ -28,7 +29,7 @@ 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 +42,10 @@ 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()
@ -137,10 +140,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)

View file

@ -24,6 +24,7 @@
local Hitbox = require("birb.modules.world.actors.utils.hitbox3D") local Hitbox = require("birb.modules.world.actors.utils.hitbox3D")
local Boxes = require("birb.modules.world.actors.utils.boxes") local Boxes = require("birb.modules.world.actors.utils.boxes")
local BasicBox = require "birb.classes.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")
@ -32,7 +33,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)
@ -44,8 +45,9 @@ Actor3D:implement(Shape3DActor)
-- 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:initKeys() self:initKeys()
@ -161,10 +163,6 @@ function Actor3D:drawShadow(x, y)
utils.graphics.resetColor() utils.graphics.resetColor()
end end
function Actor3D:getShape()
return (self.x), (self.y - self.z - self.d), self.w, (self.h + self.d)
end
function Actor3D:draw() function Actor3D:draw()
self:drawStart() self:drawStart()
if (self.box ~= nil) then if (self.box ~= nil) then

View file

@ -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

View file

@ -3,6 +3,7 @@ local Parent = Base:extend()
function Parent:new(world, type, x, y, w, h, isSolid) function Parent:new(world, type, x, y, w, h, isSolid)
self.scene = world.scene self.scene = world.scene
self.z = 0
Parent.super.new(self, world, type, x, y, w, h, isSolid) Parent.super.new(self, world, type, x, y, w, h, isSolid)
self:initCharset() self:initCharset()
self.drawDebugBox = false self.drawDebugBox = false