Guest User

Untitled

a guest
Jul 22nd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.78 KB | None | 0 0
  1. //David Down
  2. //Section D
  3. //Down.DavidR@gmail.com
  4. //Copyright © David Down February 2011 Pittsburgh, PA, 15232 All Rights Reserved
  5. //
  6. //
  7. // Do not alter or delete the next 9 lines of code.
  8. /**********************************
  9. <B> Homework #6</B><BR>
  10. Use the [arrow keys] to "fly" my initials around the screen<BR>
  11. and try to hit the moving target.<BR>
  12. If you hold down a key, my initials move faster.<BR>
  13. Try not to lose my initials.<BR>
  14. If you do lose them, press the [space bar].<BR>
  15. Have fun.<BR>
  16. ************************************/
  17.  
  18. //* ------------ Movie Code - Do Not Alter the next three lines lines ---------/
  19. import processing.video.*;
  20. Capture myCapture;
  21. MovieMaker mm;
  22.  
  23. void setup( )
  24. {
  25. size ( 400, 400 );
  26. background (10,76,250);
  27. ht=.1*height;
  28. wd=.1*width;
  29.  
  30.  
  31. loadFont("SansSerif-18.vlw");
  32. textAlign(CENTER);
  33.  
  34. // ------------ Movie Code #1 - uncomment next two lines ---------/
  35. // myCapture = new Capture(this, width, height, 30);
  36. // mm = new MovieMaker(this, width, height, "hw6.mov", 30, MovieMaker.ANIMATION, MovieMaker.HIGH);
  37. }
  38. float boxx=0;
  39. float boxy=0;
  40. float boxdx=random(8);
  41. float boxdy=random(8);
  42.  
  43. float initialsx=200;
  44. float initialsy=200;
  45. float initialsdx=random(1);
  46. float initialsdy=random(1);
  47. float ht;
  48. float wd;
  49. int hit;
  50.  
  51.  
  52.  
  53. void draw( )
  54. {
  55. offscreen();
  56. drawBox();
  57. drawInitials();
  58. collisionDetect();
  59. indicators();
  60.  
  61. // ------------ Movie Code #2 - uncomment one linelines ---------/
  62. // mm.addFrame( );
  63. }
  64.  
  65.  
  66. void keyPressed()
  67. {
  68. if (keyCode==keyEvent.VK_SPACE)
  69. {
  70. initialsx=200;
  71. initialsy=200;
  72. initialsdx=0;
  73. initialsdy=0;
  74. }
  75. if (key==CODED)
  76. {
  77. if (keyCode==UP)
  78. {
  79. initialsdy=initialsdy-1;
  80. }
  81. else if (keyCode==DOWN)
  82. {
  83. initialsdy=initialsdy+1;
  84. }
  85. else if (keyCode==LEFT)
  86. {
  87. initialsdx=initialsdx-1;
  88. }
  89. else if (keyCode==RIGHT)
  90. {
  91. initialsdx=initialsdx+1;
  92. }
  93.  
  94. }
  95.  
  96. // ------------ Movie Code #3 - uncomment next four lines lines ---------/
  97. //else if (key == 'c')
  98. //{
  99. // mm.finish
  100. //}
  101.  
  102.  
  103. }
  104.  
  105. // ------------ Movie Code #4 - uncomment next four lines lines ---------/
  106. //void captureEvent(Capture myCapture)
  107. //{
  108. //myCapture.read();
  109. //}
  110. void drawBox()
  111. {
  112. //rectMode(CORNER);
  113. fill(random(255),random(255),random(255));
  114. rect(boxx,boxy, width*.05, height*.05);
  115. boxx=boxx+boxdx;
  116. boxy=boxy+boxdy;
  117. if(boxx>400)
  118. {
  119.  
  120. boxdx=(-1*random(8));
  121. }
  122. if (boxx<0)
  123. {
  124. boxdx=random(8);
  125. }
  126. if(boxy>400)
  127. {
  128.  
  129. boxdy=(-1*random(8));
  130. }
  131.  
  132.  
  133. if (boxy<0)
  134. {
  135. boxdy=random(8);
  136. }
  137. fill(10,76,250,100);
  138. rect(0,0,width,height);
  139.  
  140. }
  141. void drawInitials ()
  142. {
  143.  
  144.  
  145. smooth();
  146. fill(21,95,5);
  147. ht=wd;
  148.  
  149. initialsx=initialsx+initialsdx;
  150. initialsy=initialsy+initialsdy;
  151.  
  152. noStroke();
  153. ellipse(initialsx,initialsy,wd,ht);
  154. noFill();
  155. strokeWeight(.03*wd);
  156.  
  157. stroke(255,11,3);
  158. beginShape();
  159. curveVertex(initialsx-(.6*wd),initialsy-(.6*ht));
  160. curveVertex(initialsx-(.3*wd),initialsy-(.4*ht));
  161. curveVertex(initialsx,initialsy);
  162. curveVertex(initialsx-(.3*wd),initialsy+(.4*ht));
  163. curveVertex(initialsx-(.6*wd),initialsy+(.6*ht));
  164. endShape();
  165.  
  166. beginShape();
  167. curveVertex(initialsx-(.2*wd),initialsy-(.55*ht));
  168. curveVertex(initialsx-(.3*wd),initialsy-(.4*ht));
  169. curveVertex(initialsx-(.38*wd),initialsy);
  170. curveVertex(initialsx-(.3*wd),initialsy+(.4*ht));
  171. curveVertex(initialsx-(.2*wd),initialsy+(.55*ht));
  172. endShape();
  173.  
  174. stroke(255,100,3);
  175. beginShape();
  176. curveVertex(initialsx-(.1*wd),initialsy+(.55*ht));
  177. curveVertex(initialsx-(.15*wd),initialsy+(.475*ht));
  178. curveVertex(initialsx-(.2*wd), initialsy);
  179. curveVertex(initialsx-(.15*wd),initialsy-(.475*ht));
  180. curveVertex(initialsx-(.1*wd),initialsy-(.55*ht));
  181. endShape();
  182.  
  183.  
  184. beginShape();
  185. curveVertex(initialsx-(.3*wd),initialsy-(.4*ht));
  186. curveVertex(initialsx-(.15*wd),initialsy-(.475*ht));
  187. curveVertex(initialsx+(.2*wd),initialsy-(.3*ht));
  188. curveVertex(initialsx+(.17*wd),initialsy);
  189. curveVertex(initialsx-(.2*wd), initialsy);
  190. curveVertex(initialsx-(.38*wd),initialsy-(.1*ht));
  191. endShape();
  192.  
  193.  
  194.  
  195. beginShape();
  196. curveVertex(initialsx-(.1*wd),initialsy-(.1*ht));
  197. curveVertex(initialsx,initialsy);
  198. curveVertex(initialsx+(.15*wd),initialsy+(.475*ht));
  199. curveVertex(initialsx+(.13*wd),initialsy+(.6*ht));
  200. endShape();
  201.  
  202.  
  203.  
  204. stroke(255,230,3);
  205. beginShape();
  206. curveVertex(initialsx+(.2*wd),initialsy-(.5*ht));
  207. curveVertex(initialsx+(.3*wd),initialsy-(.4*ht));
  208. curveVertex(initialsx+(.37*wd),initialsy);
  209. curveVertex(initialsx+(.3*wd), initialsy+(.4*ht));
  210. curveVertex(initialsx+(.2*wd),initialsy+(.5*ht));
  211. endShape();
  212.  
  213.  
  214.  
  215. beginShape();
  216. curveVertex(initialsx+(.2*wd),initialsy-(.5*ht));
  217. curveVertex(initialsx+(.3*wd),initialsy-(.4*ht));
  218. curveVertex(initialsx+(.5*wd),initialsy);
  219. curveVertex(initialsx+(.3*wd), initialsy+(.4*ht));
  220. curveVertex(initialsx+(.2*wd),initialsy+(.5*ht));
  221. endShape();
  222. }
  223.  
  224. void collisionDetect()
  225. {
  226. if(-.05*width<=initialsx-boxx&&initialsx-boxx<=.05*width+.05*width)
  227. {
  228. if(-.05*height<=initialsy-boxy&&initialsy-boxy<=.05*height+.05*height)
  229. {
  230. boxx=random(400);
  231. boxy=random(400);
  232. hit=hit+1;
  233. fill(255,0,0,100);
  234. rect(0,0,width,height);
  235. }
  236. }
  237. }
  238.  
  239. void indicators()
  240. {
  241. fill(0,0,0);
  242.  
  243. text("X Coordinate: ("+int(initialsx)+")",80,100);
  244. text("Y Coordinate: ("+int(initialsy)+")",80,130);
  245. text("X Speed: ("+int(initialsdx)+")",80,160);
  246. text("Y Speed: ("+int(initialsdy)+")",80, 190);
  247. text("Hits: ("+hit+")",80,220);
  248. }
  249.  
  250. void offscreen()
  251. {
  252. if(initialsx<0)
  253. {
  254. fill(255,0,0);
  255. text("The Initials Are Offscreen!",200,300);
  256. stroke(255,0,0);
  257. strokeWeight(4);
  258. line(200,200,initialsx, initialsy);
  259. }
  260. if(initialsx>400)
  261. {
  262. fill(255,0,0);
  263. text("The Initials Are Offscreen!",200,300);
  264. stroke(255,0,0);
  265. strokeWeight(4);
  266. line(200,200,initialsx, initialsy);
  267. }
  268. if(initialsy<0)
  269. {
  270. fill(255,0,0);
  271. text("The Initials Are Offscreen!", 200,300);
  272. stroke(255,0,0);
  273. strokeWeight(4);
  274. line(200,200,initialsx, initialsy);
  275. }
  276. if(initialsy>400)
  277. {
  278. fill(255,0,0);
  279. text("The Initials Are Offscreen!",200,300);
  280. stroke(255,0,0);
  281. strokeWeight(4);
  282. line(200,200,initialsx, initialsy);
  283. }
  284. }
Add Comment
Please, Sign In to add comment