More trees (same contributor)
authorJBM <jbm@codingame.com>
Mon, 25 May 2020 12:19:39 +0000 (14:19 +0200)
committerJBM <jbm@codingame.com>
Wed, 27 May 2020 14:56:46 +0000 (16:56 +0200)
src/main/java/com/codingame/game/View.java
src/main/resources/view/assets/Alshockv1.png [moved from src/main/resources/view/assets/Alshock.png with 100% similarity]
src/main/resources/view/assets/Alshockv2.png [new file with mode: 0644]

index 8653ab4..d3d51d1 100644 (file)
@@ -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<Pos> poss = new ArrayList<Pos>(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<Pos>() {
+                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/Alshockv2.png b/src/main/resources/view/assets/Alshockv2.png
new file mode 100644 (file)
index 0000000..fe447c7
Binary files /dev/null and b/src/main/resources/view/assets/Alshockv2.png differ