//Skateboarder by Hannah McIntear //Avoid the oncoming obstacles //Use the mouse to move //Click the mouse to jumo //The gravity and thrust I took from this project http://www-acad.sheridanc.on.ca/PROG14998/2016/interactive-toy/heather_cleveland_interactive_toy/index.html //Background I took from here: http://www-acad.sheridanc.on.ca/PROG14998/2017/interactive-toy/avery_augusto_interactive_toy/index.html //Player Variables float playerX = 50; float playerY = 275; float gravity = 5; float thrust = -8; //Obstacle Variables float trashCanX = 450; float trashCanY = 240; float objectSpeed = 3; float mailBoxX = 850; float mailBoxY = 300; float fireHydrantX = 1200; float fireHydrantY = 255; //Line Variables float lineAX = 50; float lineY = 335; float lineBX = 140; float lineCX = 230; float lineDX = 320; float lineEX = 410; float lineLength = 45; float lineSpeed = 3; float lineResetPosition = 400; //Building Variables float building1X = 0; float building1Y = 35; float building2X = 200; float building2Y = 0; float building3X = 25; float building3Y = 30; float building4X = 300; float building4Y = 0; float buildingScrollSpeed = 1; float buildingResetPosition = 400; void setup() { size(400, 400); rectMode(CORNER); ellipseMode(CORNER); } void draw() { bg(); update(); display(); } void bg() { background(0); noStroke(); for (int i = 1; i <=9; i++) { fill(0+(i*8)); rect(0, 45*i, 400, 50); } stars(); } void stars() { stroke(255); point(25, 50); point(50, 100); point(75, 20); point(100, 200); point(125, 125); point(150, 75); point(175, 225); point(200, 100); point(225, 150); point(250, 175); point(275, 50); point(300, 250); point(325, 100); point(350, 125); } void update() { moveBuildings(); moveRoadLines(); moveTrashCan(); moveMailBox(); moveFireHydrant(); jump(); } void display() { displayRearBuildings(); displayFrontBuildings(); displayRoad(); displayRoadLines(); displayTrashCan(); displayFireHydrant(); displaySkateboarder(); displayMailBox(); } void displayRoad() { strokeWeight(5); stroke(0); fill(0); line(-10, 285, 410, 285); strokeWeight(0); fill(85); rect(0, 288, 400, 115); } void displayRoadLines() { strokeWeight(5); stroke(0); fill(0); line(lineAX, lineY, lineAX+lineLength, lineY); line(lineBX, lineY, lineBX+lineLength, lineY); line(lineCX, lineY, lineCX+lineLength, lineY); line(lineDX, lineY, lineDX+lineLength, lineY); line(lineEX, lineY, lineEX+lineLength, lineY); } void moveRoadLines() { strokeWeight(5); stroke(0); fill(0); //All lines move to the left lineAX = lineAX - lineSpeed; lineBX = lineBX - lineSpeed; lineCX = lineCX - lineSpeed; lineDX = lineDX - lineSpeed; lineEX = lineEX - lineSpeed; //If the line goes off the edge of the screen it is reset if (lineAX<-lineLength) { lineAX = lineResetPosition; } if (lineBX<-lineLength) { lineBX = lineResetPosition; } if (lineCX<-lineLength) { lineCX = lineResetPosition; } if (lineDX<-lineLength) { lineDX = lineResetPosition; } if (lineEX<-lineLength) { lineEX = lineResetPosition; } } void displayRearBuildings() { strokeWeight(0); stroke(0); fill(45); rect(building3X, building3Y, 155, 255); //Windows fill(55); strokeWeight(5); stroke(80); fill(255, 229, 0); rect(building3X+65, building3Y+20, 25, 55); fill(50); fill(255, 229, 0); rect(building3X+110, building3Y+85, 25, 55); fill(50); fill(255, 229, 0); rect(building3X+20, building3Y+150, 25, 55); // Other rear building fill(60); strokeWeight(0); rect(building4X, building4Y, 140, 285); fill(50); //Windows rect(building4X+10, building4Y+10, 30, 70); rect(building4X+55, building4Y+10, 30, 70); rect(building4X+100, building4Y+10, 30, 70); rect(building4X+10, building4Y+90, 30, 70); rect(building4X+55, building4Y+90, 30, 70); rect(building4X+100, building4Y+90, 30, 70); rect(building4X+10, building4Y+170, 30, 70); rect(building4X+55, building4Y+170, 30, 70); rect(building4X+100, building4Y+170, 30, 70); } void displayFrontBuildings() { fill(170); strokeWeight(0); rect(building1X, building1Y, 120, 250); //Windows fill(50, 50, 75); rect(building1X, building1Y, 30, 62.5); rect(building1X+30, building1Y, 30, 42.5); rect(building1X+60, building1Y+62.5, 30, 62.5); rect(building1X+90, building1Y+42.5, 30, 62.5); rect(building1X, building1Y+125, 30, 62.5); rect(building1X+30, building1Y+105, 30, 62.5); rect(building1X+60, building1Y+187.5, 30, 62.5); rect(building1X+90, building1Y+167.5, 30, 62.5); rect(building1X+30, building1Y+230, 30, 20); //Darker color windows fill(20, 20, 50); rect(building1X+30, building1Y+167.5, 30, 62.5); rect(building1X, building1Y+62.5, 30, 62.5); rect(building1X+90, building1Y, 30, 42.5); rect(building1X+90, building1Y+230, 30, 20); rect(building1X+90, building1Y+105, 30, 62.5); rect(building1X, building1Y+187.5, 30, 62.5); rect(building1X+30, building1Y+42.5, 30, 62.5); rect(building1X+60, building1Y, 30, 62.5); rect(building1X+60, building1Y+125, 30, 62.5); fill(75); rect(building2X, building2Y, 250, 285); //Windows fill(95); rect(building2X+40, building2Y+40, 55, 85); rect(building2X+155, building2Y+40, 55, 85); } void moveBuildings() { //Some buildings move slower than others to create a parallax scrolling effect building1X = building1X - buildingScrollSpeed; building2X = building2X - buildingScrollSpeed; building3X = building3X - buildingScrollSpeed+0.5; building4X = building4X - buildingScrollSpeed+0.5; // If the building goes off the edge of the screen, it is reset if (building1X <-200) { building1X = buildingResetPosition; } if (building2X <-300) { building2X = buildingResetPosition; } if (building3X <-175) { building3X = buildingResetPosition; } if (building4X <-135) { building4X = buildingResetPosition; } } void displaySkateboarder() { //Skateboarder's body and head strokeWeight(2); fill(255); stroke(0); ellipse(playerX+35, playerY-40, 30, 30); strokeWeight(5); stroke(0); line(playerX+45, playerY-9, playerX+40, playerY+30); line(playerX+45, playerY-9, playerX+25, playerY+20); line(playerX+45, playerY-9, playerX+65, playerY+20); //Wheels strokeWeight(3); fill(255); ellipse(playerX+10, playerY+60, 15, 15); ellipse(playerX+68, playerY+60, 15, 15); //Board fill(30); ellipse(playerX, playerY+50, 90, 20); //Skateboarder's legs strokeWeight(5); line(playerX+40, playerY+30, playerX+50, playerY+55); line(playerX+40, playerY+30, playerX+15, playerY+55); //Limit player within the first half of screen if (pmouseX<width/2) { //The skateboarder follows the mouse playerX = pmouseX; } } void displayTrashCan() { strokeWeight(1); fill(175); rect(trashCanX, trashCanY, 60, 80, 10); quad(trashCanX, trashCanY+5, trashCanX+20, trashCanY-10, trashCanX+40, trashCanY-10, trashCanX+60, trashCanY+5); line(trashCanX+8, trashCanY, trashCanX+52, trashCanY); line(trashCanX+12, trashCanY-4, trashCanX+49, trashCanY-4); ellipse(trashCanX+3, trashCanY+10, 5, 65); ellipse(trashCanX+13, trashCanY+10, 5, 65); ellipse(trashCanX+23, trashCanY+10, 5, 65); ellipse(trashCanX+33, trashCanY+10, 5, 65); ellipse(trashCanX+43, trashCanY+10, 5, 65); ellipse(trashCanX+53, trashCanY+10, 5, 65); //Handle strokeWeight(3); line(trashCanX+20, trashCanY-10, trashCanX+20, trashCanY-14); line(trashCanX+20, trashCanY-14, trashCanX+40, trashCanY-14); line(trashCanX+40, trashCanY-14, trashCanX+40, trashCanY-10); } void moveTrashCan() { //The trashcan moves to the left continuously trashCanX = trashCanX - objectSpeed; //If the trashcan goes off the edge of the screen, its position is reset if (trashCanX<-50) { trashCanX = 1000; } } void displayMailBox() { fill(12, 104, 252); noStroke(); rect(mailBoxX, mailBoxY, 60, 65); ellipse(mailBoxX, mailBoxY-25, 60, 60); rect(mailBoxX, mailBoxY+65, 5, 20); rect(mailBoxX+55, mailBoxY+65, 5, 20); stroke(0); strokeWeight(2); rect(mailBoxX+10, mailBoxY+15, 40, 40); fill(0); rect(mailBoxX+15, mailBoxY-10, 30, 6, 8); } void moveMailBox() { //Mailbox moves to the left mailBoxX = mailBoxX - objectSpeed; //If the mailbox goes off the screen, it is reset. if (mailBoxX<-50) { mailBoxX = 1000; } } void displayFireHydrant() { fill(255, 0, 0); noStroke(); rect(fireHydrantX, fireHydrantY+5, 40, 15); rect(fireHydrantX+10, fireHydrantY-10, 20, 75); ellipse(fireHydrantX+10, fireHydrantY-20, 20, 20); rect(fireHydrantX+5, fireHydrantY-5, 30, 5); rect(fireHydrantX-2.5, fireHydrantY+10, 45, 5); ellipse(fireHydrantX, fireHydrantY+56, 40, 10); } void moveFireHydrant() { //Fire hydrant moves to the left fireHydrantX = fireHydrantX -objectSpeed; //If the fire hydrant goes off the screen, it is reset. if (fireHydrantX<-50) { fireHydrantX = 1000; } } void jump() { if (mousePressed) { //If the mouse is pressed, the player will move up on the Y axis playerY = playerY + thrust; } else { //If the mouse is not being pressed then the player is affected by gravity and slowly floats down playerY = playerY + gravity; } //Stops the player from falling out of the bottom of the screen if (playerY > 300) { gravity=0; thrust =0; } else gravity = 5; //if the skateboarder is above the middle of the screen he stops if (playerY <100) { thrust = 0; } else thrust = -8; //I attempted to adjust how the jump works. The way it is now you can jump over and over again. //I wanted to make it so you press jump once, the jump is performed, then you cannot jump again until you reach the ground. //Could use a time based thing //if(mousePressed) { //jump = true; //thrust = -8 for 3 seconds //then thrust = 0 for 3 seconds //can't jump again for 3 seconds; //if (jump= false) { // jumpDelay = millis(3000); //if(jumpDelay>3000) { //thrust = 0; }