/* Log Chop Toy By Kilian Johnson - Game Design Student at Sheridan College This program is meant to test ones reflexes with a fun game where the play needs to press the space bar when the log passes through the middle of the screen to successfully chop it in half. Be careful though, they get faster each time! */ void setup() { size(400, 400); rectMode(CENTER); } //Declaring Variables float logSpeed=1; float logY=height*2; float logX=-130; int score=0; int highScore=0; float scoreColor1=random(150,255); float scoreColor2=random(150,255); float scoreColor3=random(150,255); void draw() { //Set the background color drawBackGround(); //Draw Trees Across the Backdrop drawTrees(); //Reset frame rate back to normal frameRate(60); //Turn on Antialiasing smooth(); //Log moving from one side to the other drawLog(); //Axe for chopping the log drawAxe(); //Display score drawScore(); //Display High Score drawHighScore(); //Display the Instructions drawInstructions(); } void drawBackGround() { background(72, 103, 36); noStroke(); fill(120, 205, 225); quad(0, 100, 400, 100, 400, 280, 0, 280); stroke(252,185,40); strokeWeight(3); line(200,262,200,280); line(200,262,205,267); line(195,267,200,262); } void drawTrees() { for (float i=20; i<400; i=i+60) { noStroke(); fill(100, 50, 0); beginShape(); vertex(i-5, 30); vertex(i-5, 70); vertex(i-20, 90); vertex(i-5, 85); vertex(i-5, 100); vertex(i+5, 85); vertex(i+20, 100); vertex(i+15, 85); vertex(i+30, 85); vertex(i+10, 70); vertex(i+10, 30); endShape(); fill(118, 161, 53); noStroke(); ellipse(i, 20, 20, 20); ellipse(i+10, 25, 20, 20); ellipse(i+15, 30, 20, 20); ellipse(i+10, 35, 20, 20); ellipse(i+5, 40, 20, 20); ellipse(i, 40, 20, 20); ellipse(i-5, 35, 20, 20); ellipse(i-10, 30, 20, 20); ellipse(i-5, 25, 20, 20); } } void drawLog() { //Draw the log //Core piece fill(100, 50, 0); ellipse(logX-95, logY, 60, 99); noStroke(); rect(logX, logY, 200, 100); stroke(1); ellipse(logX+95, logY, 60, 99); ellipse(logX+95, logY, 40, 80); ellipse(logX+95, logY, 25, 60); ellipse(logX+95, logY, 15, 35); fill(0); ellipse(logX+95, logY, 5, 10); strokeWeight(3); stroke(252,185,40); line(logX-50,logY-60,logX-50,logY+48); line(logX+50,logY-48,logX+50,logY+48); strokeWeight(1); stroke(0); //Wood lines strokeWeight(3); line(logX-85, logY-40, logX-70, logY-40); line(logX+50, logY+25, logX+65, logY+25); line(logX+10, logY+20, logX+35, logY+20); line(logX-60, logY+10, logX-70, logY+10); line(logX-50, logY+45, logX-30, logY+45); line(logX+40, logY-30, logX+60, logY-30); line(logX+5, logY-5, logX+20, logY-5); line(logX-45, logY-20, logX-25, logY-20); strokeWeight(1); //Branch fill(100, 50, 0); noStroke(); quad(logX-75, logY-60, logX-35, logY-60, logX-10, logY-40, logX-50, logY-40); stroke(1); line(logX-75, logY-60, logX-50, logY-40); line(logX-35, logY-60, logX-10, logY-40); ellipse(logX-55, logY-60, 40, 15); fill(0); ellipse(logX-55, logY-60, 10, 5); fill(255); //Move log across the screen logX += logSpeed; //When log gets to the end, bring it back to the start if (logX>530) { logX=-130; } } void drawLogChopped() { //Change frame rate to let image persist frameRate(1); //Right side of log fill(100, 50, 0); noStroke(); rect(300, 200, 100, 120); fill(120, 205, 225); triangle(250, 140, 260, 150, 250, 160); triangle(250, 160, 270, 170, 250, 180); triangle(250, 180, 260, 190, 250, 200); triangle(250, 200, 260, 205, 250, 210); triangle(250, 210, 260, 215, 250, 220); triangle(250, 220, 265, 230, 250, 235); triangle(250, 235, 270, 240, 250, 245); triangle(250, 245, 260, 250, 250, 255); triangle(250, 255, 260, 257, 250, 260); fill(100, 50, 0); stroke(1); ellipse(350, 200, 60, 120); ellipse(350, 200, 50, 99); ellipse(350, 200, 40, 80); ellipse(350, 200, 25, 60); ellipse(350, 200, 15, 35); fill(0); ellipse(350, 200, 5, 10); strokeWeight(3); line(270, 160, 300, 160); line(300, 190, 310, 190); line(280, 225, 295, 225); line(310, 250, 320, 250); //Left side of log fill(100, 50, 0); noStroke(); ellipse(55, 200, 60, 120); rect(100, 200, 100, 120); fill(120, 205, 225); triangle(150, 140, 140, 145, 150, 150); triangle(150, 150, 130, 160, 150, 170); triangle(150, 170, 140, 180, 150, 190); triangle(150, 190, 130, 207, 150, 210); triangle(150, 210, 140, 220, 150, 225); triangle(150, 225, 130, 230, 150, 240); triangle(150, 240, 140, 245, 150, 250); triangle(150, 250, 140, 260, 150, 260); stroke(1); strokeWeight(3); line(60, 150, 80, 150); line(80, 180, 90, 180); line(115, 195, 125, 195); line(95, 235, 120, 235); line(65, 245, 80, 245); fill(100, 50, 0); noStroke(); quad(50, 120, 90, 120, 130, 160, 90, 160); stroke(1); strokeWeight(1); line(50, 120, 90, 160); line(90, 120, 130, 160); ellipse(70, 120, 40, 15); fill(0); ellipse(70, 120, 10, 5); } void drawAxe() { //Axe Head stroke(0); fill(219, 228, 238); arc(220, 40, 205, 213, PI/2, PI); line(220, 60, 220, 145); line(117, 40, 200, 40); //Axe Handle fill(122, 102, 93); quad(180, 20, 200, 0, 335, 130, 315, 155); fill(219, 228, 238); quad(200, 40, 220, 20, 240, 40, 220, 60); fill(255); } void drawSwungAxe() { //Axe Head stroke(0); fill(219, 228, 238); triangle(130, 160, 200, 80, 270, 160); arc(200, 160, 140, 50, 0, PI); //Axe Handle fill(122, 102, 93); quad(170, 70, 360, 70, 360, 100, 170, 100); fill(219, 228, 238); quad(183, 70, 217, 70, 217, 100, 183, 100); fill(255); } void drawScore() { fill(scoreColor1, scoreColor2, scoreColor3); textSize(30); text("Score:" + score, 10, 380); } void drawHighScore() { fill(scoreColor1, scoreColor2, scoreColor3); textSize(30); text("High Score:" + highScore, 180, 380); } void drawInstructions() { fill(scoreColor1, scoreColor2, scoreColor3); textSize(30); text("Spacebar to Chop!",65,320); } void keyPressed() { /*When spacebar is pressed while log is in the middle of the screen, increase speed of log and increase score. If spacebar is pressed while log is not in the middle of the screen, reset score to 0 and reset log speed to original */ if (key == ' ') { if (logX>150&&logX<250) { logSpeed+=2; score=score+1; logX=-130; drawBackGround(); drawTrees(); drawLogChopped(); drawSwungAxe(); drawScore(); drawHighScore(); drawInstructions(); //Keep track of high score if (score>highScore) { highScore=score; } } else { logX=-130; logSpeed=1; score=0; } } }