displaying the troll's position as a distance from both
sides instead of from the road's center.
<version>${gamengine.version}</version>
</dependency>
<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>
<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.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.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;
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;
class Player {
Model.Player model;
p1.init(gameManager.getPlayer(1));
drawTroll();
p1.init(gameManager.getPlayer(1));
drawTroll();
Curve.ELASTIC);
trollPositionGauge.setX((trollPositionGauge.getX() + troll.getX()) / 2);
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 + " →");
- trollPositionGauge.setText("↔");
+ trollPositionGauge.setText(distLeft + " ↔ " + distRight);
}
graphicEntityModule.commitEntityState(0.75, trollPositionGauge);
trollPositionGauge.setX(troll.getX());
}
}
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);
+ }
import { GraphicEntityModule } from './entity-module/GraphicEntityModule.js';
import { GraphicEntityModule } from './entity-module/GraphicEntityModule.js';
+import { ToggleModule } from './toggle-module/ToggleModule.js';
export const gameName = 'Castle-Troll';
export const gameName = 'Castle-Troll';
];
export const modules = [
];
export const modules = [
+ GraphicEntityModule
+ , ToggleModule
+];
+
+export const options = [
+ ToggleModule.defineToggle({
+ toggle: 'debug',
+ title: 'Debug Mode',
+ values: {
+ 'on': true,
+ 'off': false
+ },
+ default: false
+ })