Guest User

Untitled

a guest
Jun 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. public class move
  2. {
  3. float posX;
  4. float posY;
  5. float touchedOnScreenX;
  6. float touchedOnScreenY;
  7. float centerOfScreenX;
  8. float centerOfScreenY;
  9. float posXSetter;
  10. float posYSetter;
  11. float Speed = 150;
  12. float mapBoundsWidth;
  13. float mapBoundsHeight;
  14. boolean upperBounds;
  15. boolean lowerBounds;
  16. boolean rightBounds;
  17. boolean leftBounds;
  18. boolean tileCollition;
  19.  
  20.  
  21.  
  22. public move() {
  23.  
  24. }
  25.  
  26. public void renderMove(float delta) {
  27.  
  28.  
  29. if(Gdx.input.isTouched()) {
  30. screenAndTouchInfo();
  31. checkBoundsBoolean();
  32. checkForCollision();
  33. }
  34. }
  35.  
  36. //slows game down
  37. private void checkForCollision()
  38. {
  39. if (upperBounds == false)
  40. {
  41. if (lowerBounds == false)
  42. {
  43. if (rightBounds == false)
  44. {
  45. if (leftBounds == false)
  46. {
  47. if (tileCollition == false)
  48. {
  49. movement();
  50. }
  51. else
  52. {
  53. collitionSide();
  54. }
  55. }
  56. else
  57. {
  58. posX++;
  59. }
  60. }
  61. else
  62. {
  63. posX--;
  64. }
  65. }
  66. else
  67. {
  68. posY++;
  69. }
  70. }
  71. else
  72. {
  73. posY --;
  74. }
  75. }
  76.  
  77. private void movement()
  78. {
  79. posYSetter = posY;
  80. posXSetter = posX;
  81. if (touchedOnScreenX < centerOfScreenX)
  82. {
  83. posX -= Gdx.graphics.getDeltaTime() * Speed;
  84.  
  85. }
  86. else
  87. {
  88. posX += Gdx.graphics.getDeltaTime() * Speed;
  89.  
  90. }
  91. if (touchedOnScreenY < centerOfScreenY)
  92. {
  93. posY -= Gdx.graphics.getDeltaTime() * Speed;
  94.  
  95. }
  96. else
  97. {
  98. posY += Gdx.graphics.getDeltaTime() * Speed;
  99.  
  100. }
  101. if (touchedOnScreenY < centerOfScreenY + 64 && touchedOnScreenY > centerOfScreenY - 64)
  102. {
  103. posY = posYSetter;
  104.  
  105. }
  106. if (touchedOnScreenX < centerOfScreenX + 64 && touchedOnScreenX > centerOfScreenX - 64)
  107. {
  108. posX = posXSetter;
  109.  
  110. }
  111. }
  112.  
  113. //buggy and slows game down. Can push you into tile if input is the opposite of the side
  114. public void collitionSide() {
  115. if (tileCollition == true){
  116. if (touchedOnScreenX < centerOfScreenX)
  117. {
  118. posX = posX +10;
  119. }
  120. else
  121. {
  122. posX = posX - 10;
  123.  
  124. }
  125. if (touchedOnScreenY < centerOfScreenY)
  126. {
  127. posY = posY +10;
  128. }
  129. else
  130. {
  131. posY = posY -10;
  132. }
  133. }
  134. }
  135.  
  136. private void screenAndTouchInfo()
  137. {
  138. touchedOnScreenX = Gdx.input.getX();
  139. touchedOnScreenY = (Gdx.graphics.getHeight() - Gdx.input.getY());
  140. centerOfScreenX = Gdx.graphics.getWidth() / 2;
  141. centerOfScreenY = Gdx.graphics.getHeight() / 2;
  142. }
  143. //slows game down
  144. private void checkBoundsBoolean()
  145. {
  146. if (posX > mapBoundsWidth)
  147. {
  148. rightBounds = true;
  149. }
  150. else {
  151. rightBounds = false;
  152. }
  153. if (posY > mapBoundsHeight)
  154. {
  155. upperBounds = true;
  156. }
  157. else {
  158. upperBounds = false;
  159. }
  160. if (posX < mapBoundsWidth - mapBoundsWidth)
  161. {
  162. leftBounds = true;
  163. }
  164. else {
  165. leftBounds = false;
  166. }
  167. if (posY < mapBoundsHeight - mapBoundsHeight)
  168. {
  169. lowerBounds = true;
  170. }
  171. else {
  172. lowerBounds = false;
  173. }
  174. }
  175.  
  176. public void setTileCollision(boolean tileCollision) {
  177. this.tileCollition = tileCollision;
  178. }
  179.  
  180. public float getPosX() {
  181. return posX;
  182. }
  183.  
  184. public float getPosY() {
  185. return posY;
  186. }
  187.  
  188. public float getTouchedOnScreenX() {
  189. return touchedOnScreenX;
  190. }
  191.  
  192. public float getTouchedOnScreenY() {
  193. return touchedOnScreenY;
  194. }
  195.  
  196. public float getCenterOfScreenX() {
  197. return centerOfScreenX;
  198. }
  199.  
  200. public float getCenterOfScreenY() {
  201. return centerOfScreenY;
  202. }
  203.  
  204. public void setMapboundsWidth(float width) {
  205. this.mapBoundsWidth = width;
  206. }
  207.  
  208. public void setMapboundsHeight(float height) {
  209. this.mapBoundsHeight = height;
  210. }
  211. }
Add Comment
Please, Sign In to add comment