<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>
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;
p1.init(gameManager.getPlayer(1));
drawTroll();
+
+ drawDebug();
}
void startTurn() {
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);
+ }
}