You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

120 lines
2.6 KiB

  1. package structures.basic;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import com.fasterxml.jackson.annotation.JsonIgnore;
  6. import com.fasterxml.jackson.databind.ObjectMapper;
  7. /**
  8. * A basic representation of a tile on the game board. Tiles have both a pixel position
  9. * and a grid position. Tiles also have a width and height in pixels and a series of urls
  10. * that point to the different renderable textures that a tile might have.
  11. *
  12. * @author Dr. Richard McCreadie
  13. *
  14. */
  15. public class Tile {
  16. @JsonIgnore
  17. private static ObjectMapper mapper = new ObjectMapper(); // Jackson Java Object Serializer, is used to read java objects from a file
  18. List<String> tileTextures;
  19. int xpos;
  20. int ypos;
  21. int width;
  22. int height;
  23. int tilex;
  24. int tiley;
  25. public Tile() {}
  26. public Tile(String tileTexture, int xpos, int ypos, int width, int height, int tilex, int tiley) {
  27. super();
  28. tileTextures = new ArrayList<String>(1);
  29. tileTextures.add(tileTexture);
  30. this.xpos = xpos;
  31. this.ypos = ypos;
  32. this.width = width;
  33. this.height = height;
  34. this.tilex = tilex;
  35. this.tiley = tiley;
  36. }
  37. public Tile(List<String> tileTextures, int xpos, int ypos, int width, int height, int tilex, int tiley) {
  38. super();
  39. this.tileTextures = tileTextures;
  40. this.xpos = xpos;
  41. this.ypos = ypos;
  42. this.width = width;
  43. this.height = height;
  44. this.tilex = tilex;
  45. this.tiley = tiley;
  46. }
  47. public List<String> getTileTextures() {
  48. return tileTextures;
  49. }
  50. public void setTileTextures(List<String> tileTextures) {
  51. this.tileTextures = tileTextures;
  52. }
  53. public int getXpos() {
  54. return xpos;
  55. }
  56. public void setXpos(int xpos) {
  57. this.xpos = xpos;
  58. }
  59. public int getYpos() {
  60. return ypos;
  61. }
  62. public void setYpos(int ypos) {
  63. this.ypos = ypos;
  64. }
  65. public int getWidth() {
  66. return width;
  67. }
  68. public void setWidth(int width) {
  69. this.width = width;
  70. }
  71. public int getHeight() {
  72. return height;
  73. }
  74. public void setHeight(int height) {
  75. this.height = height;
  76. }
  77. public int getTilex() {
  78. return tilex;
  79. }
  80. public void setTilex(int tilex) {
  81. this.tilex = tilex;
  82. }
  83. public int getTiley() {
  84. return tiley;
  85. }
  86. public void setTiley(int tiley) {
  87. this.tiley = tiley;
  88. }
  89. /**
  90. * Loads a tile from a configuration file
  91. * parameters.
  92. * @param configFile
  93. * @return
  94. */
  95. public static Tile constructTile(String configFile) {
  96. try {
  97. Tile tile = mapper.readValue(new File(configFile), Tile.class);
  98. return tile;
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. }
  102. return null;
  103. }
  104. }