Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.44 KB | None | 0 0
  1. public class MyDemo
  2. {
  3. public static void main(String[]args)
  4. {
  5. int Counter=0, AnimY, AnimX, Menu=0, Distance=0, XPosit=0, YPosit=0, XSize=0, YSize=0, Movement=0;
  6. boolean Binary = true;
  7. System.out.println("How tall would you like the animation to be?");
  8. AnimY = IO.readInt();
  9. System.out.println("How wide would you like the animation to be?");
  10. AnimX = IO.readInt();
  11. Animation Demo = new Animation(1000, 600);
  12. Demo.setBackgroundImage("tunnel-background.jpg");
  13. Demo.setFrameRate(2);
  14. Demo.frameFinished();
  15. Sprite One = new Sprite("sailor.jpg");
  16. Demo.addSprite(One);
  17. One.setPosition(100, 100);
  18. Sprite Two = new Sprite("army.png");
  19. Demo.addSprite(Two);
  20. Two.setPosition(300, 100);
  21. Sprite Three = new Sprite("RSS.gif");
  22. Demo.addSprite(Three);
  23. Three.setPosition(500, 100);
  24. Sprite Current=null;
  25. Demo.frameFinished();
  26. while (Binary)
  27. {
  28. Menu = 0;
  29. //Menu
  30. System.out.println("Would you like to move sprite #1, #2, or #3? Press anything else to exit.");
  31. Menu = IO.readInt();
  32. if (Menu >3 || Menu < 1)
  33. {
  34. Binary = false;
  35. break;
  36. }
  37. //Sprite controls
  38. if (Menu == 1)
  39. {
  40. Current = One;
  41. }
  42. else if (Menu == 2)
  43. {
  44. Current = Two;
  45. }
  46. else if (Menu == 3)
  47. {
  48. Current = Three;
  49. }
  50. /*
  51. else
  52. {
  53. Binary = false;
  54.  
  55. }
  56. */
  57. if (Binary)
  58. {
  59. System.out.println("Press 1 if you would like to move up, 2 if you would like to move right, 3 if you would like to move down, and 4 if you would like to move left.");
  60. Menu = IO.readInt();
  61. if (Menu >4 || Menu < 1)
  62. {
  63. IO.reportBadInput();
  64. System.out.println("I'm sorry, Dave; I can't let you do that.");
  65. }
  66. else
  67. {
  68. System.out.println("How far would you like to move?");
  69. Distance = IO.readInt();
  70. YPosit = Current.getYposition();
  71. XPosit = Current.getXposition();
  72. XSize = Current.getXsize();
  73. YSize = Current.getYsize();
  74. }
  75.  
  76. if (Menu == 1)
  77. {
  78. YPosit = YPosit+Distance;
  79. Current.setPosition(XPosit, YPosit);
  80. //Interference Check
  81. if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
  82. Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
  83. {
  84. YPosit = YPosit - Distance;
  85. Current.setPosition(XPosit, YPosit);
  86. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  87. }
  88. if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
  89. Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
  90. {
  91. YPosit = YPosit - Distance;
  92. Current.setPosition(XPosit, YPosit);
  93. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  94. }
  95. if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
  96. Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
  97. {
  98. YPosit = YPosit - Distance;
  99. Current.setPosition(XPosit, YPosit);
  100. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  101. }
  102. if ((Current.getYposition() < 0) || (Current.getYposition() > AnimX))
  103. {
  104. YPosit = YPosit - Distance;
  105. Current.setPosition(XPosit, YPosit);
  106. System.out.println("Oh, no! You can't go off the screen!");
  107. }
  108.  
  109. }
  110. if (Menu == 2)
  111. {
  112. XPosit = XPosit+Distance;
  113. Current.setPosition(XPosit, YPosit);
  114. //Interference Check
  115. if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
  116. Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
  117. {
  118. XPosit = XPosit - Distance;
  119. Current.setPosition(XPosit, YPosit);
  120. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  121. }
  122. if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
  123. Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
  124. {
  125. XPosit = XPosit - Distance;
  126. Current.setPosition(XPosit, YPosit);
  127. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  128. }
  129. if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
  130. Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
  131. {
  132. XPosit = XPosit - Distance;
  133. Current.setPosition(XPosit, YPosit);
  134. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  135. }
  136. if ((Current.getXposition() < 0) || (Current.getXposition() > AnimX))
  137. {
  138. XPosit = XPosit - Distance;
  139. Current.setPosition(XPosit, YPosit);
  140. System.out.println("Oh, no! You can't go off the screen!");
  141. }
  142. }
  143. if (Menu == 3)
  144. {
  145. YPosit = YPosit-Distance;
  146. Current.setPosition(XPosit, YPosit);
  147. //Interference Check
  148. if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
  149. Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
  150. {
  151. YPosit = YPosit + Distance;
  152. Current.setPosition(XPosit, YPosit);
  153. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  154. }
  155. else if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
  156. Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
  157. {
  158. YPosit = YPosit + Distance;
  159. Current.setPosition(XPosit, YPosit);
  160. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  161. }
  162. else if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
  163. Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
  164. {
  165. YPosit = YPosit + Distance;
  166. Current.setPosition(XPosit, YPosit);
  167. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  168. }
  169. if ((Current.getYposition() < 0) || (Current.getYposition() > AnimX))
  170. {
  171. YPosit = YPosit + Distance;
  172. Current.setPosition(XPosit, YPosit);
  173. System.out.println("Oh, no! You can't go off the screen!");
  174. }
  175. }
  176. if (Menu == 4)
  177. {
  178. XPosit = XPosit-Distance;
  179. Current.setPosition(XPosit, YPosit);
  180. //Interference Check
  181. if (Math.abs(One.getXposition() - Two.getXposition()) < Math.max(One.getXsize(), Two.getXsize()) &&
  182. Math.abs(One.getYposition() - Two.getYposition()) < Math.max(One.getYsize(), Two.getYsize()))
  183. {
  184. XPosit = XPosit + Distance;
  185. Current.setPosition(XPosit, YPosit);
  186. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  187. }
  188. if (Math.abs(Two.getXposition() - Three.getXposition()) < Math.max(Two.getXsize(), Three.getXsize()) &&
  189. Math.abs(Two.getYposition() - Three.getYposition()) < Math.max(Two.getYsize(), Three.getYsize()))
  190. {
  191. XPosit = XPosit + Distance;
  192. Current.setPosition(XPosit, YPosit);
  193. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  194. }
  195. if (Math.abs(One.getXposition() - Three.getXposition()) < Math.max(One.getXsize(), Three.getXsize()) &&
  196. Math.abs(One.getYposition() - Three.getYposition()) < Math.max(One.getYsize(), Three.getYsize()))
  197. {
  198. XPosit = XPosit + Distance;
  199. Current.setPosition(XPosit, YPosit);
  200. System.out.println("I'm sorry; you would bump into another sprite and we wouldn't want that.");
  201. }
  202. if ((Current.getXposition() < 0) || (Current.getXposition() > AnimX))
  203. {
  204. XPosit = XPosit + Distance;
  205. Current.setPosition(XPosit, YPosit);
  206. System.out.println("Oh, no! You can't go off the screen!");
  207. }
  208. }
  209. Demo.frameFinished();
  210. }
  211.  
  212. }
  213. }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement