@Inject private GraphicEntityModule graphicEntityModule;
@Inject PantsModule pantsModule;
+ /*
+ * Frame timings, for a base frame length of 2s:
+ * - first half: stone throw
+ * - second half: troll move
+ * The troll message is anchored around the troll move.
+ *
+ * The castle destruction is currently ad hoc simultaneously with
+ * the troll move, but this ought to change if I get some
+ * lengthened frame system ready.
+ *
+ * The endgame message is completely ad hoc, and really ought to
+ * improve.
+ */
+ private final double AVATAR_ANIMATION_START = 0.5;
+ private final double STONE_THROW_START = 0.0;
+ private final double STONE_THROW_PEAK = 0.25;
+ private final double STONE_THROW_END = 0.5;
+ private final double CASTLE_DESTRUCTION_START = 0.5;
+ private final double CASTLE_DESTRUCTION_END = 1.0;
+ private final double TROLL_MOVE_START = 0.5;
+ private final double TROLL_MOVE_END = 1.0;
+ private final double TROLL_MESSAGE_START = 0.5;
+ private final double TROLL_MESSAGE_END = 1.0;
+ private final double ENDGAME_MESSAGE_START = 0.25;
+
class Player {
Model.Player model;
}
void startTurn() {
- graphicEntityModule.commitEntityState(0, stoneReminder);
+ graphicEntityModule.commitEntityState(0.0, stoneReminder);
}
void victory() {
}
void markWinner() {
- graphicEntityModule.commitEntityState(0.5, avatar);
+ graphicEntityModule.commitEntityState(AVATAR_ANIMATION_START, avatar);
avatar.setScaleX(1.5, Curve.EASE_OUT);
avatar.setScaleY(1.5, Curve.EASE_OUT);
avatar.setRotation((random.nextDouble() - 0.5) * Math.PI / 18,
}
void markLoser() {
- graphicEntityModule.commitEntityState(0.5, avatar);
+ graphicEntityModule.commitEntityState(AVATAR_ANIMATION_START, avatar);
int dir = random.nextInt(2) == 1 ? 1 : -1;
avatar.setRotation(dir * 170 * Math.PI / 180, Curve.ELASTIC);
}
stone.setY(castle.getY() - 100);
stone.setText(stonesString);
stone.setAlpha(1);
- graphicEntityModule.commitEntityState(0, stone);
+ graphicEntityModule.commitEntityState(STONE_THROW_START, stone);
int peakX = (castle.getX() + troll.getX()) / 2;
int peakY = 540;
stone.setX(peakX);
stone.setY(peakY, Curve.EASE_OUT);
- graphicEntityModule.commitEntityState(0.25,
+ graphicEntityModule.commitEntityState(STONE_THROW_PEAK,
stone,
stoneCounter);
stone.setX(troll.getX());
stone.setY(troll.getY() - 50, Curve.EASE_IN);
stone.setAlpha(0, Curve.EASE_IN);
- graphicEntityModule.commitEntityState(0.5, stone);
+ graphicEntityModule.commitEntityState(STONE_THROW_END, stone);
stoneReminder.setText(stonesString);
- graphicEntityModule.commitEntityState(0, stoneReminder);
+ graphicEntityModule.commitEntityState(0.0, stoneReminder);
}
// ========== Player/castle
void displayMessage(String msg) {
message.setText(msg);
- graphicEntityModule.commitEntityState(0, message);
+ graphicEntityModule.commitEntityState(0.0, message);
}
void destroyCastle() {
- graphicEntityModule.commitEntityState(0.5, castle);
+ graphicEntityModule.commitEntityState(CASTLE_DESTRUCTION_START, castle);
castle.setX(castle.getX(), Curve.ELASTIC);
castle.setScaleY(-0.2, Curve.EASE_IN);
+ graphicEntityModule.commitEntityState(CASTLE_DESTRUCTION_END, castle);
}
} // class Player
}
private void moveTroll() {
- graphicEntityModule.commitEntityState(0.5, troll, trollPositionGauge);
+ graphicEntityModule.commitEntityState(TROLL_MOVE_START, troll, trollPositionGauge);
int x0 = p0.castle.getX(), x1 = p1.castle.getX();
int y0 = p0.castle.getY(), y1 = p1.castle.getY();
troll.setX(x0 + model.trollPosition * (x1-x0) / model.roadLength,
else {
trollPositionGauge.setText(distLeft + " ↔ " + distRight);
}
- graphicEntityModule.commitEntityState(0.75, trollPositionGauge);
+ final double moveMid = (TROLL_MOVE_START + TROLL_MOVE_END) / 2;
+ graphicEntityModule.commitEntityState(moveMid, trollPositionGauge);
trollPositionGauge.setX(troll.getX());
}
gameManager.addToGameSummary(trollRace.starter + " " + d.movement);
trollMessage.setText(selectTrollMessage(d)).setAlpha(1, Curve.NONE);
- graphicEntityModule.commitEntityState(0.5, trollMessage);
+ graphicEntityModule.commitEntityState(TROLL_MESSAGE_START, trollMessage);
trollMessage.setAlpha(0, Curve.EASE_IN);
- graphicEntityModule.commitEntityState(1, trollMessage);
+ graphicEntityModule.commitEntityState(TROLL_MESSAGE_END, trollMessage);
}
String selectTrollMessage(Dir d) {
void animateLoss(int x, int y, int size, String message) {
int startX;
if (x < 1920/2) { startX = 1920; }
- else if (x > 1920/2) { startX = 1920; } // XXX
+ else if (x > 1920/2) { startX = 0; }
else { startX = 1920 * random.nextInt(2); }
Text msg = graphicEntityModule.createText(message)
.setFillColor(0xff7f7f)
.setFontWeight(Text.FontWeight.BOLD)
.setTextAlign(TextBasedEntity.TextAlign.CENTER);
- graphicEntityModule.commitEntityState(0.25, msg);
+ graphicEntityModule.commitEntityState(ENDGAME_MESSAGE_START, msg);
Curve curve = Curve.ELASTIC;
msg.setX(x, Curve.EASE_OUT)
.setY(y, Curve.ELASTIC)