From 38fddc9a51fde719092ec86cdb1d5d808dc9d474 Mon Sep 17 00:00:00 2001
From: Paolo Brasolin <paolo.brasolin@eurac.edu>
Date: Mon, 4 Apr 2022 15:07:19 +0200
Subject: [PATCH] refactor: #fe improve init placement and bound checking

---
 frontend/src/js/critter.ts | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/frontend/src/js/critter.ts b/frontend/src/js/critter.ts
index a92744f..4e81eb4 100644
--- a/frontend/src/js/critter.ts
+++ b/frontend/src/js/critter.ts
@@ -38,6 +38,12 @@ class Critter extends Phaser.Physics.Arcade.Sprite {
 
     this.setScale(scale);
 
+    // NOTE: just outside the bound and above the ground
+    this.setPosition(
+      -0.5 * this.displayWidth,
+      scene.cameras.main.height - 30 - 0.5 * this.displayHeight,
+    );
+
     this.walk();
   }
 
@@ -52,11 +58,11 @@ class Critter extends Phaser.Physics.Arcade.Sprite {
   }
 
   isOutsideRightBound() {
-    return this.x - this.width * 0.5 > this.scene.cameras.main.width;
+    return this.getBounds().left > this.scene.cameras.main.width;
   }
 
   isOutsideLeftBound() {
-    return this.x + this.width * 0.5 < 0;
+    return this.getBounds().right < 0;
   }
 
   walk() {
-- 
GitLab