+ enum Dir {
+ LEFT("walks left.", 0),
+ STILL("stands still.", 1),
+ RIGHT("walks right.", 2);
+
+ String movement; int index;
+ Dir(String mvt, int i) { movement = mvt; index = i; }
+ }
+
+ void moveTroll(Dir d) {
+ moveTroll();
+ gameManager.addToGameSummary(trollRace.starter + " " + d.movement);
+
+ trollMessage.setText(selectTrollMessage(d)).setAlpha(1, Curve.NONE);
+ graphicEntityModule.commitEntityState(TROLL_MESSAGE_START, trollMessage);
+ trollMessage.setAlpha(0, Curve.EASE_IN);
+ graphicEntityModule.commitEntityState(TROLL_MESSAGE_END, trollMessage);
+ }
+
+ String selectTrollMessage(Dir d) {
+ if (random.nextInt(10000) == 0) {
+ return TrollText.specials[random.nextInt(TrollText.specials.length)];
+ }
+
+ // yup, still biased
+ int i = random.nextInt(TrollText.directed.length + TrollText.isotropic.length / 3);
+ if (i < TrollText.directed.length) {
+ return TrollText.directed[i][d.index];
+ }
+ else {
+ return TrollText.isotropic[random.nextInt(TrollText.isotropic.length)];
+ }
+ }
+
+ // ==================== Debug information
+
+ void animateTurnCounter() {
+ for (int i = 0; i < 10; i++) {
+ turnCounter.setText("T" + _turns + "." + i);
+ // The following line is likely not a bug.
+ graphicEntityModule.commitEntityState((double) i/9, turnCounter);
+ }
+ _turns++;
+ }
+
+ 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(60)
+ .setAnchorX(0.5)
+ .setLoop(true);
+ pantsModule.displayOnToggleState(debugMode, "debug", true);
+
+ turnCounter = graphicEntityModule.createText()
+ .setAnchorX(0.5)
+ .setAnchorY(0)
+ .setX(1920 / 2)
+ .setY(260)
+ .setStrokeColor(0xff0080)
+ .setFillColor(0xff0080)
+ .setFontFamily("monospace")
+ .setFontWeight(Text.FontWeight.BOLD)
+ .setFontSize(100);
+ pantsModule.displayOnToggleState(turnCounter, "debug", true);
+ animateTurnCounter();
+ }
+
+ // ==================== Endgame status
+
+ void animateLoss(int x, int y, int size, String message) {
+ int startX;
+ if (x < 1920/2) { startX = 1920; }
+ else if (x > 1920/2) { startX = 0; }
+ else { startX = 1920 * random.nextInt(2); }
+
+ Text msg = graphicEntityModule.createText(message)
+ .setX(startX)
+ .setY(1080)
+ .setAnchorX(0.5)
+ .setAnchorY(0.5)
+ .setScaleX(3*random.nextDouble() - 1)
+ .setScaleY(3*random.nextDouble() - 1)
+ .setSkewX(2*random.nextDouble() - 1)
+ .setSkewY(2*random.nextDouble() - 1)
+ .setRotation(4*Math.PI * (1 + random.nextDouble())
+ * (random.nextInt(2) == 0 ? 1 : -1))
+ .setFontSize(0)
+ .setStrokeColor(0xff7f7f)
+ .setFillColor(0xff7f7f)
+ .setFontWeight(Text.FontWeight.BOLD)
+ .setTextAlign(TextBasedEntity.TextAlign.CENTER);
+ graphicEntityModule.commitEntityState(0.0, msg);
+ Curve curve = Curve.ELASTIC;
+ msg.setX(x, Curve.EASE_OUT)
+ .setY(y, Curve.ELASTIC)
+ .setScaleX(1, curve)
+ .setScaleY(1, curve)
+ .setSkewX(0, curve)
+ .setSkewY(0, curve)
+ .setRotation(2*Math.PI * (random.nextDouble() - 0.5), Curve.LINEAR)
+ .setFontSize(size, curve);
+ }