# jwchou-final project-E

For my project, I decided to stay with the theme I had developed throughout the semester with plane-based projects.

The objective of the game is to fly the plane onto the runway while avoiding mountains and lightning. Instructions for running the game are included.

I had a really hard time with this project. My original concept was perhaps more interesting but I had an extremely hard time executing it, so I pivoted my project to this secondary concept at the last minute. However, I had a lot of fun creating it, as well as working on the styling and themes of the splash screens in particular. I hope you enjoy it!

``````//Jackie Chou
//jwchou@andrew.cmu.edu
//Section E
//Final Project

//stores image variables
var explosion;
var lost;
var crash;
var win;
var beginScreen;
var lightning;
var mountain;
var img;

//variable to determine if the game has started
var gameStarted = false;

//position and speed variables for the plane
var xPos = 240;
var yPos = 0;
var xSpeed = 0;
var ySpeed = 0;

//arrays to store the obstacles in
var mountains = [];
var lightnings = [];

function setup() {
createCanvas(480, 480);

//pushes random coordinates into the obstacle arrays
for (i = 0; i < 8; i++) {
lightnings.push(random(0, width));
lightnings.push(random(80, 350));
mountains.push(random(0, width));
mountains.push(random(80, 350))
}
}

function draw() {
imageMode(CENTER);
//draws background image
image(img, 240, 240);
//initializes plane if the game has begun
if (gameStarted == true){
ySpeed = 0.5;
}
//controls plane's direction
yPos += ySpeed;
xPos += xSpeed;
//calls function to draw obstacles
drawObstacles();
//displays splash screen before the game starts
if (gameStarted == false) {
image(beginScreen, width/2, height/2);
}
//drawing the airplane
fill(240);
strokeWeight(0.5);
//wings
ellipse(xPos, yPos, 70, 11);
ellipse(xPos, yPos - 20, 35, 8);
//horz stabilizer
fill(108, 190, 225);
ellipse(xPos, yPos, 17, 45);
//fuselage
ellipse(xPos + 17, yPos + 5, 6, 15);
//left engine
ellipse(xPos - 17, yPos + 5, 6, 15);
//right engine
fill(0);
ellipse(xPos - 17, yPos + 10, 10, 2);
//right propeler
ellipse(xPos + 17, yPos + 10, 10, 2);
//left propeller
fill(240);
ellipse(xPos, yPos - 25, 5, 17);
//tail
fill(0);
beginShape();
//cockpit
vertex(xPos - 5, yPos + 10);
vertex(xPos, yPos + 17);
vertex(xPos + 5, yPos + 10);
vertex(xPos + 5, yPos + 5);
vertex(xPos, yPos + 10);
vertex(xPos - 5, yPos + 5);
vertex(xPos - 5,yPos +  10);
endShape();
//checks to see if the plane has collided into lightning
for (i = 0; i < lightnings.length; i += 2) {
if (dist(xPos, yPos, lightnings[i], lightnings[i+1]) <= 35) {
gameOver();
}
}
//checks to see if the plane has collided in mountains
for (i = 0; i < mountains.length; i += 2) {
if (dist(xPos + 3, yPos, mountains[i], mountains[i+1]) <= 38) {
gameOver();
}
}
//calls landing function if plane crosses top edge of runway
if (dist(xPos, yPos, 235, 440) <= 15) {
xSpeed = 0;
ySpeed = 0;
landed();
}
//calls lost screen function if plane leaves canvas (x)
if (xPos <= 10 || xPos >= 470) {
gotLost();
}
//calls lost screen function if plane leaves canvas (y)
if (yPos >= 470) {
gotLost();
}
}

//draws the obstacles using randomized values from the arrays
function drawObstacles() {
for (i = 0; i < lightnings.length; i += 2) {
image(lightning, lightnings[i], lightnings[i+1]);
//image(mountain, random(0, width), random(80, 350));
}
for (i = 0; i < mountains.length; i += 2) {
image(mountain, mountains[i], mountains[i+1]);
}
}

//controls the direction of the plane via arrow keys
function keyPressed() {
if (keyCode === RIGHT_ARROW) {
xSpeed = 0.65;
}
if (keyCode === LEFT_ARROW) {
xSpeed = -0.65;
}
if (keyCode === DOWN_ARROW) {
xSpeed = 0;
}
}

//starts the game
function mousePressed() {
gameStarted = true;
}

//game over function, displays splash screen
function gameOver() {
image(explosion, xPos, yPos - 3);
image(crash, width/2, height/2);
noLoop();
}

//plane lost function
function gotLost() {
image(lost, width/2, height/2);
noLoop();
}

//plane landed function
function landed() {
image(win, width/2, height/2);
noLoop();
}``````