//Claire Jarzab
//#991524076
//Alice has decided to jump between the different mushrooms.
//Move Alice left and right with 'A' and 'D'. Each mushroom launches her different heights.
//Avoid touching the ground!
//Psuedocode at the bottom of the code.
///////////////////////////////////////////////////////////////////////////////////////////
//Global Variables
///////////////////////////////////////////////////////////////////////////////////////////
//variables used to draw mushrooms
int mushroom1X = 40;
int mushroom1Y = 390;
int mushroom2X = 200;
int mushroom2Y = 390;
int mushroom3X = 360;
int mushroom3Y = 390;
//variables used to draw and move Alice
int aliceFeetX = 200;
int aliceFeetY = 200;
int aliceMoveSpeed = 3;
boolean aliceRight = false;
boolean aliceLeft = false;
boolean aliceFall = true;
int fallSpeed = 4;
int upSpeed = 1;
/////////////////////////////////////////////////////////////////////////////////////////
//Setup
/////////////////////////////////////////////////////////////////////////////////////////
void setup() {
//Set Frame Rate
frameRate(60);
//Setup screen size
size(400, 400);
}
/////////////////////////////////////////////////////////////////////////////////////
//Draw
///////////////////////////////////////////////////////////////////////////////////////
void draw() {
//Moves alice
moveAlice();
//Determines whether Alice is rising or falling
setAliceBouncing();
//Determines when Alice should come back down
aliceReturn();
//Background colour set to Dark Green
background(52, 52, 2);
//background(10, 51, 7);
//Draws background assets
drawPineTreeDark();
drawLeafTree();
drawPineTree();
//Draws Mushrooms and Alice
drawMushrooms();
drawAlice();
}
///////////////////////////////////////////////////////////////////////////////
//MOVEMENT AND CHANGES
////////////////////////////////////////////////////////////////////////////////
//Moves Alice's position
void moveAlice() {
//Determines whether Alice should be falling and makes her fall, if not then she is rising
if (aliceFall == true) {
aliceFeetY= aliceFeetY + fallSpeed;
} else {
aliceFeetY= aliceFeetY - upSpeed;
}
//Determines if Alice hits the ground, if she does then game over prints, prevents her from going trhough the ground
if (aliceBoundariesY()) {
println ("Game Over! Please Refresh!");
aliceFeetY=height;
}
//Sets boundaries, prevents Alice from leaving the left and right sides of the screens, she is still able to bounce upwards out of view
//Determines what the key press does, Moves Alice Left and Right at set speed
if (aliceBoundariesX()) {
if (aliceLeft == true) {
aliceFeetX+=-aliceMoveSpeed;
}
if (aliceRight == true) {
aliceFeetX+=aliceMoveSpeed;
}
} else if (!aliceBoundariesX() && aliceFeetX<0) {
aliceFeetX=0;
} else if (!aliceBoundariesX() && aliceFeetX>width) {
aliceFeetX=width;
}
}
//Checks to see where Alice is on the X axis
boolean aliceBoundariesX() {
if (aliceFeetX>=0) {
if (aliceFeetX<=width) {
return true;
} else {
return false;
}
} else {
return false;
}
}
//Checks to see where Alice is on the Y axis
boolean aliceBoundariesY() {
if (aliceFeetY>=height) {
return true;
} else
return false;
}
//Assigns A and D on the keyboard to Left and Right
void keyPressed() {
if (key == 'a') {
aliceLeft=true;
}
if (key == 'd') {
aliceRight=true;
}
}
//Once the key is released, Alice doesn't move
void keyReleased() {
if (key == 'a') {
aliceLeft=false;
}
if (key == 'd') {
aliceRight=false;
}
}
//Determines whether Alice has stepped on a mushroom and if so, stops her decent and causes her to go up at a random speed
void setAliceBouncing() {
if (aliceFeetY >= 330 && aliceFeetY<=340) {
if (aliceFeetX >=0 && aliceFeetX <=80) {
upSpeed = int(random(3, 20));
aliceFall=false;
} else if (aliceFeetX >=160 && aliceFeetX <=240) {
upSpeed = int(random(3, 40));
aliceFall=false;
} else if (aliceFeetX >=320 && aliceFeetX <=400) {
upSpeed = int(random(3, 5));
aliceFall=false;
} else {
return;
}
}
}
//Stops Alice's accension and brings her back to falling, the point at which she is stopped is determined by the random number assigned to upSpeed
void aliceReturn() {
if (aliceFeetY < 200 - (upSpeed *10) ) {
aliceFall = true;
}
}
////////////////////////////////////////////////////////////////////////////////////
//ASSETS
////////////////////////////////////////////////////////////////////////////////////
//Draws different tree lines
void drawPineTreeDark () {
float treeLinePineDarkX=10;
while (treeLinePineDarkX<width) {
fill(41, 30, 2);
rectMode(CORNERS);
noStroke();
rect(treeLinePineDarkX, 10, treeLinePineDarkX+25, 270);
ellipse(treeLinePineDarkX+12.5, 270, 25, 10);
// triangle(treeLinePineDarkX, 0, treeLinePineDarkX-18, 7, treeLinePineDarkX-6.5, 6.5);
treeLinePineDarkX+=80;
}
}
void drawLeafTree() {
float treeLineLeafX=20;
while (treeLineLeafX<width) {
noStroke();
fill(108, 61, 5);
rectMode(CORNERS);
rect(treeLineLeafX, 0, treeLineLeafX+10, 290);
ellipse(treeLineLeafX+5, 290, 10, 5);
fill(38, 33, 1);
ellipseMode(CENTER);
ellipse(treeLineLeafX+5, 0, 130, 100);
treeLineLeafX+=40;
}
}
void drawPineTree() {
float treeLinePineDarkX=35;
float treeLinePineDarkPines=5;
float treeLinePineDarkPinesTwo=5;
while (treeLinePineDarkX<width) {
fill(70, 102, 27);
rectMode(CORNERS);
noStroke();
//Draws Pine needles on front trees
while (treeLinePineDarkPines<220) {
triangle(treeLinePineDarkX+10, treeLinePineDarkPines-15, treeLinePineDarkX+90, treeLinePineDarkPines+70, treeLinePineDarkX+40, treeLinePineDarkPines+40);
treeLinePineDarkPines+=20;
}
while (treeLinePineDarkPinesTwo<220) {
triangle(treeLinePineDarkX+20, treeLinePineDarkPinesTwo-15, treeLinePineDarkX-80, treeLinePineDarkPinesTwo+70, treeLinePineDarkX-30, treeLinePineDarkPinesTwo+40);
treeLinePineDarkPinesTwo+=20;
}
rect(treeLinePineDarkX, 0, treeLinePineDarkX+20, 310);
ellipse(treeLinePineDarkX+10, 310, 20, 10);
treeLinePineDarkX+=100;
treeLinePineDarkPines=5;
treeLinePineDarkPinesTwo=5;
}
}
//Draws the three mushrooms
void drawMushrooms() {
ellipseMode(CENTER);
rectMode(CORNERS);
noStroke();
//mushroom1
fill(120, 255, 198);
ellipse(mushroom1X, mushroom1Y, 20, 20);
quad(mushroom1X-10, mushroom1Y, mushroom1X+10, mushroom1Y, mushroom1X+5, mushroom1Y-20, mushroom1X-5, mushroom1Y-20);
fill(151, 0, 204);
ellipse(mushroom1X-30, mushroom1Y-30, 20, 20);
ellipse(mushroom1X+30, mushroom1Y-30, 20, 20);
rect(mushroom1X-30, mushroom1Y-30, mushroom1X+30, mushroom1Y-20);
arc(mushroom1X, mushroom1Y-30, 80, 70, PI, TWO_PI);
fill(120, 255, 198);
ellipse(mushroom1X-15, mushroom1Y-45, 15, 15);
ellipse(mushroom1X+10, mushroom1Y-30, 5, 5);
ellipse(mushroom1X+20, mushroom1Y-40, 20, 20);
//mushroom2
fill(120, 255, 198);
ellipse(mushroom2X, mushroom2Y, 20, 20);
quad(mushroom2X-10, mushroom2Y, mushroom2X+10, mushroom2Y, mushroom2X+5, mushroom2Y-20, mushroom2X-5, mushroom2Y-20);
fill(151, 0, 204);
ellipse(mushroom2X-30, mushroom2Y-30, 20, 20);
ellipse(mushroom2X+30, mushroom2Y-30, 20, 20);
rect(mushroom2X-30, mushroom2Y-30, mushroom2X+30, mushroom2Y-20);
arc(mushroom2X, mushroom2Y-30, 80, 70, PI, TWO_PI);
fill(120, 255, 198);
ellipse(mushroom2X-15, mushroom2Y-45, 15, 15);
ellipse(mushroom2X+10, mushroom2Y-30, 5, 5);
ellipse(mushroom2X+20, mushroom2Y-40, 20, 20);
//mushroom3
fill(120, 255, 198);
ellipse(mushroom3X, mushroom3Y, 20, 20);
quad(mushroom3X-10, mushroom3Y, mushroom3X+10, mushroom3Y, mushroom3X+5, mushroom3Y-20, mushroom3X-5, mushroom3Y-20);
fill(151, 0, 204);
ellipse(mushroom3X-30, mushroom3Y-30, 20, 20);
ellipse(mushroom3X+30, mushroom3Y-30, 20, 20);
rect(mushroom3X-30, mushroom3Y-30, mushroom3X+30, mushroom3Y-20);
arc(mushroom3X, mushroom3Y-30, 80, 70, PI, TWO_PI);
fill(120, 255, 198);
ellipse(mushroom3X-15, mushroom3Y-45, 15, 15);
ellipse(mushroom3X+10, mushroom3Y-30, 5, 5);
ellipse(mushroom3X+20, mushroom3Y-40, 20, 20);
}
//Draws Alice
void drawAlice() {
noStroke();
fill(255, 68, 41);
triangle(aliceFeetX-6, aliceFeetY-78, aliceFeetX, aliceFeetY-88, aliceFeetX+6, aliceFeetY-80);
triangle(aliceFeetX-6, aliceFeetY-78, aliceFeetX-15, aliceFeetY-80, aliceFeetX-10, aliceFeetY-74);
fill(232, 187, 109);
ellipse(aliceFeetX, aliceFeetY-67.5, 25, 25);
triangle(aliceFeetX-12, aliceFeetY-73, aliceFeetX-14, aliceFeetY-52, aliceFeetX-5, aliceFeetY-70);
quad(aliceFeetX-15, aliceFeetY-37, aliceFeetX+18, aliceFeetY-35, aliceFeetX+12, aliceFeetY-70, aliceFeetX-5, aliceFeetY-75);
fill(255, 255, 132);
quad(aliceFeetX, aliceFeetY-40, aliceFeetX+3, aliceFeetY-40, aliceFeetX+3, aliceFeetY-55, aliceFeetX+1, aliceFeetY-55);
ellipse(aliceFeetX, aliceFeetY-65, 20, 20);
arc(aliceFeetX, aliceFeetY-60, 20, 12, PI-HALF_PI, TWO_PI-HALF_PI);
fill(50);
stroke(50);
strokeWeight(1);
ellipse(aliceFeetX-5, aliceFeetY-64, 2, 2);
ellipse(aliceFeetX+2, aliceFeetY-64, 2, 2);
line(aliceFeetX-4, aliceFeetY-64, aliceFeetX-7, aliceFeetY-65);
line(aliceFeetX+2, aliceFeetY-64, aliceFeetX+5, aliceFeetY-65);
line(aliceFeetX-3, aliceFeetY-58, aliceFeetX-1, aliceFeetY-56);
line(aliceFeetX-1, aliceFeetY-56, aliceFeetX+1, aliceFeetY-58);
noStroke();
fill(232, 187, 109);
triangle(aliceFeetX-5, aliceFeetY-80, aliceFeetX+3, aliceFeetY-76, aliceFeetX, aliceFeetY-64);
triangle(aliceFeetX+3, aliceFeetY-75, aliceFeetX+12, aliceFeetY-70, aliceFeetX+10, aliceFeetY-48);
fill(255, 255, 132);
quad(aliceFeetX-8, aliceFeetY-45, aliceFeetX-5, aliceFeetY-38, aliceFeetX-5, aliceFeetY-20, aliceFeetX-10, aliceFeetY-20);
quad(aliceFeetX+10, aliceFeetY-40, aliceFeetX+13, aliceFeetY-40, aliceFeetX+18, aliceFeetY-25, aliceFeetX+15, aliceFeetY-22);
ellipse(aliceFeetX+18, aliceFeetY-23, 7, 5);
fill(255, 68, 41);
ellipse(aliceFeetX-4, aliceFeetY-45, 10, 10);
ellipse(aliceFeetX+8, aliceFeetY-45, 10, 10);
ellipse(aliceFeetX+2, aliceFeetY-40, 15, 15);
arc(aliceFeetX+2, aliceFeetY-10, 30, 50, PI, TWO_PI);
fill(255);
triangle(aliceFeetX-1, aliceFeetY, aliceFeetX+2, aliceFeetY-10, aliceFeetX-4, aliceFeetY-10);
triangle(aliceFeetX+7, aliceFeetY, aliceFeetX+4, aliceFeetY-10, aliceFeetX+10, aliceFeetY-10);
}
/////////////////////////////////////////////////////////////////////////////////////
//Pseudocode
/////////////////////////////////////////////////////////////////////////////////////
//1. Begin by setting a default frame rate and a size for the program.
//2. Draw the background then draw a tree.
//3. Keep drawing the tree over and over a certain amount apart until it hits the right side of the screen.
//4. Do step 4 for two more layers of trees.
//5. Draw a mushroom 3 times.
//6. Draw Alice in the air.
//7. When Alice is in the air, let her fall downwards at a constant speed. But if she is not falling, then she is probably rising into the air.
//8. If Alice hits the ground then she stays on the ground and the line ‘Game Over!’ is displayed.
//9. If the D button is pressed Alice moves right by increasing her value.
//10. If the A button is pressed Alice moves left by decreasing her value.
//11. Check Alice is trying to move off screen to left (or right). If so then put her to the left (or right) edge of the screen.
//12. When Alice touches the top of a mushroom, her decent stops and she begins to ascend at a random speed.
//13. Once Alice reaches a a random height, she begins to fall again.