Tiles.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package pathgame.tilemap;
  2. import pathgame.gameplay.PlayerAbilities;
  3. /**
  4. * Static class for all existing tiles.
  5. *
  6. * @author kajetan
  7. */
  8. public class Tiles {
  9. public final static Tile GRASS = buildGrass();
  10. public final static Tile GRASS_WITH_STONE = buildGrass();
  11. public final static Tile GRASS_WITH_6_BUSHES = buildGrass();
  12. public final static Tile GRASS_WITH_3_BUSHES = buildGrass();
  13. public final static Tile GRASS_WITH_FLOWERS_1 = buildGrass();
  14. public final static Tile GRASS_WITH_FLOWERS_2 = buildGrass();
  15. public final static Tile GRASS_WITH_FLOWERS_3 = buildGrass();
  16. public final static Tile GRASS_WITH_FLOWERS_4 = buildGrass();
  17. public final static Tile GRASS_WITH_HILL = buildGrass();
  18. public final static Tile GRASS_WITH_EARTH = buildGrass();
  19. public final static Tile[] GRASS_VARIANTS = new Tile[]{
  20. GRASS, GRASS_WITH_STONE, GRASS_WITH_6_BUSHES, GRASS_WITH_3_BUSHES,
  21. GRASS_WITH_FLOWERS_1, GRASS_WITH_FLOWERS_2, GRASS_WITH_FLOWERS_3,
  22. GRASS_WITH_FLOWERS_4, GRASS_WITH_HILL, GRASS_WITH_EARTH
  23. };
  24. public final static Tile FOREST = Tile.TileBuilder.create()
  25. .setEnergyCost(4)
  26. .setForestReplaceChance(0.0f)
  27. .setSpeedUp((p) -> p.getAbilities().getFasterForest())
  28. .pathHost()
  29. .build();
  30. public final static Tile SWAMP = buildSwamp();
  31. public final static Tile SWAMP_DECO = buildSwamp();
  32. public final static Tile SWAMP_TREE = buildSwamp();
  33. public final static Tile SWAMP_BONES = buildSwamp();
  34. public final static Tile SHALLOW_WATER = Tile.TileBuilder.create()
  35. .setEnergyCost(6)
  36. .setForestReplaceChance(0.0f)
  37. .setSpeedUp((p)
  38. -> {
  39. if(p.isSailing()) {
  40. if(p.getAbilities() == PlayerAbilities.SAILOR) {
  41. return 5;
  42. }
  43. return 4;
  44. }
  45. return p.getAbilities().getFasterShallowWater();
  46. })
  47. .noTown()
  48. .setRenderType(TileRenderType.WATER)
  49. .setType(TileType.SHALLOW_WATER)
  50. .build();
  51. public final static Tile DEEP_WATER = Tile.TileBuilder.create()
  52. .setEnergyCost(2)
  53. .setForestReplaceChance(0.0f)
  54. .setSpeedUp((p) -> p.getAbilities().getFasterDeepWater())
  55. .noTown()
  56. .setRenderType(TileRenderType.WATER)
  57. .setType(TileType.DEEP_WATER)
  58. .build();
  59. public final static Tile HILL = Tile.TileBuilder.create()
  60. .setEnergyCost(6)
  61. .setForestReplaceChance(0.5f)
  62. .setSpeedUp((p) -> p.getAbilities().getFasterHill())
  63. .pathHost()
  64. .build();
  65. public final static Tile MOUNTAIN = Tile.TileBuilder.create()
  66. .setEnergyCost(9)
  67. .setForestReplaceChance(0.0f)
  68. .setSpeedUp((p) -> p.getAbilities().getFasterMountain())
  69. .noTown()
  70. .build();
  71. public final static Tile TOWN = new TileTown();
  72. public final static Tile TOWN_BLOCKED_1 = buildBlockedTown();
  73. public final static Tile TOWN_BLOCKED_2 = buildBlockedTown();
  74. public final static Tile TOWN_BLOCKED_3 = buildBlockedTown();
  75. public final static Tile TOWN_BLOCKED_4 = buildBlockedTown();
  76. public final static Tile[] TOWN_BLOCKED = new Tile[]{
  77. TOWN_BLOCKED_1, TOWN_BLOCKED_2, TOWN_BLOCKED_3, TOWN_BLOCKED_4
  78. };
  79. public final static Tile PORT = new TilePort();
  80. private final static Tile buildGrass() {
  81. return Tile.TileBuilder.create()
  82. .setSpeedUp((p) -> p.getAbilities().getFasterGrass())
  83. .pathHost()
  84. .setEnergyCost(3)
  85. .build();
  86. }
  87. private final static Tile buildSwamp() {
  88. return Tile.TileBuilder.create()
  89. .setEnergyCost(5)
  90. .setForestReplaceChance(0.0f)
  91. .setRenderType(TileRenderType.SWAMP)
  92. .setSpeedUp((p) -> p.getAbilities().getFasterSwamp())
  93. .build();
  94. }
  95. private final static Tile buildBlockedTown() {
  96. return Tile.TileBuilder.create()
  97. .setForestReplaceChance(0.0f)
  98. .noTown()
  99. .build();
  100. }
  101. public final static Tile HOME_TOWN = new TileHomeTown();
  102. private final static Tile buildPath() {
  103. return Tile.TileBuilder.create()
  104. .setForestReplaceChance(0.0f)
  105. .path()
  106. .build();
  107. }
  108. public final static Tile PATH_N_E_S_W = buildPath();
  109. public final static Tile PATH_N_E_S = buildPath();
  110. public final static Tile PATH_N_E_W = buildPath();
  111. public final static Tile PATH_N_E = buildPath();
  112. public final static Tile PATH_N_S_W = buildPath();
  113. public final static Tile PATH_N_S = buildPath();
  114. public final static Tile PATH_N_W = buildPath();
  115. public final static Tile PATH_N = buildPath();
  116. public final static Tile PATH_E_S_W = buildPath();
  117. public final static Tile PATH_E_S = buildPath();
  118. public final static Tile PATH_E_W = buildPath();
  119. public final static Tile PATH_E = buildPath();
  120. public final static Tile PATH_S_W = buildPath();
  121. public final static Tile PATH_S = buildPath();
  122. public final static Tile PATH_W = buildPath();
  123. public final static Tile[] PATH = new Tile[]{
  124. PATH_N_E_S_W, PATH_N_E_S, PATH_N_E_W, PATH_N_E,
  125. PATH_N_S_W, PATH_N_S, PATH_N_W, PATH_N,
  126. PATH_E_S_W, PATH_E_S, PATH_E_W, PATH_E,
  127. PATH_S_W, PATH_S, PATH_W, GRASS
  128. };
  129. /**
  130. * Returns a path with the given blocked directions.
  131. *
  132. * @param north true if there is a connection to the north tile
  133. * @param east true if there is a connection to the east tile
  134. * @param south true if there is a connection to the south tile
  135. * @param west true if there is a connection to the west tile
  136. * @return a path with the given blocked directions
  137. */
  138. public static Tile getPath(boolean north, boolean east, boolean south, boolean west) {
  139. return PATH[(north ? 0 : 8) + (east ? 0 : 4) + (south ? 0 : 2) + (west ? 0 : 1)];
  140. }
  141. }