# rgriswol_FinalProject

My project changed a lot from what I originally intended. At first I wanted a more traditional, Mario-like 8 bit game. However, while I was working on my project I started watching the show Supergirl and fell in love with it, so I wanted to make a game based off of her. Instead of running around and jumping, the player character (Supergirl) flies through the air to save Lois Lane, all while trying to avoid obstacles in her way.
This was a lot of fun to make, and hopefully in the future I can make something more complex!

``````/*
* Rachel Griswold
* rgriswol@andrew.cmu.edu
* Section B
* Final Project
*
*/

var started = false;
var gameOver = false;
var terrainSpeed = 0.0003; //speed of hills
var terrainDetail = 0.005;
var terrain = [];
var cloudX = [];
var cloudY = [];
var birdX = [];
var birdY = [];
var treeX = []; // the trees are actually buildings, for reference - changed my mind last minute
var treeH = [];
var speedMod = 0;
var img1; // supergirl
var img2; // airplanes
var img3; // buildings
var img4; // clouds

}

function updateLocation(){ //moves the objects
for(i = 0; i < cloudX.length; i++){
cloudX[i] = cloudX[i] - 1 - speedMod/200;
if(cloudX[i] < -150){ //makes the clouds go away
cloudX.splice(i,1);
cloudY.splice(i,1);
}
}
for(i = 0; i < birdX.length; i++){
birdX[i] = birdX[i] - 1 - speedMod/200;
if(birdX[i] < -100){ //makes the birds go away
birdX.splice(i,1);
birdY.splice(i,1);
}
}
for(i = 0; i < treeX.length; i++){
treeX[i] = treeX[i] - 1 - speedMod/200;
if(treeX[i] < -150){ //makes the buildings go away
treeX.splice(i,1);
treeH.splice(i,1);
}
}
}

function drawCloud(x, y){ //creates cloud
image(img4, x, y);
}

function drawClouds(){ //places clouds
for(i = 0; i < cloudX.length; i++){
drawCloud(cloudX[i], cloudY[i]);
}
}

function drawBird(x, y){ //creates airplane
image(img2, x, y);
}

function drawBirds(){ //places airplanes
for(i = 0; i < birdX.length; i++){
drawBird(birdX[i], birdY[i]);
}
}

function drawTree(x, h){ //creates building
image(img3, x, height-h-20);
}

function drawTrees(){ //places buildings
for(i = 0; i < treeX.length; i++){
drawTree(treeX[i], treeH[i]);
}
}

function checkGameOver(){
for(i = 0; i < treeX.length; i++){
x = treeX[i];
h = treeH[i];
if(!(mouseX < x - 20 || mouseX > x + 142 + 20 || mouseY < height - h - 20 || mouseY > height)){
gameOver = true;
break;
}
}
for(i = 0; i < birdX.length; i++){
x = birdX[i];
y = birdY[i];
if(!(mouseX < x - 20 || mouseX > x + 102 + 20 || mouseY < y - 10 || mouseY > y + 83)){
gameOver = true;
break;
}
}
}

function setup(){
createCanvas(600, 400);
noCursor();
}

function draw() {

if(gameOver == true){
background(0);
fill(255, 0, 0);
textSize(60);
textAlign(CENTER);
text("GAME OVER", width/2, height/2);
textSize(30);
textAlign(CENTER);
text("Oh no! Now who will save Lois?", width/2, 280);
fill(255);
textSize(20);
textAlign(CENTER);
text("click to try again", width/2, 350);

if(mouseIsPressed){
gameOver = false;
started = false;
treeX = [];
treeH = [];
cloudX = [];
cloudY = [];
birdX = [];
birdY = [];

speedMod = 0;
}
}

else{

if(started == true){ // loads game
speedMod++;
background(190, 240, 255);

fill(255, 0, 0);
textSize(16);
textAlign(CENTER);
text("Score = " + speedMod, 50, 20);

checkGameOver();

drawClouds(); // draws clouds
if(random(0, 100) < 1 + speedMod/2000){
cloudX.push(700);
cloudY.push(random(20, 200));
}

drawBirds(); // draws airplanes
if(random(0, 100) < 0.5 + speedMod/2000){
birdX.push(700);
birdY.push(random(20, 200));
}

drawTrees(); // draws buildings
if(random(0, 100) < 0.5 + speedMod/2000){
treeX.push(700);
treeH.push(random(20, 200));
}

updateLocation();

image(img1, mouseX - 30, mouseY - 30); // supergirl

}

else{ // starting screen
background(140, 220, 235);

fill(255, 0, 0);
textSize(60);
textAlign(CENTER);
text("SUPERGIRL", width/2, 150);

fill(0, 0, 255);
textSize(20);
textAlign(CENTER);
text("Lois Lane is in trouble! Can Supergirl get there in time?", width/2, height/2);
text("Don't hit the buildings or the airplanes!", width/2, 240);

fill(255);
textSize(30);
textAlign(CENTER);
text("Press any key to play!", width/2, 300);

if(keyIsPressed === true){
started = true;
}

}
}

}``````