Kajetan Johannes Hammerle 4 anos atrás
pai
commit
9fa8613e90

+ 12 - 0
src/pathgame/rendering/TileRenderer.java

@@ -4,6 +4,10 @@ import pathgame.tilemap.Tile;
 import pathgame.tilemap.TileMap;
 import pathgame.tilemap.Tiles;
 
+/** Registry for rendering all possible tiles.
+ *
+ * @author kajetan
+ */
 public class TileRenderer
 {
     /** The unscaled render size of a map tile. */
@@ -68,6 +72,14 @@ public class TileRenderer
         register(Tiles.PATH_N_E_S_W, new StaticTextureProvider(TileTexture.fromTextureId(38)));
     }
     
+    /** Returns a tile texture of a given map tile.
+     *
+     * @param map a map
+     * @param t a tile
+     * @param x the x coordinate of the given tile
+     * @param y the y coordinate of the given tile
+     * @return a tile texture of a given map tile
+     */
     public static TileTexture getTileTexture(TileMap map, Tile t, int x, int y)
     {
         if(t == null)

+ 17 - 0
src/pathgame/tilemap/HighMap.java

@@ -2,11 +2,22 @@ package pathgame.tilemap;
 
 import java.util.Random;
 
+/** Class for generating two dimensional highmaps of arbitrary size.
+ *
+ * @author kajetan
+ */
 public class HighMap
 {
     private static final float LOW_FREQUENCY = 8.0f;
     private static final float HIGH_FREQUENCY = 7.0f;
     
+    /** Returns a generated highmap.
+     *
+     * @param seed the seed for the highmap
+     * @param width the width of the highmap
+     * @param height the height of the highmap
+     * @return a generated highmap
+     */
     public static HighMap generate(long seed, int width, int height)
     {
         HighMap map = new HighMap(seed, width, height);
@@ -27,6 +38,12 @@ public class HighMap
         this.data = new float[width][height];
     }
     
+    /** Returns the value at the given position.
+     *
+     * @param x the x coordinate of a position
+     * @param y the y coordinate of a position
+     * @return the value at the given position
+     */
     public float get(int x, int y)
     {
         return data[x][y];

+ 58 - 0
src/pathgame/tilemap/Tile.java

@@ -9,6 +9,10 @@ import pathgame.gameplay.Player;
  */
 public class Tile
 {
+
+    /** A builder for tiles.
+     *
+     */
     public static class TileBuilder
     {
         private int energyCost = 2;
@@ -25,65 +29,114 @@ public class Tile
         {
         }
         
+        /** Returns a new tile builder;
+         *
+         * @return a new tile builder
+         */
         public static TileBuilder create()
         {
             return new TileBuilder();
         }
 
+        /** Sets the base energy cost of the tile.
+         *
+         * @param energyCost the base energy cost of the tile.
+         * @return the tile builder
+         */
         public TileBuilder setEnergyCost(int energyCost)
         {
             this.energyCost = energyCost;
             return this;
         }
 
+        /** Sets the chance that the tile can be replaced by forest.
+         *
+         * @param forestReplaceChance the chance that the tile can be replaced by forest.
+         * @return the tile builder
+         */
         public TileBuilder setForestReplaceChance(float forestReplaceChance)
         {
             this.forestReplaceChance = forestReplaceChance;
             return this;
         }
 
+        /** Sets the function for handling speed ups.
+         *
+         * @param speedUp a function.
+         * @return the tile builder
+         */
         public TileBuilder setSpeedUp(Function<Player, Integer> speedUp)
         {
             this.speedUp = speedUp;
             return this;
         }
 
+        /** Marks the tile as non host for towns.
+         *
+         * @return the tile builder
+         */
         public TileBuilder noTown()
         {
             this.canHostTown = false;
             return this;
         }
         
+        /** Marks the tile as blocked for every movement.
+         *
+         * @return the tile builder
+         */
         public TileBuilder noMovement()
         {
             this.blocksMovement = true;
             return this;
         }
         
+        /** Sets the type of the tile.
+         *
+         * @param type a tile type
+         * @return the tile builder
+         */
         public TileBuilder setType(TileType type)
         {
             this.type = type;
             return this;
         }
         
+        /** Marks the tile as host for paths.
+         *
+         * @return the tile builder
+         */
         public TileBuilder pathHost()
         {
             this.canHostPath = true;
             return this;
         }
         
+        /** Marks the tile as path.
+         *
+         * @return the tile builder
+         */
         public TileBuilder path()
         {
             this.path = true;
             return this;
         }
         
+        /** Sets the render type of the tile.
+         *
+         * @param type a render type
+         * @return the tile builder
+         */
         public TileBuilder setRenderType(TileRenderType type)
         {
             this.renderType = type;
             return this;
         }
         
+        /** Returns the built tile.
+         *
+         * @return the built tile.
+         */
         public Tile build()
         {
             return new Tile(energyCost, forestReplaceChance, speedUp, canHostTown, blocksMovement, type, canHostPath, path, renderType);
@@ -155,6 +208,11 @@ public class Tile
         return id;
     }
     
+    /** Returns the energy cost of a player on this tile.
+     *
+     * @param p a player
+     * @return the energy cost of a player on this tile
+     */
     public int getEnergyCost(Player p)
     {
         return energyCost - speedUp.apply(p);

+ 4 - 0
src/pathgame/tilemap/TileHomeTown.java

@@ -2,6 +2,10 @@ package pathgame.tilemap;
 
 import pathgame.gameplay.Player;
 
+/** Class for home towns to have special behaviour.
+ *
+ * @author kajetan
+ */
 public class TileHomeTown extends Tile
 {
     public TileHomeTown()

+ 4 - 1
src/pathgame/tilemap/TileMap.java

@@ -106,6 +106,9 @@ public class TileMap
         dirty = false;
     }
     
+    /** Ticks the tilemap.
+     *
+     */
     public void tick()
     {
         Iterator<TownConverter> iter = townConverters.iterator();
@@ -126,7 +129,7 @@ public class TileMap
         }
     }
     
-    /** Slowly Converts a tile into blocked town.
+    /** Slowly converts a tile into blocked town.
      *
      * @param x the x coordinate of the tile
      * @param y the y coordinate of the tile

+ 4 - 0
src/pathgame/tilemap/TileMapGenerator.java

@@ -3,6 +3,10 @@ package pathgame.tilemap;
 import java.util.ArrayList;
 import java.util.Random;
 
+/** Static class to generate tile maps.
+ *
+ * @author kajetan
+ */
 public class TileMapGenerator
 {
     private static long seed = 1;

+ 4 - 0
src/pathgame/tilemap/TilePort.java

@@ -3,6 +3,10 @@ package pathgame.tilemap;
 import pathgame.gameplay.Keys;
 import pathgame.gameplay.Player;
 
+/** Class for ports to have special behaviour.
+ *
+ * @author kajetan
+ */
 public class TilePort extends Tile
 {
     public TilePort()

+ 4 - 0
src/pathgame/tilemap/TileRenderType.java

@@ -1,5 +1,9 @@
 package pathgame.tilemap;
 
+/** Rendering types of tiles used for deciding which overlay should be used.
+ *
+ * @author kajetan
+ */
 public enum TileRenderType
 {
     WATER, SWAMP, NORMAL

+ 4 - 0
src/pathgame/tilemap/TileTown.java

@@ -2,6 +2,10 @@ package pathgame.tilemap;
 
 import pathgame.gameplay.Player;
 
+/** Class for towns to have special behaviour.
+ *
+ * @author kajetan
+ */
 public class TileTown extends Tile
 {
     public TileTown()

+ 5 - 0
src/pathgame/tilemap/TileType.java

@@ -1,5 +1,10 @@
 package pathgame.tilemap;
 
+/** Types of tiles used for deciding if a player can enter this tile in their
+ * current state.
+ *
+ * @author kajetan
+ */
 public enum TileType
 {
     PORT, LAND, SHALLOW_WATER, DEEP_WATER

+ 16 - 4
src/pathgame/tilemap/Tiles.java

@@ -2,6 +2,10 @@ package pathgame.tilemap;
 
 import pathgame.gameplay.PlayerAbilities;
 
+/** Static class for all existing tiles.
+ *
+ * @author kajetan
+ */
 public class Tiles
 {
 
@@ -86,7 +90,7 @@ public class Tiles
 
     public final static Tile PORT = new TilePort();
 
-    public final static Tile buildGrass()
+    private final static Tile buildGrass()
     {
         return Tile.TileBuilder.create()
                 .setSpeedUp((p) -> p.getAbilities().getFasterGrass())
@@ -95,7 +99,7 @@ public class Tiles
                 .build();
     }
 
-    public final static Tile buildSwamp()
+    private final static Tile buildSwamp()
     {
         return Tile.TileBuilder.create()
                 .setEnergyCost(5)
@@ -105,7 +109,7 @@ public class Tiles
                 .build();
     }
 
-    public final static Tile buildBlockedTown()
+    private final static Tile buildBlockedTown()
     {
         return Tile.TileBuilder.create()
                 .setForestReplaceChance(0.0f)
@@ -115,7 +119,7 @@ public class Tiles
 
     public final static Tile HOME_TOWN = new TileHomeTown();
 
-    public final static Tile buildPath()
+    private final static Tile buildPath()
     {
         return Tile.TileBuilder.create()
                 .setForestReplaceChance(0.0f)
@@ -147,6 +151,14 @@ public class Tiles
         PATH_S_W, PATH_S, PATH_W, GRASS
     };
 
+    /** Returns a path with the given blocked directions.
+     *
+     * @param north true if there is a connection to the north tile
+     * @param east true if there is a connection to the east tile
+     * @param south true if there is a connection to the south tile
+     * @param west true if there is a connection to the west tile
+     * @return a path with the given blocked directions
+     */
     public static Tile getPath(boolean north, boolean east, boolean south, boolean west)
     {
         return PATH[(north ? 0 : 8) + (east ? 0 : 4) + (south ? 0 : 2) + (west ? 0 : 1)];