Add debug mode for @pb4. Also ensure it's useless by
authorJBM <jbm@codingame.com>
Wed, 27 May 2020 09:52:44 +0000 (11:52 +0200)
committerJBM <jbm@codingame.com>
Wed, 27 May 2020 14:56:48 +0000 (16:56 +0200)
displaying the troll's position as a distance from both
sides instead of from the road's center.

pom.xml
src/main/java/com/codingame/game/View.java
src/main/resources/view/assets/debug.png [new file with mode: 0644]
src/main/resources/view/assets/game.xcf
src/main/resources/view/config.js

diff --git a/pom.xml b/pom.xml
index b7d6d9e..8262acc 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        <version>${gamengine.version}</version>
                </dependency>
 
+               <dependency>
+                       <groupId>com.codingame.gameengine</groupId>
+                       <artifactId>module-toggle</artifactId>
+                       <version>${gamengine.version}</version>
+               </dependency>
+
                <dependency>
                        <groupId>com.codingame.gameengine</groupId>
                        <artifactId>runner</artifactId>
index d3d51d1..f39bbb8 100644 (file)
@@ -8,14 +8,17 @@ import com.codingame.gameengine.core.MultiplayerGameManager;
 import com.codingame.gameengine.module.entities.GraphicEntityModule;
 import com.codingame.gameengine.module.entities.Rectangle;
 import com.codingame.gameengine.module.entities.Sprite;
+import com.codingame.gameengine.module.entities.SpriteAnimation;
 import com.codingame.gameengine.module.entities.Text;
 import com.codingame.gameengine.module.entities.Group;
 import com.codingame.gameengine.module.entities.Curve;
+import com.codingame.gameengine.module.toggle.ToggleModule;
 import com.google.inject.Inject;
 
 class View {
     @Inject private MultiplayerGameManager<com.codingame.game.Player> gameManager;
     @Inject private GraphicEntityModule graphicEntityModule;
+    @Inject ToggleModule toggleModule;
 
     class Player {
         Model.Player model;
@@ -208,6 +211,8 @@ class View {
         p1.init(gameManager.getPlayer(1));
 
         drawTroll();
+
+        drawDebug();
     }
 
     void startTurn() {
@@ -288,18 +293,38 @@ class View {
                    Curve.ELASTIC);
 
         trollPositionGauge.setX((trollPositionGauge.getX() + troll.getX()) / 2);
-        int delta = model.trollPosition - model.roadLength / 2;
-        if (delta < 0) {
-            trollPositionGauge.setText("← " + Math.abs(delta));
+        int distLeft = model.trollPosition;
+        int distRight = model.roadLength - model.trollPosition;
+        if (distLeft <= 0) {
+            trollPositionGauge.setText("← " + distRight);
         }
-        else if (delta > 0) {
-            trollPositionGauge.setText(Math.abs(delta) + " →");
+        else if (distRight <= 0) {
+            trollPositionGauge.setText(distLeft + " →");
         }
         else {
-            trollPositionGauge.setText("↔");
+            trollPositionGauge.setText(distLeft + " ↔ " + distRight);
         }
         graphicEntityModule.commitEntityState(0.75, trollPositionGauge);
         trollPositionGauge.setX(troll.getX());
     }
 
+    void drawDebug() {
+        String[] debugModePngs = graphicEntityModule.createSpriteSheetSplitter()
+            .setSourceImage("debug.png")
+            .setImageCount(2)
+            .setWidth(900)
+            .setHeight(150)
+            .setOrigRow(0)
+            .setOrigCol(0)
+            .setImagesPerRow(1)
+            .setName("debug")
+            .split();
+        SpriteAnimation debugMode = graphicEntityModule.createSpriteAnimation()
+            .setImages(debugModePngs)
+            .setX(1920 / 2)
+            .setY(80)
+            .setAnchorX(0.5)
+            .setLoop(true);
+        toggleModule.displayOnToggleState(debugMode, "debug", true);
+    }
 }
diff --git a/src/main/resources/view/assets/debug.png b/src/main/resources/view/assets/debug.png
new file mode 100644 (file)
index 0000000..640581a
Binary files /dev/null and b/src/main/resources/view/assets/debug.png differ
index 8384687..c1d9e89 100644 (file)
Binary files a/src/main/resources/view/assets/game.xcf and b/src/main/resources/view/assets/game.xcf differ
index 50b1654..164519f 100644 (file)
@@ -1,4 +1,5 @@
 import { GraphicEntityModule } from './entity-module/GraphicEntityModule.js';
+import { ToggleModule } from './toggle-module/ToggleModule.js';
 
 export const gameName = 'Castle-Troll';
 
@@ -8,5 +9,18 @@ export const playerColors = [
 ];
 
 export const modules = [
-       GraphicEntityModule
+      GraphicEntityModule
+    , ToggleModule
+];
+
+export const options = [
+    ToggleModule.defineToggle({
+        toggle: 'debug',
+        title: 'Debug Mode',
+        values: {
+            'on': true,
+            'off': false
+        },
+        default: false
+    })
 ];