From: JBM Date: Wed, 27 May 2020 09:52:44 +0000 (+0200) Subject: Add debug mode for @pb4. Also ensure it's useless by X-Git-Url: https://troll.desast.re/troll.git/commitdiff_plain/32050f92ddfeefc143c87440ac4fe6b10c78a9cb?ds=inline;hp=1b2f76237b137aedd6c447580412a3b93d50a9bf Add debug mode for @pb4. Also ensure it's useless by displaying the troll's position as a distance from both sides instead of from the road's center. --- diff --git a/pom.xml b/pom.xml index b7d6d9e..8262acc 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,12 @@ ${gamengine.version} + + com.codingame.gameengine + module-toggle + ${gamengine.version} + + com.codingame.gameengine runner diff --git a/src/main/java/com/codingame/game/View.java b/src/main/java/com/codingame/game/View.java index d3d51d1..f39bbb8 100644 --- a/src/main/java/com/codingame/game/View.java +++ b/src/main/java/com/codingame/game/View.java @@ -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 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 index 0000000..640581a Binary files /dev/null and b/src/main/resources/view/assets/debug.png differ diff --git a/src/main/resources/view/assets/game.xcf b/src/main/resources/view/assets/game.xcf index 8384687..c1d9e89 100644 Binary files a/src/main/resources/view/assets/game.xcf and b/src/main/resources/view/assets/game.xcf differ diff --git a/src/main/resources/view/config.js b/src/main/resources/view/config.js index 50b1654..164519f 100644 --- a/src/main/resources/view/config.js +++ b/src/main/resources/view/config.js @@ -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 + }) ];