refactor(levels): use Actor2D initialization functions

This commit is contained in:
Kazhnuz 2019-06-16 19:55:38 +02:00
parent 4ee17f01b6
commit cd7e381672
3 changed files with 13 additions and 43 deletions

View File

@ -9,7 +9,7 @@ function Debris:new(world, x, y, speed, dir, timelimit)
self.timelimit = timelimit or 2 self.timelimit = timelimit or 2
self:setMotionDirection(dir, speed) self:setMotionDirection(dir, speed)
self.grav = 1 self.grav = 1
self.bounce = 0.5 self:setBounceFactor(0.5)
self.frc = 0.046875*60*1.5 self.frc = 0.046875*60*1.5
self.rotation = love.math.random(0, 360) self.rotation = love.math.random(0, 360)
end end

View File

@ -1,42 +1,27 @@
local Base = require "core.modules.world.actors.actor2D" local Base = require "core.modules.world.actors.actor2D"
local Entity = Base:extend() -- On créer la classe des entitées, c'est la classe de base local Entity = Base:extend() -- On créer la classe des entitées, c'est la classe de base
function Entity:new(world, type, x, y, w, h) -- On enregistre une nouvelle entité, avec par défaut sa hitbox. function Entity:new(world, type, x, y, w, h, isSolid)
self:initPhysics(world, type, x, y, w, h) self.playerID = -1
self.destroyed = false self.camera = world.scene.camera -- TODO: change that
self.registered = false Entity.super.new(self, world, type, x, y, w, h, isSolid)
self:setDebugColor(0,0,0)
end end
function Entity:initPhysics(world, type, x, y, w, h) function Entity:initMovement()
self:setManagers(world) Entity.super.initMovement(self)
self.camera = self.scene.camera
self.type = type
self.gacc = 550
self.xsp = 0
self.ysp = 0
self.bounce = 0
self.grav = 0
self.frc = 0 self.frc = 0
end
self:initHitbox(x, y, w, h) function Entity:initGravity()
self.grav = 0
self.gacc = 550
self.onGround = false self.onGround = false
self.playerID = -1
self:register()
end end
function Entity:update(dt) function Entity:update(dt)
end end
function Entity:canBounce(bounce)
self.bounce = bounce
end
function Entity:setMotion(xsp, ysp) function Entity:setMotion(xsp, ysp)
self.xsp, self.ysp = xsp, ysp self.xsp, self.ysp = xsp, ysp
end end
@ -66,20 +51,6 @@ function Entity:friction(dt)
end end
end end
function Entity:changeSpeedToCollisionNormal(nx, ny)
local xsp, ysp = self.xsp, self.ysp
if (nx < 0 and xsp > 0) or (nx > 0 and xsp < 0) then
xsp = -xsp * self.bounce
end
if (ny < 0 and ysp > 0) or (ny > 0 and ysp < 0) then
ysp = -ysp * self.bounce
end
self.xsp, self.ysp = xsp, ysp
end
function Entity:purge() function Entity:purge()
self:remove() self:remove()
end end

View File

@ -24,11 +24,10 @@ function Player:new(world, x, y, playerID)
self:getStats(playerID) self:getStats(playerID)
self:lifeInit() self:lifeInit()
self:initWeapon() self:initWeapon()
self:initStats()
self.currentWeapon = 1 self.currentWeapon = 1
self:initMovement()
self:setDebugColor(0,255,0) self:setDebugColor(0,255,0)
end end
@ -43,7 +42,7 @@ function Player:lifeInit()
self.mp = self.stats.maxMP self.mp = self.stats.maxMP
end end
function Player:initMovement() function Player:initStats()
self.maxxsp = 16*60 self.maxxsp = 16*60
self.maxysp = self.maxxsp self.maxysp = self.maxxsp
self.topsp = 4.5*60 self.topsp = 4.5*60