From cd7e381672bebed128dae515adc3795ad2bd1230 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 Jun 2019 19:55:38 +0200 Subject: [PATCH] refactor(levels): use Actor2D initialization functions --- .../scenes/levels/entities/debris.lua | 2 +- .../scenes/levels/entities/parent.lua | 49 ++++--------------- .../scenes/levels/entities/player.lua | 5 +- 3 files changed, 13 insertions(+), 43 deletions(-) diff --git a/imperium-porcorum.love/scenes/levels/entities/debris.lua b/imperium-porcorum.love/scenes/levels/entities/debris.lua index d5be766..ac12b5a 100644 --- a/imperium-porcorum.love/scenes/levels/entities/debris.lua +++ b/imperium-porcorum.love/scenes/levels/entities/debris.lua @@ -9,7 +9,7 @@ function Debris:new(world, x, y, speed, dir, timelimit) self.timelimit = timelimit or 2 self:setMotionDirection(dir, speed) self.grav = 1 - self.bounce = 0.5 + self:setBounceFactor(0.5) self.frc = 0.046875*60*1.5 self.rotation = love.math.random(0, 360) end diff --git a/imperium-porcorum.love/scenes/levels/entities/parent.lua b/imperium-porcorum.love/scenes/levels/entities/parent.lua index 2d74e06..719c5f7 100644 --- a/imperium-porcorum.love/scenes/levels/entities/parent.lua +++ b/imperium-porcorum.love/scenes/levels/entities/parent.lua @@ -1,42 +1,27 @@ 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 -function Entity:new(world, type, x, y, w, h) -- On enregistre une nouvelle entité, avec par défaut sa hitbox. - self:initPhysics(world, type, x, y, w, h) - self.destroyed = false - self.registered = false - self:setDebugColor(0,0,0) +function Entity:new(world, type, x, y, w, h, isSolid) + self.playerID = -1 + self.camera = world.scene.camera -- TODO: change that + Entity.super.new(self, world, type, x, y, w, h, isSolid) end -function Entity:initPhysics(world, type, x, y, w, h) - self:setManagers(world) - self.camera = self.scene.camera - self.type = type - - self.gacc = 550 - self.xsp = 0 - self.ysp = 0 - - self.bounce = 0 - self.grav = 0 +function Entity:initMovement() + Entity.super.initMovement(self) self.frc = 0 +end - self:initHitbox(x, y, w, h) +function Entity:initGravity() + self.grav = 0 + self.gacc = 550 self.onGround = false - - self.playerID = -1 - - self:register() end function Entity:update(dt) end -function Entity:canBounce(bounce) - self.bounce = bounce -end - function Entity:setMotion(xsp, ysp) self.xsp, self.ysp = xsp, ysp end @@ -66,20 +51,6 @@ function Entity:friction(dt) 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() self:remove() end diff --git a/imperium-porcorum.love/scenes/levels/entities/player.lua b/imperium-porcorum.love/scenes/levels/entities/player.lua index 9b1525f..5d76ae2 100644 --- a/imperium-porcorum.love/scenes/levels/entities/player.lua +++ b/imperium-porcorum.love/scenes/levels/entities/player.lua @@ -24,11 +24,10 @@ function Player:new(world, x, y, playerID) self:getStats(playerID) self:lifeInit() self:initWeapon() + self:initStats() self.currentWeapon = 1 - self:initMovement() - self:setDebugColor(0,255,0) end @@ -43,7 +42,7 @@ function Player:lifeInit() self.mp = self.stats.maxMP end -function Player:initMovement() +function Player:initStats() self.maxxsp = 16*60 self.maxysp = self.maxxsp self.topsp = 4.5*60