X-Git-Url: https://troll.desast.re/troll.git/blobdiff_plain/d20fd565ca9fd9b1476469c29a9a3104163cd58c..1b2f76237b137aedd6c447580412a3b93d50a9bf:/src/main/java/com/codingame/game/View.java?ds=inline diff --git a/src/main/java/com/codingame/game/View.java b/src/main/java/com/codingame/game/View.java index 21489ff..d3d51d1 100644 --- a/src/main/java/com/codingame/game/View.java +++ b/src/main/java/com/codingame/game/View.java @@ -1,6 +1,8 @@ package com.codingame.game; import java.util.Random; +import java.util.ArrayList; +import java.util.Comparator; import com.codingame.gameengine.core.MultiplayerGameManager; import com.codingame.gameengine.module.entities.GraphicEntityModule; @@ -213,10 +215,48 @@ class View { p1.startTurn(); } + private class Pos { + int x, y; + Pos(int _x, int _y) { x = _x; y = _y; } + } + private void drawBackground() { graphicEntityModule.createSprite() .setImage("background.png") .setAnchor(0); + + int numTrees = random.nextInt(21); + ArrayList poss = new ArrayList(numTrees); + while (numTrees --> 0) { + int x, y; + do { + x = random.nextInt(1920); + // yes, this biases randomness wrt perspective! :-( + y = 700 + random.nextInt(175); + } while (y > 880 && (x < 200 || x > 1720)); + poss.add(new Pos(x, y)); + } + poss.sort(new Comparator() { + public int compare(Pos a, Pos b) { return a.y < b.y ? -1 : 1; } + }); + + for (Pos p : poss) { + double scale = ( 90.0 / 433.0 // base height from PNG + * (p.y - 680) / (875 - 680) ); // perspective + graphicEntityModule.createSprite() + .setImage(random.nextInt(2) == 0 ? "Alshockv1.png" + : "Alshockv2.png") + .setAnchorX(0.5) + .setAnchorY(1) + .setX(p.x) + .setY(p.y) + .setScaleX(scale * (random.nextInt(2) == 0 ? -1 : 1) + * (1 + (random.nextDouble() - 0.5) / 6)) + .setScaleY(scale * (1 + (random.nextDouble() -0.5) / 6)) + .setRotation((random.nextDouble() - 0.5) * Math.PI / 1800) + .setSkewX((random.nextDouble() - 0.5) /4) + .setSkewY((random.nextDouble() - 0.5) /8); + } } private void drawTroll() {