Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //variables needed for two tools
- int hammerPos = 0; int hammerVel = 1; int hammerPending = 0;
- int bucketPos = 0; int bucketVel = 2; int bucketPending = 0;
- int mrPos;
- int jump = 60;
- boolean doorOpen = true;
- long timeAt; // the time at which the door was last opened or closed
- long waitTime; // the time to wait (in total) until the door opens next
- int circleX;
- int circleY;
- int t = 0;
- int circleCount;
- int up;
- int down;
- void setup() {
- size(512,348);
- mrPos = width/8;
- frameRate(30);
- waitTime = int(random(3000,8000));
- }
- void draw() {
- if (millis() > timeAt + waitTime) { // calculation will tell me if current time (millis) has gone past the last time the door opened plus waitTime
- doorOpen = !doorOpen;
- timeAt = millis(); //reset last opening time to now
- waitTime = int(random(3000,8000)); //Choose new waiting time
- }
- background(150,172,173);
- //draw entrance
- noFill();
- strokeWeight(2);
- stroke(0);
- rect(1,209,45,84);
- fill(0);
- rect(12,223,17,17);
- ellipse(35,257,7,9);
- //draw house
- strokeWeight(20);
- stroke(0);
- line(402,206,490,169);
- line(490,169,512,179);
- strokeWeight(2);
- noFill();
- line(411,213,411,305);
- rect(419,210,49,85);
- if(doorOpen) {
- line(479,206,499,199);
- line(499,199,499,314);
- line(499,314,478,302);
- fill(0);
- noStroke();
- triangle(476,225,493,219,493,243);
- triangle(476,225,493,243,476,240);
- ellipse(487,255,6,8);
- arc(499,255,507,262,3*HALF_PI, HALF_PI, CHORD);
- } else {
- fill(0);
- noStroke();
- rect(432,225,21,18);
- ellipse(425,255,6,8);
- }
- //draw hammer;
- fill(0);
- stroke(0);
- strokeWeight(6);
- line(128,hammerPos+10,148,hammerPos-12);
- strokeWeight(4);
- line(125,hammerPos+13,129,hammerPos+11);
- strokeWeight(8);
- line(115,hammerPos+5,130,hammerPos+20);
- //draw bucket
- fill(0);
- noStroke();
- triangle(167,bucketPos-5,187,bucketPos-12,188,bucketPos+12);
- triangle(167,bucketPos-5,187,bucketPos+12,169,bucketPos+14);
- noFill();
- stroke(0);
- strokeWeight(4);
- ellipse(183,bucketPos,25,18);
- //Draw Mr Gw
- noStroke();
- fill(0);
- ellipse(mrPos,240,30,30);
- fill(150,172,173);
- ellipse(mrPos+9,247,13,9);
- fill(0);
- triangle(mrPos,240+15,mrPos-11,275,mrPos+3,280);
- // animate all automatically moving objects.. first update pending then decide if there is a jump this frame
- hammerPending = hammerPending + hammerVel;
- bucketPending = bucketPending + bucketVel;
- if (hammerPending > jump){
- hammerPos = hammerPos + hammerPending;
- hammerPending = 0;
- }
- if (bucketPending > jump){
- bucketPos = bucketPos + bucketPending;
- bucketPending = 0;
- }
- if (hammerPos > 300) {
- hammerPos = 0;
- up++;
- } else if (bucketPos > 300) {
- bucketPos = 0;
- up++;
- }
- // what to do when tool hits mr gw
- if (hammerPos > 240 && hammerPos < 300 && mrPos == width/4){
- mrPos = width/8;
- }
- if (bucketPos > 240 && bucketPos < 300 && mrPos == 3*width/8){
- mrPos = width/8;
- }
- }
- void score(int up, int down) {
- int circleY = 43;
- int circleX = 43;
- int circleCount = up + down;
- int t = 0;
- while(t < circleCount) {
- if (down < t) {
- circle(circleX,circleY,false);
- } else {
- circle(circleX,circleY, true);
- }
- if ((circleX > 440) && (circleY < 298)) {
- circleX = 43;
- circleY += 64;
- } else {
- circleX += 80;
- }
- t++;
- }
- }
- void circle(int gradientX,int gradientY,boolean up) {
- noStroke();
- int radius = 1;
- while (radius<=50) {
- if (up==false) {
- fill(255,0,0,radius*2);
- } else {
- fill(0,0,0,radius*2);
- }
- ellipse(gradientX,gradientY,(70-radius),(70-radius));
- radius++;
- }
- }
- void keyPressed(){
- if (keyCode == RIGHT && (mrPos < 7*(width/8)) && doorOpen){ // mr gw is moving right and the door is open
- mrPos = mrPos + width/8;
- } else if (keyCode == RIGHT && (mrPos < 6*(width/8))){ // mr gw is moving right not including last slot
- mrPos = mrPos + width/8;
- } else if (keyCode == LEFT && (mrPos > width/8)){ // mr gw is moving left.
- mrPos = mrPos - width/8;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement