improvement(actor): merge most physics initialisation
This commit is contained in:
parent
049213000a
commit
10bbd5fd84
2 changed files with 50 additions and 45 deletions
|
@ -32,9 +32,8 @@ local Hitbox = require(cwd .. "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)
|
||||||
self:setCoordinate(x, y)
|
Actor2D.super.new(self, world, type, x, y, 0, w, h, 0, isSolid)
|
||||||
Actor2D.super.new(self, world, type, isSolid)
|
self:initHitboxes()
|
||||||
self:initHitboxes(w, h)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Actor2D:destroy()
|
function Actor2D:destroy()
|
||||||
|
@ -43,16 +42,8 @@ function Actor2D:destroy()
|
||||||
self.isDestroyed = true
|
self.isDestroyed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- MOVEMENT FUNCTIONS
|
-- PHYSICS FUNCTIONS
|
||||||
-- Basic functions from the movement.
|
-- Handle movement and collisions.
|
||||||
|
|
||||||
function Actor2D:initMovement()
|
|
||||||
self.xsp = 0
|
|
||||||
self.ysp = 0
|
|
||||||
|
|
||||||
self.xfrc = 0
|
|
||||||
self.yfrc = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:autoMove(dt)
|
function Actor2D:autoMove(dt)
|
||||||
self:updateHitboxes()
|
self:updateHitboxes()
|
||||||
|
@ -168,13 +159,18 @@ function Actor2D:checkGround()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- COORDINATE/MOVEMENT FUNCTIONS
|
||||||
|
-- Handle coordinate
|
||||||
|
|
||||||
|
function Actor2D:getViewCenter()
|
||||||
|
local x, y = self:getCenter()
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
|
||||||
-- HITBOXES FUNCTIONS
|
-- HITBOXES FUNCTIONS
|
||||||
-- Functions related to actor hitboxes
|
-- Functions related to actor hitboxes
|
||||||
|
|
||||||
function Actor2D:initHitboxes(w, h)
|
function Actor2D:initHitboxes()
|
||||||
self.w = w or 0
|
|
||||||
self.h = h or 0
|
|
||||||
|
|
||||||
self:initMainHitbox()
|
self:initMainHitbox()
|
||||||
|
|
||||||
self.hitboxes = {}
|
self.hitboxes = {}
|
||||||
|
@ -322,22 +318,6 @@ function Actor2D:drawMainHitbox()
|
||||||
self.mainHitbox:draw()
|
self.mainHitbox:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- COORDINATE FUNCTION
|
|
||||||
-- Handle the coordinate system
|
|
||||||
|
|
||||||
function Actor2D:setCoordinate(x, y)
|
|
||||||
self.x = x or self.x
|
|
||||||
self.y = y or self.y
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:getCenter()
|
|
||||||
return (self.x + (self.w / 2)), (self.y + (self.h / 2))
|
|
||||||
end
|
|
||||||
|
|
||||||
function Actor2D:getViewCenter()
|
|
||||||
return self:getCenter()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
-- Draw the actors.
|
-- Draw the actors.
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
-- actor2D.lua :: the global implementation of an actor. Basically, it abstract
|
-- BaseActor.lua :: the global implementation of an actor. Basically, it abstract
|
||||||
-- everything that isn't 2D or 3D related to the actor system.
|
-- everything that isn't only 2D or 3D related to the actor system.
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Copyright © 2019 Kazhnuz
|
Copyright © 2019 Kazhnuz
|
||||||
|
@ -30,7 +30,7 @@ local Timer = require(cwd .. "utils.timer")
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initialise the actor and its base functions
|
-- Initialise the actor and its base functions
|
||||||
|
|
||||||
function BaseActor:new(world, type, isSolid)
|
function BaseActor:new(world, type, x, y, z, w, h, d, isSolid)
|
||||||
self.type = type or ""
|
self.type = type or ""
|
||||||
self.isSolid = isSolid or false
|
self.isSolid = isSolid or false
|
||||||
self.depth = 0
|
self.depth = 0
|
||||||
|
@ -39,7 +39,7 @@ function BaseActor:new(world, type, isSolid)
|
||||||
self:initKeys()
|
self:initKeys()
|
||||||
self:initTimers()
|
self:initTimers()
|
||||||
self:setSprite()
|
self:setSprite()
|
||||||
self:initPhysics()
|
self:initPhysics(x, y, z, w, h, d)
|
||||||
|
|
||||||
self:setDebugColor(1, 1, 1)
|
self:setDebugColor(1, 1, 1)
|
||||||
self:register()
|
self:register()
|
||||||
|
@ -69,17 +69,36 @@ function BaseActor:destroy()
|
||||||
self.isDestroyed = true
|
self.isDestroyed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- PHYSICS INITIALISATION
|
-- PHYSICS FUNCTIONS
|
||||||
-- Basic initialization of the physic systems
|
-- Raw implementation of everything common in physics
|
||||||
|
|
||||||
|
function BaseActor:initPhysics(x, y, z, w, h, d)
|
||||||
|
self:setCoordinate(x, y, z)
|
||||||
|
|
||||||
|
self.w = w or 0
|
||||||
|
self.h = h or 0
|
||||||
|
self.d = d or 0
|
||||||
|
|
||||||
|
self.xsp = 0
|
||||||
|
self.ysp = 0
|
||||||
|
self.zsp = 0
|
||||||
|
|
||||||
|
self.xfrc = 0
|
||||||
|
self.yfrc = 0
|
||||||
|
self.zfrc = 0
|
||||||
|
|
||||||
function BaseActor:initPhysics()
|
|
||||||
self:initMovement()
|
|
||||||
self:initGravity()
|
self:initGravity()
|
||||||
|
|
||||||
self:setBounceFactor()
|
self:setBounceFactor()
|
||||||
self:setFilter()
|
self:setFilter()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BaseActor: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 BaseActor:setBounceFactor(newBounceFactor)
|
function BaseActor:setBounceFactor(newBounceFactor)
|
||||||
self.bounceFactor = newBounceFactor or 0
|
self.bounceFactor = newBounceFactor or 0
|
||||||
end
|
end
|
||||||
|
@ -98,14 +117,20 @@ function BaseActor:setFilter()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseActor:initMovement( )
|
|
||||||
-- Empty placeholder function
|
|
||||||
end
|
|
||||||
|
|
||||||
function BaseActor:initGravity( )
|
function BaseActor:initGravity( )
|
||||||
-- Empty placeholder function
|
-- Empty placeholder function
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- COORDINATE/MOVEMENT FUNCTIONS
|
||||||
|
-- Handle coordinate
|
||||||
|
|
||||||
|
function BaseActor:getCenter()
|
||||||
|
return (self.x + (self.w / 2)), (self.y + (self.h / 2)), (self.z + (self.d / 2))
|
||||||
|
end
|
||||||
|
|
||||||
|
function BaseActor:getViewCenter()
|
||||||
|
return self:getCenter()
|
||||||
|
end
|
||||||
|
|
||||||
-- UPDATE FUNCTIONS
|
-- UPDATE FUNCTIONS
|
||||||
-- Theses functions are activated every steps
|
-- Theses functions are activated every steps
|
||||||
|
|
Loading…
Reference in a new issue