From 738ed2aeaa2ab30f7a4fb5a7754ca106c43757b0 Mon Sep 17 00:00:00 2001
From: Paolo Brasolin <paolo.brasolin@eurac.edu>
Date: Wed, 6 Apr 2022 10:41:29 +0200
Subject: [PATCH] feat: #fe responsive critter size

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

diff --git a/frontend/src/js/critter.ts b/frontend/src/js/critter.ts
index 4e81eb4..539baea 100644
--- a/frontend/src/js/critter.ts
+++ b/frontend/src/js/critter.ts
@@ -25,18 +25,15 @@ class Critter extends Phaser.Physics.Arcade.Sprite {
     this.species = species;
     this.baseVelocity = baseVelocity;
 
-    let scale = 2;
-    if (this.species === "deer") {
-      scale = 2.5;
-    } else if (this.species === "bear") {
-      scale = 3;
-    }
-
     this.body = new Phaser.Physics.Arcade.Body(this.scene.physics.world, this);
     this.scene.physics.world.add(this.body);
     this.setCollideWorldBounds(true);
 
-    this.setScale(scale);
+    // NOTE: our sprites widths are in the 52-72 range; average: 62.
+    // NOTE: the idea is to fit 5 critters onscreen, tail to tail
+    const averageWidth = 62;
+    const targetAverageWidth = this.scene.cameras.main.width * 0.2;
+    this.setScale(targetAverageWidth / averageWidth);
 
     // NOTE: just outside the bound and above the ground
     this.setPosition(
-- 
GitLab