big-refactor #106
5 changed files with 18 additions and 31 deletions
|
@ -42,6 +42,7 @@ end
|
|||
|
||||
function Box:getShape()
|
||||
local x, y, z, w, h, d = self:getArea()
|
||||
return x, y-z-d, w, h+d
|
||||
end
|
||||
|
||||
function Box:getCorners()
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
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.
|
||||
]]
|
||||
local Rect = require "birb.classes.2D.rect"
|
||||
|
||||
local BaseActor = require "birb.modules.world.actors.mixins.base"
|
||||
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 PhysicalActor = require("birb.modules.world.actors.mixins.physics")
|
||||
|
||||
local Actor2D = Object:extend()
|
||||
local Actor2D = Rect:extend()
|
||||
Actor2D:implement(BaseActor)
|
||||
Actor2D:implement(SpritedActor)
|
||||
Actor2D:implement(TimedActor)
|
||||
|
@ -41,8 +42,10 @@ local Hitbox = require "birb.modules.world.actors.utils.hitbox2D"
|
|||
-- Initialise the actor and its base functions
|
||||
|
||||
function Actor2D:new(world, type, x, y, w, h, isSolid)
|
||||
Actor2D.super.new(self, x, y, w, h)
|
||||
|
||||
self:init(world, type)
|
||||
self:initPhysics(Hitbox, x, y, 0, w, h, 0, isSolid)
|
||||
self:initPhysics(Hitbox, isSolid)
|
||||
self:initTimers()
|
||||
self:initSprite()
|
||||
self:initKeys()
|
||||
|
@ -137,10 +140,6 @@ end
|
|||
-- DRAW FUNCTIONS
|
||||
-- Draw the actors.
|
||||
|
||||
function Actor2D:getShape()
|
||||
return (self.x), (self.y), self.w, (self.h)
|
||||
end
|
||||
|
||||
function Actor2D:draw()
|
||||
self:drawStart()
|
||||
local x, y = math.floor(self.x), math.floor(self.y)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
local Hitbox = require("birb.modules.world.actors.utils.hitbox3D")
|
||||
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 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 Shape3DActor = require("birb.modules.world.actors.mixins.shapes")
|
||||
|
||||
local Actor3D = Object:extend()
|
||||
local Actor3D = BasicBox:extend()
|
||||
Actor3D:implement(BaseActor)
|
||||
Actor3D:implement(SpritedActor)
|
||||
Actor3D:implement(TimedActor)
|
||||
|
@ -44,8 +45,9 @@ Actor3D:implement(Shape3DActor)
|
|||
-- Initialise the actor and its base functions
|
||||
|
||||
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:initPhysics(Hitbox, x, y, z, w, h, d, isSolid)
|
||||
self:initPhysics(Hitbox, isSolid)
|
||||
self:initTimers()
|
||||
self:initSprite()
|
||||
self:initKeys()
|
||||
|
@ -161,10 +163,6 @@ function Actor3D:drawShadow(x, y)
|
|||
utils.graphics.resetColor()
|
||||
end
|
||||
|
||||
function Actor3D:getShape()
|
||||
return (self.x), (self.y - self.z - self.d), self.w, (self.h + self.d)
|
||||
end
|
||||
|
||||
function Actor3D:draw()
|
||||
self:drawStart()
|
||||
if (self.box ~= nil) then
|
||||
|
|
|
@ -3,15 +3,9 @@ PhysicalActor = Object:extend()
|
|||
-- PHYSICS FUNCTIONS
|
||||
-- Raw implementation of everything common in physics
|
||||
|
||||
function PhysicalActor:initPhysics(hitboxObj, x, y, z, w, h, d, isSolid)
|
||||
self:setCoordinate(x, y, z)
|
||||
|
||||
function PhysicalActor:initPhysics(hitboxObj, isSolid)
|
||||
self.isSolid = isSolid or false
|
||||
|
||||
self.w = w or 0
|
||||
self.h = h or 0
|
||||
self.d = d or 0
|
||||
|
||||
self.xsp = 0
|
||||
self.ysp = 0
|
||||
self.zsp = 0
|
||||
|
@ -29,12 +23,6 @@ function PhysicalActor:initPhysics(hitboxObj, x, y, z, w, h, d, isSolid)
|
|||
self:addUpdateFunction(self.autoMove)
|
||||
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)
|
||||
self.bounceFactor = newBounceFactor or 0
|
||||
end
|
||||
|
@ -57,7 +45,9 @@ function PhysicalActor:getFuturePosition(dt)
|
|||
local dx, dy, dz
|
||||
dx = self.x + self.xsp * dt
|
||||
dy = self.y + self.ysp * dt
|
||||
dz = self.z + self.zsp * dt
|
||||
if (self.z ~= nil) then
|
||||
dz = self.z + self.zsp * dt
|
||||
end
|
||||
|
||||
return dx, dy, dz
|
||||
end
|
||||
|
@ -65,7 +55,9 @@ end
|
|||
function PhysicalActor:applyFriction(dt)
|
||||
self.xsp = utils.math.toZero(self.xsp, self.xfrc * dt)
|
||||
self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
|
||||
self.zsp = utils.math.toZero(self.zsp, self.zfrc * dt)
|
||||
if (self.z ~= nil) then
|
||||
self.zsp = utils.math.toZero(self.zsp, self.zfrc * dt)
|
||||
end
|
||||
end
|
||||
|
||||
function PhysicalActor:solveAllCollisions(cols)
|
||||
|
@ -89,10 +81,6 @@ end
|
|||
-- Handle coordinate
|
||||
-- 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()
|
||||
return self:getCenter()
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ local Parent = Base:extend()
|
|||
|
||||
function Parent:new(world, type, x, y, w, h, isSolid)
|
||||
self.scene = world.scene
|
||||
self.z = 0
|
||||
Parent.super.new(self, world, type, x, y, w, h, isSolid)
|
||||
self:initCharset()
|
||||
self.drawDebugBox = false
|
||||
|
|
Loading…
Reference in a new issue