Advertisement
Guest User

Untitled

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