From c21753d988dafffcf378500c0f294036e1e0bea7 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 17 Jun 2019 11:02:49 +0200 Subject: [PATCH] refactor(levels): use the friction system from gamecore --- .../scenes/levels/entities/debris.lua | 4 ++-- .../scenes/levels/entities/parent.lua | 14 +++----------- .../scenes/levels/entities/player.lua | 4 ++-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/imperium-porcorum.love/scenes/levels/entities/debris.lua b/imperium-porcorum.love/scenes/levels/entities/debris.lua index ac12b5a..7f5a5d5 100644 --- a/imperium-porcorum.love/scenes/levels/entities/debris.lua +++ b/imperium-porcorum.love/scenes/levels/entities/debris.lua @@ -10,7 +10,7 @@ function Debris:new(world, x, y, speed, dir, timelimit) self:setMotionDirection(dir, speed) self.grav = 1 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) end @@ -27,7 +27,7 @@ end function Debris:update(dt) self:setFilter() 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) cols, cols_len = self:move(dt) diff --git a/imperium-porcorum.love/scenes/levels/entities/parent.lua b/imperium-porcorum.love/scenes/levels/entities/parent.lua index a3b6ca3..ce11b1b 100644 --- a/imperium-porcorum.love/scenes/levels/entities/parent.lua +++ b/imperium-porcorum.love/scenes/levels/entities/parent.lua @@ -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) end -function Entity:initMovement() - Entity.super.initMovement(self) - self.frc = 0 -end - function Entity:initGravity() self.grav = 0 self.gacc = 550 @@ -43,12 +38,9 @@ function Entity:gravity(dt) self.ysp = self.ysp + self.gacc * self.grav * dt end -function Entity:friction(dt) - if (math.abs(self.xsp) <= self.frc) then - self.xsp = 0 - else - self.xsp = self.xsp - (self.frc * utils.math.sign(self.xsp)) - end +function Entity:applyFriction(dt) + self.xsp = utils.math.toZero(self.xsp, self.xfrc * dt) + self.ysp = utils.math.toZero(self.ysp, self.yfrc * dt) end function Entity:purge() diff --git a/imperium-porcorum.love/scenes/levels/entities/player.lua b/imperium-porcorum.love/scenes/levels/entities/player.lua index ab14dfa..a4262cf 100644 --- a/imperium-porcorum.love/scenes/levels/entities/player.lua +++ b/imperium-porcorum.love/scenes/levels/entities/player.lua @@ -49,7 +49,7 @@ function Player:initStats() self.topsp = 4.5*60 self.acc = 0.046875*60*1.5 self.dec = 0.5*60 - self.frc = self.acc + self.xfrc = self.acc*60*4 self.grav = 1 self.jmp = -5*60 @@ -156,7 +156,7 @@ function Player:actionMove(dt) end end else - self:friction(dt) + self:applyFriction(dt) end if (self.grav == 0) then