+ class Player {
+ Model.Player model;
+ int colorToken;
+ String nicknameToken;
+ String avatarToken;
+
+ Group avatar;
+ Text stoneCounter;
+ Text message;
+ Sprite castle;
+ Text stone;
+
+ void init(com.codingame.game.Player p) {
+ model = p.model;
+ colorToken = p.getColorToken();
+ nicknameToken = p.getNicknameToken();
+ avatarToken = p.getAvatarToken();
+
+ boolean p0 = model.index == 0;
+ int x = p0 ? 280 : 1920 - 280;
+ int y = 220;
+
+ Rectangle border1 = graphicEntityModule
+ .createRectangle()
+ .setWidth(140)
+ .setHeight(140)
+ .setX(x - 70)
+ .setY(y - 70)
+ .setLineWidth(0)
+ .setFillColor(colorToken);
+
+ Rectangle border2 = graphicEntityModule
+ .createRectangle()
+ .setWidth(120)
+ .setHeight(120)
+ .setX(x - 60)
+ .setY(y - 60)
+ .setLineWidth(0)
+ .setFillColor(0xffffff);
+
+ Sprite avatarSprite = graphicEntityModule.createSprite()
+ .setX(x)
+ .setY(y)
+ .setZIndex(20)
+ .setImage(avatarToken)
+ .setAnchor(0.5)
+ .setBaseHeight(116)
+ .setBaseWidth(116);
+
+ avatar = graphicEntityModule.createGroup(border1, border2, avatarSprite);
+
+ Text text = graphicEntityModule.createText(nicknameToken)
+ .setX(x)
+ .setY(y + 120)
+ .setZIndex(20)
+ .setFontSize(40)
+ .setFillColor(0x7f3f00)
+ .setAnchor(0.5);
+
+ stoneCounter = graphicEntityModule.createText("S")
+ .setX(x)
+ .setY(y+200)
+ .setZIndex(20)
+ .setFontSize(40)
+ .setFillColor(0x7f3f00)
+ .setAnchor(0.5);
+
+ message = graphicEntityModule.createText()
+ .setX(p0 ? 15 : 1920-15)
+ .setY(680)
+ .setZIndex(1)
+ .setFontSize(40)
+ .setStrokeColor(0x000000)
+ .setFillColor(0xffbf7f)
+ .setAnchorX(p0 ? 0 : 1)
+ .setAnchorY(1);
+
+ castle = graphicEntityModule.createSprite()
+ .setImage("castle.png")
+ .setTint(colorToken)
+ .setX(p0 ? 160 : 1920-160)
+ .setY(p0 ? 890 : 880)
+ .setZIndex(1)
+ .setAnchorX(0.5)
+ .setAnchorY(1)
+ .setScaleX(p0 ? 1 : -1);
+
+ stone = graphicEntityModule.createText()
+ .setZIndex(3)
+ .setFontSize(150)
+ .setFillColor(0x12322a)
+ .setAnchor(0.5)
+ .setAlpha(0);
+ }
+
+ void setStone() {
+ int stones = model.getStones();
+ if (stones <= 0) {
+ stoneCounter.setText("No stones!");
+ stoneCounter.setFillColor(0xff7777);
+ }
+ else if (stones == 1) {
+ stoneCounter.setText("1 stone");
+ stoneCounter.setFillColor(0xffbb77);
+ }
+ else {
+ stoneCounter.setText(stones + " stones");
+ }
+ }
+ void animateStones(int stones) {
+ stone.setX(castle.getX());
+ stone.setY(castle.getY() - 100);
+ stone.setText(new Integer(stones).toString());
+ stone.setAlpha(1);
+ graphicEntityModule.commitEntityState(0, stone);
+
+ int peakX = (castle.getX() + troll.getX()) / 2;
+ int peakY = 540;
+ stone.setX(peakX);
+ stone.setY(peakY, Curve.EASE_OUT);
+ graphicEntityModule.commitEntityState(0.25,
+ 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);
+ }
+ void displayMessage(String msg) {
+ message.setText(msg);
+ graphicEntityModule.commitEntityState(0, message);
+ }
+
+ void destroy() {
+ avatar.setRotation(170*Math.PI/180, Curve.ELASTIC);
+
+ graphicEntityModule.commitEntityState(0.5, castle);
+ castle.setX(castle.getX(), Curve.ELASTIC);
+ castle.setScaleY(-0.2, Curve.EASE_IN);
+ }
+ }
+
+ Model model;