Advertisement
Guest User

Version No.2

a guest
May 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. //Kin Hee, Student ID--> 45422451
  2.  
  3. //variables needed for two tools
  4. int hammerPos = 0; int hammerVel = 1; int hammerPending = 0;
  5. int bucketPos = 0; int bucketVel = 2; int bucketPending = 0;
  6.  
  7. int mrPos;
  8. int jump = 60;
  9. boolean doorOpen = true;
  10.  
  11. long timeAt; // the time at which the door was last opened or closed
  12. long waitTime; // the time to wait (in total) until the door opens next
  13.  
  14. int circleX;
  15. int circleY;
  16. int t = 0;
  17. int circleCount;
  18. int up = 0;
  19. int down = 0;
  20.  
  21. void setup() {
  22. size(512,348);
  23. mrPos = width/8;
  24. frameRate(30);
  25. waitTime = int(random(3000,8000));
  26. }
  27.  
  28. void draw() {
  29. if (millis() > timeAt + waitTime) { // calculation will tell me if current time (millis) has gone past the last time the door opened plus waitTime
  30. doorOpen = !doorOpen;
  31. timeAt = millis(); //reset last opening time to now
  32. waitTime = int(random(3000,8000)); //Choose new waiting time
  33. }
  34.  
  35. background(150,172,173);
  36. entrance();
  37. house();
  38. condition();
  39. hammer();
  40. bucket();
  41. Gw();
  42. animation();
  43. movingHammer();
  44. hittingGw();
  45. score(up,down);
  46. }
  47.  
  48. void entrance() {
  49. //draw entrance
  50. noFill();
  51. strokeWeight(2);
  52. stroke(0);
  53. rect(1,209,45,84);
  54. fill(0);
  55. rect(12,223,17,17);
  56. ellipse(35,257,7,9);
  57. }
  58.  
  59. void house() {
  60. strokeWeight(20);
  61. stroke(0);
  62. line(402,206,490,169);
  63. line(490,169,512,179);
  64. strokeWeight(2);
  65. noFill();
  66. line(411,213,411,305);
  67. rect(419,210,49,85);
  68. }
  69.  
  70. void condition() {
  71. if(doorOpen) {
  72. line(479,206,499,199);
  73. line(499,199,499,314);
  74. line(499,314,478,302);
  75. fill(0);
  76. noStroke();
  77. triangle(476,225,493,219,493,243);
  78. triangle(476,225,493,243,476,240);
  79. ellipse(487,255,6,8);
  80. arc(499,255,507,262,3*HALF_PI, HALF_PI, CHORD);
  81. } else {
  82. fill(0);
  83. noStroke();
  84. rect(432,225,21,18);
  85. ellipse(425,255,6,8);
  86. }
  87. }
  88.  
  89. void hammer() {
  90. //draw hammer;
  91. fill(0);
  92. stroke(0);
  93. strokeWeight(6);
  94. line(128,hammerPos+10,148,hammerPos-12);
  95. strokeWeight(4);
  96. line(125,hammerPos+13,129,hammerPos+11);
  97. strokeWeight(8);
  98. line(115,hammerPos+5,130,hammerPos+20);
  99. }
  100.  
  101. void bucket() {
  102. //draw bucket
  103. fill(0);
  104. noStroke();
  105. triangle(167,bucketPos-5,187,bucketPos-12,188,bucketPos+12);
  106. triangle(167,bucketPos-5,187,bucketPos+12,169,bucketPos+14);
  107. noFill();
  108. stroke(0);
  109. strokeWeight(4);
  110. ellipse(183,bucketPos,25,18);
  111. }
  112.  
  113. void Gw() {
  114. //Draw Mr Gw
  115. noStroke();
  116. fill(0);
  117. ellipse(mrPos,240,30,30);
  118. fill(150,172,173);
  119. ellipse(mrPos+9,247,13,9);
  120. fill(0);
  121. triangle(mrPos,240+15,mrPos-11,275,mrPos+3,280);
  122. }
  123.  
  124. void animation() {
  125. // animate all automatically moving objects.. first update pending then decide if there is a jump this frame
  126. hammerPending = hammerPending + hammerVel;
  127. bucketPending = bucketPending + bucketVel;
  128. if (hammerPending > jump){
  129. hammerPos = hammerPos + hammerPending;
  130. hammerPending = 0;
  131. }
  132. if (bucketPending > jump){
  133. bucketPos = bucketPos + bucketPending;
  134. bucketPending = 0;
  135. }
  136. }
  137. void movingHammer() {
  138.  
  139. if (hammerPos > 300) {
  140. hammerPos = 0;
  141. up++;
  142. } else if (bucketPos > 300) {
  143. bucketPos = 0;
  144. up++;
  145. }
  146. }
  147.  
  148. void hittingGw() {
  149. // what to do when tool hits mr gw
  150. if (hammerPos > 240 && hammerPos < 300 && mrPos == width/4){
  151. mrPos = width/8;
  152. up+=6;
  153. }
  154. if (bucketPos > 240 && bucketPos < 300 && mrPos == 3*width/8){
  155. mrPos = width/8;
  156. down+=6;
  157. }
  158.  
  159. }
  160.  
  161. void circle(int gradientX,int gradientY,boolean up) {
  162. noStroke();
  163. int radius = 1;
  164. while (radius<=50) {
  165. if (up==false) {
  166. fill(255,0,0,radius*2);
  167. } else {
  168. fill(0,0,0,radius*2);
  169. }
  170. ellipse(gradientX,gradientY,(90-radius),(90-radius));
  171. radius++;
  172. }
  173. }
  174.  
  175. void score(int up, int down) {
  176. int circleY = 43;
  177. int circleX = 43;
  178. int circleCount = up + down;
  179. int t = 0;
  180. while(t < circleCount) {
  181. if (down >t) {
  182. circle(circleX,circleY,false);
  183. } else {
  184. circle(circleX,circleY, true);
  185. }
  186. if ((circleX > 440) && (circleY < 298)) {
  187. circleX = 43;
  188. circleY += 85;
  189. } else {
  190. circleX += 85;
  191. }
  192. t++;
  193. }
  194. }
  195.  
  196. void keyPressed(){
  197. if (keyCode == RIGHT && (mrPos < 7*(width/8)) && doorOpen){ // mr gw is moving right and the door is open
  198. mrPos = mrPos + width/8;
  199. } else if (keyCode == RIGHT && (mrPos < 6*(width/8))){ // mr gw is moving right not including last slot
  200. mrPos = mrPos + width/8;
  201. } else if (keyCode == LEFT && (mrPos > width/8)){ // mr gw is moving left.
  202. mrPos = mrPos - width/8;
  203. }
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement