1 package com.codingame.game;
3 import java.util.Random;
5 import com.codingame.gameengine.core.MultiplayerGameManager;
6 import com.codingame.gameengine.module.entities.GraphicEntityModule;
7 import com.codingame.gameengine.module.entities.Rectangle;
8 import com.codingame.gameengine.module.entities.Sprite;
9 import com.codingame.gameengine.module.entities.Text;
10 import com.codingame.gameengine.module.entities.Group;
11 import com.codingame.gameengine.module.entities.Curve;
12 import com.google.inject.Inject;
15 @Inject private MultiplayerGameManager<com.codingame.game.Player> gameManager;
16 @Inject private GraphicEntityModule graphicEntityModule;
30 void init(com.codingame.game.Player p) {
32 colorToken = p.getColorToken();
33 nicknameToken = p.getNicknameToken();
34 avatarToken = p.getAvatarToken();
36 boolean p0 = model.index == 0;
37 int x = p0 ? 280 : 1920 - 280;
40 Sprite border1 = graphicEntityModule.createSprite()
43 .setImage("frame.png")
45 .setScale(p0 ? -1 : 1)
49 Sprite border2 = graphicEntityModule.createSprite()
52 .setImage("frame_bg.png")
56 Sprite avatarSprite = graphicEntityModule.createSprite()
60 .setImage(avatarToken)
65 avatar = graphicEntityModule
66 .createGroup(border1, border2, avatarSprite)
69 Text text = graphicEntityModule.createText(nicknameToken)
74 .setFillColor(0x7f3f00)
77 stoneCounter = graphicEntityModule.createText("S")
82 .setFillColor(0x7f3f00)
85 message = graphicEntityModule.createText()
86 .setX(p0 ? 15 : 1920-15)
90 .setStrokeColor(0x000000)
91 .setFillColor(0xffbf7f)
92 .setAnchorX(p0 ? 0 : 1)
95 castle = graphicEntityModule.createSprite()
96 .setImage("castle.png")
98 .setX(p0 ? 160 : 1920-160)
103 .setScaleX(p0 ? 1 : -1);
105 stone = graphicEntityModule.createText()
108 .setFillColor(0x12322a)
114 int stones = model.getStones();
116 stoneCounter.setText("Out of stones!");
117 stoneCounter.setFillColor(0xff7777);
119 else if (stones == 1) {
120 stoneCounter.setText("1 stone");
121 stoneCounter.setFillColor(0xffbb77);
124 stoneCounter.setText(stones + " stones");
128 void animateStones(int stones) {
129 stone.setX(castle.getX());
130 stone.setY(castle.getY() - 100);
131 stone.setText(new Integer(stones).toString());
133 graphicEntityModule.commitEntityState(0, stone);
135 int peakX = (castle.getX() + troll.getX()) / 2;
138 stone.setY(peakY, Curve.EASE_OUT);
139 graphicEntityModule.commitEntityState(0.25,
143 stone.setX(troll.getX());
144 stone.setY(troll.getY() - 50, Curve.EASE_IN);
145 stone.setAlpha(0, Curve.EASE_IN);
146 graphicEntityModule.commitEntityState(0.5, stone);
149 void displayMessage(String msg) {
150 message.setText(msg);
151 graphicEntityModule.commitEntityState(0, message);
155 avatar.setRotation(170*Math.PI/180, Curve.ELASTIC);
157 graphicEntityModule.commitEntityState(0.5, castle);
158 castle.setX(castle.getX(), Curve.ELASTIC);
159 castle.setScaleY(-0.2, Curve.EASE_IN);
164 Random random = new Random();
166 Text trollPositionGauge;
167 Player p0 = new Player(), p1 = new Player();
173 p0.init(gameManager.getPlayer(0));
174 p1.init(gameManager.getPlayer(1));
179 private void drawBackground() {
180 graphicEntityModule.createSprite()
181 .setImage("background.png")
185 private void drawTroll() {
186 troll = graphicEntityModule.createSprite()
187 .setImage("troll.png")
193 trollPositionGauge = graphicEntityModule.createText()
199 .setFillColor(0xffffff);
203 graphicEntityModule.commitEntityState(0.5, troll, trollPositionGauge);
204 int x0 = p0.castle.getX(), x1 = p1.castle.getX();
205 int y0 = p0.castle.getY(), y1 = p1.castle.getY();
206 troll.setX(x0 + model.trollPosition * (x1-x0) / model.roadLength,
208 troll.setY(y0 + model.trollPosition * (y1-y0) / model.roadLength,
211 trollPositionGauge.setX((trollPositionGauge.getX() + troll.getX()) / 2);
212 int delta = model.trollPosition - model.roadLength / 2;
214 trollPositionGauge.setText("← " + Math.abs(delta));
216 else if (delta > 0) {
217 trollPositionGauge.setText(Math.abs(delta) + " →");
220 trollPositionGauge.setText("↔");
222 graphicEntityModule.commitEntityState(0.75, trollPositionGauge);
223 trollPositionGauge.setX(troll.getX());