From 94c38b87f179f4812277601446c87347c7ff0c75 Mon Sep 17 00:00:00 2001 From: Autapomorph Date: Mon, 13 Jul 2020 21:25:35 +0300 Subject: [PATCH] refactor: use setBodySize --- src/prefabs/horizon/obstacles/bird/AnimationManager.js | 9 ++++----- src/prefabs/horizon/obstacles/cactus/Cactus.js | 2 +- src/prefabs/player/PhysicsManager.js | 9 ++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/prefabs/horizon/obstacles/bird/AnimationManager.js b/src/prefabs/horizon/obstacles/bird/AnimationManager.js index 535d6cf..2cac642 100644 --- a/src/prefabs/horizon/obstacles/bird/AnimationManager.js +++ b/src/prefabs/horizon/obstacles/bird/AnimationManager.js @@ -45,7 +45,6 @@ class AnimationManager { * @param {Phaser.Animations.AnimationFrame} frame */ resizeBodyOnAnim(anim, frame) { - const { body } = this.bird; const { name } = frame.frame; const bodyZoneWidth = 76; @@ -56,11 +55,11 @@ class AnimationManager { // Resize body to match frame dimensions if (name === AnimationManager.CONFIG.FRAMES.FLYING[0]) { const frameYOffset = 12; - body.setSize(bodyZoneWidth, bodyZoneHeight); - body.setOffset(bodyZoneXOffset, frameYOffset + bodyZoneYOffset); + this.bird.setBodySize(bodyZoneWidth, bodyZoneHeight); + this.bird.body.setOffset(bodyZoneXOffset, frameYOffset + bodyZoneYOffset); } else if (name === AnimationManager.CONFIG.FRAMES.FLYING[1]) { - body.setSize(bodyZoneWidth, bodyZoneHeight); - body.setOffset(bodyZoneXOffset, bodyZoneYOffset); + this.bird.setBodySize(bodyZoneWidth, bodyZoneHeight); + this.bird.body.setOffset(bodyZoneXOffset, bodyZoneYOffset); } } } diff --git a/src/prefabs/horizon/obstacles/cactus/Cactus.js b/src/prefabs/horizon/obstacles/cactus/Cactus.js index 4097a7e..2a59da4 100644 --- a/src/prefabs/horizon/obstacles/cactus/Cactus.js +++ b/src/prefabs/horizon/obstacles/cactus/Cactus.js @@ -15,7 +15,7 @@ class Cactus extends Obstacle { // reduce body size by excluding borders const borderWidth = 2; - this.body.setSize(this.width - borderWidth * 2, this.height - borderWidth); + this.setBodySize(this.width - borderWidth * 2, this.height - borderWidth); this.body.setOffset(borderWidth, borderWidth); } } diff --git a/src/prefabs/player/PhysicsManager.js b/src/prefabs/player/PhysicsManager.js index e8465e2..3e87af7 100644 --- a/src/prefabs/player/PhysicsManager.js +++ b/src/prefabs/player/PhysicsManager.js @@ -71,7 +71,6 @@ class PhysicsManager { * @param {Phaser.Textures.Frame} frame - Current Player texture frame */ resizeBodyToMatchFrame(frame) { - const { body } = this.player; const { name, width, height } = frame; // Resize body to reduce player collisions @@ -83,14 +82,14 @@ class PhysicsManager { const headZone = 15; const tailZone = 25; const topZone = 4; - body.setSize(width - headZone - tailZone, height - topZone); - body.setOffset(tailZone, topZone); + this.player.setBodySize(width - headZone - tailZone, height - topZone); + this.player.body.setOffset(tailZone, topZone); } else if (PhysicsManager.CONFIG.FRAMES.DUCKING.includes(name)) { const headZone = 35; const tailZone = 25; const topZone = 6; - body.setSize(width - headZone - tailZone, height - topZone); - body.setOffset(tailZone, topZone); + this.player.setBodySize(width - headZone - tailZone, height - topZone); + this.player.body.setOffset(tailZone, topZone); } } }