Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. List<Rectangle> bounds= new ArrayList<Rectangle>();
  2.  
  3. for (int i = 0; i < 250; i++)
  4. {
  5. for (int j = 0; j < 250; j++)
  6. {
  7. TiledMapTileLayer cur = (TiledMapTileLayer) map.getLayers().get(1);
  8. Cell cell3 = new Cell();
  9.  
  10. if (cur.getCell(i, j) != null)
  11. {
  12. cell3 = cur.getCell(i, j);
  13. System.out.println("Found a chest detector at: " + i + ", " + j
  14. + ", " + cell3.getTile().getId());
  15. bounds.add(new Rectangle(i * 64, j * 64, 64, 64));
  16. }
  17. }
  18. }
  19.  
  20.  
  21. // CHECKING FOR TREES
  22. for (int i = 0; i < bounds.size(); i++)
  23. {
  24. if (bounds.get(i).overlaps(player.getBounds()))
  25. {
  26. int x = (int) bounds.get(i).x / 64;
  27. int y = (int) bounds.get(i).y / 64;
  28.  
  29. TiledMapTileLayer cur = (TiledMapTileLayer) map.getLayers()
  30. .get(1);
  31. Cell cell = cur.getCell(x, y);
  32.  
  33. if (cell.getTile().getProperties().containsKey("Green"))
  34. {
  35. if (Gdx.input.isKeyPressed(Keys.SPACE))
  36. {
  37. System.out.println("You've cut down a tree!");
  38. }
  39. }
  40. if (cell.getTile().getProperties().containsKey("Gray"))
  41. {
  42. player.reAdjust();
  43. }
  44. }
  45. }
  46.  
  47. String movement = "";
  48.  
  49. if (Gdx.input.isKeyPressed(Keys.W))
  50. {
  51. if (curEnergy > 0)
  52. {
  53. if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
  54. {
  55. position.y += 2.5f;
  56. movement = "up";
  57. curEnergy--;
  58.  
  59. currentFrame = animation.getKeyFrame(12 + stateTime);
  60. }
  61. }
  62. else
  63. {
  64. allowRegen = true;
  65. checkIfEnergyIsZero();
  66. }
  67. position.y += 2f;
  68. movement = "up";
  69. currentFrame = animation.getKeyFrame(12 + stateTime);
  70. }
  71.  
  72. if (Gdx.input.isKeyPressed(Keys.A))
  73. {
  74. if (curEnergy > 0)
  75. {
  76. if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
  77. {
  78. position.x -= 2.5f;
  79. movement = "left";
  80. curEnergy--;
  81. currentFrame = animation.getKeyFrame(4 + stateTime);
  82. }
  83. }
  84. else
  85. {
  86. allowRegen = true;
  87. checkIfEnergyIsZero();
  88. }
  89. position.x -= 2f;
  90. movement = "left";
  91. currentFrame = animation.getKeyFrame(4 + stateTime);
  92. }
  93.  
  94. if (Gdx.input.isKeyPressed(Keys.D))
  95. {
  96. if (curEnergy > 0)
  97. {
  98. if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
  99. {
  100. position.x += 2.5f;
  101. movement = "right";
  102. curEnergy--;
  103. currentFrame = animation.getKeyFrame(8 + stateTime);
  104. }
  105. }
  106. else
  107. {
  108. allowRegen = true;
  109. checkIfEnergyIsZero();
  110. }
  111. position.x += 2f;
  112. movement = "right";
  113. currentFrame = animation.getKeyFrame(8 + stateTime);
  114. }
  115.  
  116. if (Gdx.input.isKeyPressed(Keys.S))
  117. {
  118. if (curEnergy > 0)
  119. {
  120. if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT))
  121. {
  122. position.y -= 2.5f;
  123. movement = "down";
  124. curEnergy--;
  125. currentFrame = animation.getKeyFrame(0 + stateTime);
  126. }
  127. }
  128. else
  129. {
  130. allowRegen = true;
  131. checkIfEnergyIsZero();
  132. }
  133. position.y -= 2f;
  134. movement = "down";
  135. currentFrame = animation.getKeyFrame(0 + stateTime);
  136. }
  137. }
  138.  
  139. public void reAdjust()
  140. {
  141. if (movement == "up") {
  142. position.y -= 2f;
  143. }
  144. if (movement == "down") {
  145. position.y += 2f;
  146. }
  147. if (movement == "right") {
  148. position.x -= 2f;
  149. }
  150. if (movement == "left") {
  151. position.x += 2f;
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement