From: JBM Date: Mon, 25 May 2020 12:19:39 +0000 (+0200) Subject: More trees (same contributor) X-Git-Url: https://troll.desast.re/troll.git/commitdiff_plain/a1f14c4c156f093f81db62e27d0810df250a1b46?ds=inline;hp=bea135ec39ff862fb25b4f99e8c7d48eb44134f2 More trees (same contributor) --- diff --git a/src/main/java/com/codingame/game/View.java b/src/main/java/com/codingame/game/View.java index 8653ab4..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,12 +215,18 @@ 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(101); + int numTrees = random.nextInt(21); + ArrayList poss = new ArrayList(numTrees); while (numTrees --> 0) { int x, y; do { @@ -226,16 +234,25 @@ class View { // yes, this biases randomness wrt perspective! :-( y = 700 + random.nextInt(175); } while (y > 880 && (x < 200 || x > 1720)); - double scale = ( 100.0 / 433.0 // base height from PNG - * (y - 680) / (875 - 680) ); // perspective + 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("Alshock.png") + .setImage(random.nextInt(2) == 0 ? "Alshockv1.png" + : "Alshockv2.png") .setAnchorX(0.5) .setAnchorY(1) - .setX(x) - .setY(y) - .setScaleX(scale * (random.nextInt(2) == 0 ? -1 : 1)) - .setScaleY(scale) + .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); diff --git a/src/main/resources/view/assets/Alshock.png b/src/main/resources/view/assets/Alshockv1.png similarity index 100% rename from src/main/resources/view/assets/Alshock.png rename to src/main/resources/view/assets/Alshockv1.png diff --git a/src/main/resources/view/assets/Alshockv2.png b/src/main/resources/view/assets/Alshockv2.png new file mode 100644 index 0000000..fe447c7 Binary files /dev/null and b/src/main/resources/view/assets/Alshockv2.png differ