refactor(levels): use the friction system from gamecore

This commit is contained in:
Kazhnuz 2019-06-17 11:02:49 +02:00
parent 0da137a3e4
commit c21753d988
3 changed files with 7 additions and 15 deletions

View File

@ -10,7 +10,7 @@ function Debris:new(world, x, y, speed, dir, timelimit)
self:setMotionDirection(dir, speed) self:setMotionDirection(dir, speed)
self.grav = 1 self.grav = 1
self:setBounceFactor(0.5) self:setBounceFactor(0.5)
self.frc = 0.046875*60*1.5 self.xfrc = 0.046875*60*1.5*60*4
self.rotation = love.math.random(0, 360) self.rotation = love.math.random(0, 360)
end end
@ -27,7 +27,7 @@ end
function Debris:update(dt) function Debris:update(dt)
self:setFilter() self:setFilter()
self:gravity(dt) self:gravity(dt)
self:friction(dt) self:applyFriction(dt)
--self.x, self.y, cols, cols_len = currentLevel.world:move(self, self.x + self.xsp*dt, self.y + self.ysp*dt, bulletFilter) --self.x, self.y, cols, cols_len = currentLevel.world:move(self, self.x + self.xsp*dt, self.y + self.ysp*dt, bulletFilter)
cols, cols_len = self:move(dt) cols, cols_len = self:move(dt)

View File

@ -7,11 +7,6 @@ function Entity:new(world, type, x, y, w, h, isSolid)
Entity.super.new(self, world, type, x, y, w, h, isSolid) Entity.super.new(self, world, type, x, y, w, h, isSolid)
end end
function Entity:initMovement()
Entity.super.initMovement(self)
self.frc = 0
end
function Entity:initGravity() function Entity:initGravity()
self.grav = 0 self.grav = 0
self.gacc = 550 self.gacc = 550
@ -43,12 +38,9 @@ function Entity:gravity(dt)
self.ysp = self.ysp + self.gacc * self.grav * dt self.ysp = self.ysp + self.gacc * self.grav * dt
end end
function Entity:friction(dt) function Entity:applyFriction(dt)
if (math.abs(self.xsp) <= self.frc) then self.xsp = utils.math.toZero(self.xsp, self.xfrc * dt)
self.xsp = 0 self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt)
else
self.xsp = self.xsp - (self.frc * utils.math.sign(self.xsp))
end
end end
function Entity:purge() function Entity:purge()

View File

@ -49,7 +49,7 @@ function Player:initStats()
self.topsp = 4.5*60 self.topsp = 4.5*60
self.acc = 0.046875*60*1.5 self.acc = 0.046875*60*1.5
self.dec = 0.5*60 self.dec = 0.5*60
self.frc = self.acc self.xfrc = self.acc*60*4
self.grav = 1 self.grav = 1
self.jmp = -5*60 self.jmp = -5*60
@ -156,7 +156,7 @@ function Player:actionMove(dt)
end end
end end
else else
self:friction(dt) self:applyFriction(dt)
end end
if (self.grav == 0) then if (self.grav == 0) then