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 Rectangle border1 = graphicEntityModule
47 .setFillColor(colorToken);
49 Rectangle border2 = graphicEntityModule
56 .setFillColor(0xffffff);
58 Sprite avatarSprite = graphicEntityModule.createSprite()
62 .setImage(avatarToken)
67 avatar = graphicEntityModule.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("No stones!");
117 stoneCounter.setFillColor(0xff7777);
119 else if (stones == 1) {
120 stoneCounter.setText("1 stone");
121 stoneCounter.setFillColor(0xffbb77);
124 stoneCounter.setText(stones + " stones");
127 void animateStones(int stones) {
128 stone.setX(castle.getX());
129 stone.setY(castle.getY() - 100);
130 stone.setText(new Integer(stones).toString());
132 graphicEntityModule.commitEntityState(0, stone);
134 int peakX = (castle.getX() + troll.getX()) / 2;
137 stone.setY(peakY, Curve.EASE_OUT);
138 graphicEntityModule.commitEntityState(0.25,
142 stone.setX(troll.getX());
143 stone.setY(troll.getY() - 50, Curve.EASE_IN);
144 stone.setAlpha(0, Curve.EASE_IN);
145 graphicEntityModule.commitEntityState(0.5, stone);
147 void displayMessage(String msg) {
148 message.setText(msg);
149 graphicEntityModule.commitEntityState(0, message);
153 avatar.setRotation(170*Math.PI/180, Curve.ELASTIC);
155 graphicEntityModule.commitEntityState(0.5, castle);
156 castle.setX(castle.getX(), Curve.ELASTIC);
157 castle.setScaleY(-0.2, Curve.EASE_IN);
162 Random random = new Random();
164 Text trollPositionGauge;
165 Player p0 = new Player(), p1 = new Player();
169 p0.init(gameManager.getPlayer(0));
170 p1.init(gameManager.getPlayer(1));
176 private void drawBackground() {
177 graphicEntityModule.createSprite()
178 .setImage("background.png")
182 private void drawTroll() {
183 troll = graphicEntityModule.createSprite()
184 .setImage("troll.png")
190 trollPositionGauge = graphicEntityModule.createText()
196 .setFillColor(0xffffff);
200 graphicEntityModule.commitEntityState(0.5, troll, trollPositionGauge);
201 int x0 = p0.castle.getX(), x1 = p1.castle.getX();
202 int y0 = p0.castle.getY(), y1 = p1.castle.getY();
203 troll.setX(x0 + model.trollPosition * (x1-x0) / model.roadLength,
205 troll.setY(y0 + model.trollPosition * (y1-y0) / model.roadLength,
208 trollPositionGauge.setX((trollPositionGauge.getX() + troll.getX()) / 2);
209 int delta = model.trollPosition - model.roadLength / 2;
211 trollPositionGauge.setText("← " + Math.abs(delta));
213 else if (delta > 0) {
214 trollPositionGauge.setText(Math.abs(delta) + " →");
217 trollPositionGauge.setText("↔");
219 graphicEntityModule.commitEntityState(0.75, trollPositionGauge);
220 trollPositionGauge.setX(troll.getX());