Final Project

This program is a Covid-19 version of whack-a-mole called put-on-a-mask. The idea was inspired by an online game that my friends and I played during the pandemic called Covidopoly, a Covid-19 version of the board game Monopoly. Like this game, I wanted to make some light out of this dark situation we are in a make a fun, easy, time-passing game that will (hopefully) keep making you play until the pandemic is over.
To play is simple: the player must put masks on the viruses as fast as they can. There will be a total of 4 viruses on the screen at all times and once a virus is successfully clicked (accompanied by a “pop” sound), it will regenerate in a random color to a random position. If the player misses or takes too long to click a virus, they will get a strike– an accumulation of 3 strikes will end the game. The virus that was on the screen for too long will disappear on its own and regenerate in a new random color and position. Every 20 points, the player will level up which makes the time it takes a virus to disappear on its own shorter.
If I had more time, I would like to add more complex elements to the game like making the viruses move around, add more viruses to the screen after a certain amount of levels, or add more clickable elements for bonus points or strike reductions.

sketch
var covidviruses = [];
var covidImageLinks = ["https://i.imgur.com/iUnzt1x.png", 
                        "https://i.imgur.com/V9cdbDy.png", 
                        "https://i.imgur.com/OjUptCF.png", 
                        "https://i.imgur.com/heDuTxd.png",
                        "https://i.imgur.com/PoNLrQ1.png",
                        "https://i.imgur.com/oIF3cp7.png",
                        "https://i.imgur.com/jc8muyt.png",
                        "https://i.imgur.com/X6MPvtK.png"]
var mask;
var coronavirusSound;
var popSound;
var clickSound;
var covidX = [150, 200, 300, 350];
var covidY = [300, 150, 200, 250];
var strike = 0;
// array of virus objects
var virus = [];
var page = 1;
var score = 0;
var ageIncrease = 1;
var maxScore = 0;
var gameLevel = 1;
var angle = 20;

function preload() {
    // load pictures (different color viruses)
    for(var i = 0; i < covidImageLinks.length; i ++) {
        covidviruses[i] = loadImage(covidImageLinks[i]);
    }
    mask = loadImage("https://i.imgur.com/DdBChjv.png");
    coronavirusSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/coronavirus.wav");
    popSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/pop.wav");
    clickSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/click.wav")
}

function setup() {
    createCanvas(480, 480);
    useSound();
    // create array of objects of 4 starter viruses (location, size, color, age)
    for(var i = 0; i < 4; i ++) {
        virus[i] = new Object();
        virus[i].x = covidX[i];
        virus[i].y = covidY[i];
        virus[i].color = floor(random(0, 8));
        virus[i].size = 90;
        virus[i].age = 0;
     }
     frameRate(40);
     noStroke();
}

function soundSetup() { 
    coronavirusSound.setVolume(.5);
    popSound.setVolume(.5);
    clickSound.setVolume(.5);
}


function draw() {
    // title page 
    if(page == 1) {
        cursor();
        createTitlePage();
    }
    // game
    if(page == 2) {
        noCursor();
        background("#BFEDFF");
        // draw 4 viruses to begin
        for(var i = 0; i < 4; i ++) {
            image(covidviruses[virus[i].color], virus[i].x, virus[i].y, virus[i].size, virus[i].size);
            // add virus age
            virus[i].age += ageIncrease;
            // if virus has been unclicked for 200 frames --> strike + new virus replacement
            if(virus[i].age == 200) {
                makeNewVirus(i);
                strike += 1;
            }
        }   
        // 3 misses --> game over
        if(strike == 3) {
        // go to end page
            page = 3;
        }

        // mask on cursor
        imageMode(CENTER);
        image(mask, mouseX, mouseY, 90, 90);
        
        updateScore();

        // level up every 20 points and increase aging rate (so virus disappears faster)
        if(score%20 == 0 & score > maxScore) {
            ageIncrease += 1;
            maxScore = score;
            gameLevel += 1;
        }
    }

    // end page
    if(page == 3) {
        cursor();
        createEndPage();
    }

    // help page
    if(page == 4) {
        cursor();
        createHelpPage();
    }
}

function mousePressed() {
    // thresholds of a success click for viruses
    var d = [];
    for(var i = 0; i < 4; i ++) {
        d[i] = dist(mouseX, mouseY, virus[i].x, virus[i].y);
    }

    // title page
    if(page == 1) {
        // play  button --> reset everything
        if(mouseX > 190 & mouseX < 290 && mouseY > 305 && mouseY < 355) {           
            // go to game page
            clickSound.play();
            strike = 0;
            score = 0;
            ageIncrease = 1;
            maxScore = 20;
            gameLevel = 1;
            page = 2;
        }
        if(mouseX > 165 & mouseX < 315 && mouseY > 135 && mouseY < 285){
            // sound effect
            coronavirusSound.play();
        }
        if(mouseX > 140 & mouseX < 340 && mouseY > 365 && mouseY < 415) {
            clickSound.play();
            page = 4;
        }
    }

    // game page
    else if(page == 2) {
        // if clicks are successes for any 4 of the viruses --> make pop sound, score increase by 1, new virus replacement
        if (d[0] < 45) {
            popSound.play();
            makeNewVirus(0);
            score += 1;
        }
        else if (d[1] < 45) {
            popSound.play();
            makeNewVirus(1);
            score += 1;
        }
        else if(d[2] < 45) {
            popSound.play();
            makeNewVirus(2);
            score += 1;
        }
        else if(d[3] < 45) {
            popSound.play();
            makeNewVirus(3);
            score += 1;
        }
        else { // a miss
            strike += 1;
        }
    }

    // end page
    else if(page == 3) {
        // play again button --> reset everything
        if(mouseX > 125 & mouseX < 355 && mouseY > 290 && mouseY < 370) {
            clickSound.play();
            strike = 0;
            score = 0;
            ageIncrease = 1;
            maxScore = 20;
            gameLevel = 1;
            page = 2;
        }
        // go back to main page
        if(mouseX > 140 & mouseX < 340 && mouseY > 365 && mouseY < 415) {
            clickSound.play();
            page = 1;
        }
    }

    // help page
    else if(page == 4) {
        // play  button --> reset everything
        if(mouseX > 190 & mouseX < 290 && mouseY > 305 && mouseY < 355) {           
            // game page
            clickSound.play();
            strike = 0;
            score = 0;
            ageIncrease = 1;
            maxScore = 20;
            gameLevel = 1;
            page = 2;
        }
        // return to main page
        if(mouseX > 140 & mouseX < 340 && mouseY > 365 && mouseY < 415) {
            clickSound.play();
            page = 1;
        }
    }
        
}

// replace clicked viruses or missed viruses 
function makeNewVirus(index) {
    covidX[index] = random(90, 390);
    covidY[index] = random(135, 390);

    virus[index].x = covidX[index];
    virus[index].y = covidY[index];
    virus[index].color = floor(random(0, 8));
    virus[index].size = 90;
    virus[index].age = 0;

}

// title page (page 0)
    // button to play
    // button to go to help page
    // interactive graphic (makes sound)
function createTitlePage() {
    background("#D7C9FF");
    // play button
    if(mouseX > 190 & mouseX < 290 && mouseY > 305 && mouseY < 355) {     
        fill("pink");
    }
    else{
        fill("white");
    }

    rectMode(CENTER);
    rect(width/2, 330, 100, 50);
    
    // help button
    if(mouseX > 140 & mouseX < 340 && mouseY > 365 && mouseY < 415) {
        fill("pink");
    }
    else{
        fill("white");
    }
    rect(width/2, 390, 200, 50);

    textSize(30);
    textAlign(CENTER);

    // text, box labels
    fill("black");
    text("put on a mask!", width/2, height/4);
    text("play!", width/2, 340);
    text("how to play", width/2, 400);
    textSize(10);
    text("click on me!", width/2, 280);

    // animation using transformation
    // viruses moving around the borders
    imageMode(CORNER);
    virusBorder();

    // sound effect virus
    // mouse hover --> rotate
    push();
    translate(240, 210);
    if(mouseX > 165 & mouseX < 315 && mouseY > 135 && mouseY < 285){
        rotate(radians(angle));
    }
    imageMode(CENTER);
    image(covidviruses[6], 0, 0, 150, 150);
    pop();
    angle += 5;
    
}

// page 3
function createEndPage() {
    background("#D7C9FF");    
    
    // play button
    if(mouseX > 125 & mouseX < 355 && mouseY > 290 && mouseY < 370) {
        fill("pink");
    }
    else {
        fill("white");
    }
    rectMode(CENTER);
    rect(width/2, 330, 200, 50);
    
    // return to main page
    if(mouseX > 140 & mouseX < 340 && mouseY > 365 && mouseY < 415) {
        fill("pink");
    }
    else {
        fill("white");
    }
    rect(width/2, 390, 200, 50);

    // text, button labels
    fill("black");
    textSize(30);
    textAlign(CENTER);
    text("game over!", width/2, 150);
    textSize(20);
    text("Score: " + str(score), width/2, 200);
    text("Highest Level: " + str(gameLevel), width/2, 230);
    textSize(30);
    text("play again!", width/2, 340);
    text("main page", width/2, 400);

    imageMode(CORNER);
    virusBorder();
}

// keep track of score, strikes, level on game page
function updateScore() {
    // print current score, strikes, and level at top
    textSize(20);
    textAlign(CENTER);
    text("Score: " + str(score), width/2, 50);
    text("Strikes: " + str(strike), width/2, 70);
    text("Level " + str(gameLevel), width/2, 90);
}

// border pattern
function virusBorder() {
    for(var i = 0; i < width; i += 40) {
        image(covidviruses[floor(random(0, 8))], i, 0, 40, 40);
        image(covidviruses[floor(random(0, 8))], i, 440, 40, 40);
        image(covidviruses[floor(random(0, 8))], 0, i, 40, 40);
        image(covidviruses[floor(random(0, 8))], 440, i, 40, 40);
    }
}

// help page, page 4
function createHelpPage() {
    background("#D7C9FF");
    rectMode(CENTER);

    // play button
    if(mouseX > 190 & mouseX < 290 && mouseY > 305 && mouseY < 355) {     
        fill("pink");
    }
    else{
        fill("white");
    }
    rect(width/2, 330, 100, 50);
    
    // return to home button
    if(mouseX > 140 & mouseX < 340 && mouseY > 365 && mouseY < 415) {
        fill("pink");
    }
    else{
        fill("white");
    }
    rect(width/2, 390, 200, 50);

    // text, labels
    fill("black");
    textSize(30);
    textAlign(CENTER);
    // page button
    text("play!", width/2, 340);
    // help button
    text("main page", width/2, 400);

    text("how to play:", width/2, 120);
    textSize(15);
    text("like whack-a-mole but covid edition! click on the viruses as they appear and cover them with masks! make sure to be fast because the higher the score, the faster they disappear! the game ends after you get 3 misses!", 
        width/2, 300, 300, 300);
    
    imageMode(CORNER);
    virusBorder();
}

Final Project: Covid-19 Precaution Simulator

In my final project, I showcase somewhat of a Covid-19 Precaution Simulation. The user is situated in the right side of the window and with the refreshing of the page, red virus balls and green mask/safety balls appear. The red viruses will come across the page at different speeds and sizes to symbolize the various ways of possibly contracting Covid-19. Hovering over the green safety orbs will help the users glowing shield to grow larger and brighter. As the shield grows, the viruses will be eliminated; at one point due to the immense “precautions and safety measures” that have been collected/taken by the user, the viruses die before reaching the shield, signifying that we can never be too safe in these times.

sketch
var shieldAttribute; //tracks size + color of shield
var mask=[]; //masks (green circles)
var virus = []; //virus (red circles)
var virusCount=10; //number of virus
var maskCount =15 // number of masks
var waves=10;
var x;
var y;
var speed;
var maskx;
var masky;
var maskr;
var checkMask;
var checkVirus;

function setup() {
  createCanvas(600, 400);
  shieldAttribute = 60; 
  for (var i = 0; i < virusCount; i++) {  //setting up to create virus objects
    var x;
    var y;
    var speed ;
    virus[i] = new Covid19(x, y, speed);
  }
  let checkMask = false;
  for (var j = 0; j < maskCount; j++) {  //creat mask objects
    mask[j] = new Masks(maskx, masky, maskr);
  }
}

function draw() {
  background(0);
  userGen();  //create user + shield 
  for (var i = 0; i < virusCount ; i++){  //functionality of virus implemented
    virus[i].generate();
    virus[i].forward();
    if(dist(virus[i].x, virus[i].y, 550, height/2)<= shieldAttribute-120){  //the virus balls get eliminated as they approach the growing shield
    virus[i].x = -600
  }
  }
  for (var j = 0; j < maskCount ; j++){  //functionality of virus implemented
    mask[j].build();
    mask[j].collect();
    mask[j].move();
  } 
}
//function for creating user
function userGen(){
  noStroke();
  fill(20,255,238,shieldAttribute/5);  //shield
  ellipse(550, height/2, shieldAttribute, shieldAttribute);
  
  fill(60, 198, 177);  //user circle
  ellipse(550, height/2 ,40, 40);
}

//COVID19 VIRUS CLASS
class Covid19 {
  constructor(){
    this.x = 0;
    this.y = random(20, 380);
    this.speed = random(0.5,2.5);
    this.virRad = random (30,50);
    this.checkVirus = false;
  }
  
  forward (){
  //  for (var i = 0; i < 5; i++){
    this.x += this.speed;
  }
  
  generate (){   //create the virus
    if (this.checkVirus == false){
    noStroke();
    fill(255,80,10);
    ellipse(this.x, this.y, this.virRad, this.virRad);
    }
  }
}

//MASK CLASS
class Masks {  
  constructor(){
    this.maskx = random(550);
    this.masky = random(350);
    this.maskr = random(10,80);
    this.checkMask = false;
  }
  
  build(){   //create the mask
    noStroke();  
    fill(50,240,80);
    if (this.checkMask == false){
    ellipse(this.maskx, this.masky, this.maskr);
    }
  }
  collect(){   //the mask balls disappear when hovered over, giving the illusion of "collecting"
    let d = dist(mouseX, mouseY, this.maskx , this.masky);
    if (d <= 20){
      shieldAttribute += this.maskr;
      this.checkMask = true;
      this.maskx = -600
      this.masky = -600
      this.maskr = 0
    }
  }
  
  move(){    //masks jittering to make collecting a bit more difficult
    this.maskx += random(-2,2);
    this.masky += random(-2,2);
  }
  
}

Final Project – Interactive Calendar

sketch
//Diana McLaughlin and Shaun Murray
//dmclaugh@andrew.cmu.edu and shaunmur@andrew.cmu.edu
//Section A and Section B
//A calendar commemorating a major event from each month in 2020
//All global variables except image variables are with the start of the respective month's program. Some of these variables are called in set up, but you'll find them before their clickMonthX() function
//Shaun's code starts at clickMonthJan(). He also wrote the makeCalendar() function
//Diana's code starts at clickMonthJul(). She also wrote the writeMonths() function
//Aside from the makeCalendar and writeMonths functions, Shaun did everything related to January - June and Diana did everything related to July - December
//"The biggest waste of computer processing power in 15-104"

//Image Variables
//for the main calendar
var imgJanCal, imgFebCal, imgMarCal, imgAprCal, 
	imgMayCal, imgJunCal, imgJulCal, imgAugCal, 
	imgSepCal, imgOctCal, imgNovCal, imgDecCal;

//for the month functions
var imgJan2, imgMar, aprImg, aprImg2, 
    aprImg3, imgJun1, imgJun2, imgJun3, 
    imgJul, imgOct, imgNov;


function preload() {
	imgJanCal = loadImage("https://i.imgur.com/mGCWr67.jpg?2"); //January main calendar
	imgFebCal = loadImage("https://i.imgur.com/8hI9x3x.jpg"); //February main calendar
	imgMarCal = loadImage("https://i.imgur.com/hozlVRU.jpg"); //March main calendar
	imgAprCal = loadImage("https://i.imgur.com/PUDQpPe.jpg"); //April main calendar
	imgMayCal = loadImage("https://i.imgur.com/FyUdmy7.png"); //May main calendar
	imgJunCal = loadImage("https://i.imgur.com/1V9Akde.jpg"); //June main calendar
	imgJulCal = loadImage("https://i.imgur.com/Tvukiin.jpg"); //July main calendar
	imgAugCal = loadImage("https://i.imgur.com/kECFW1b.jpg"); //August main calendar
	imgSepCal = loadImage("https://i.imgur.com/O6e3LcQ.jpg"); //September main calendar
	imgOctCal = loadImage("https://i.imgur.com/CcQpShS.jpg"); //October main calendar
	imgNovCal = loadImage("https://i.imgur.com/8Sqt5Um.jpg"); //November main calendar
	imgDecCal = loadImage("https://i.imgur.com/DrModlG.jpg"); //December main calendar

    imgJan = loadImage("https://i.imgur.com/UO8RoiW.png"); //santa hat for JAN
    imgJan2 = loadImage("https://i.imgur.com/lM5i1Gp.jpeg") //A-Bomb Jan
    imgFeb = loadImage("https://i.imgur.com/AIq3z8n.jpeg"); //House Chamber background
    imgMar = loadImage("https://i.imgur.com/VFoP91O.png"); //background image for March
    mayImg1 = loadImage("https://i.imgur.com/RhNvf13.jpeg"); //Kim Jong Un
	mayImg2 = loadImage("https://i.imgur.com/huOal0b.png"); //podium
	mayImg3 = loadImage("https://i.imgur.com/20G2Bj4.jpg"); //NK flag
    aprImg = loadImage("https://i.imgur.com/G0SnXSB.jpg"); //Tiger
	aprImg2 = loadImage("https://i.imgur.com/VVfSCll.jpeg"); //Oklahoma
	aprImg3 = loadImage("https://i.imgur.com/IgLfZQb.png"); //Joe Exotic
	imgJun1 = loadImage("https://i.imgur.com/V8MHehF.jpg"); //St John's Church
	imgJun2 = loadImage("https://i.imgur.com/on3fzqb.jpg"); //President
	imgJun3 = loadImage("https://i.imgur.com/SAUkUd3.jpg"); //Protesters
	imgJul = loadImage("https://i.imgur.com/FXdV1Bk.jpg"); //John Lewis photograph for July
    imgOct = loadImage("https://i.imgur.com/a7W8anl.png"); //map for Oct
    imgNov = loadImage("https://i.imgur.com/OCT1IpR.jpg"); //auditorium for November
}

function setup() {
    createCanvas(500, 400);
    makeCalendar();

    //set up March
    for (var i = 0; i < 1; i++) {
    // make virus cell
    	var v = makeVirus(200, 200,
                             random(-50, 50), random(10, 50));
        viruses.push(v);
    }

    //set up for April
    for (var i = 0; i < 12; i++){ // create an initial collection of cats
        var rx = random(width);
        tigers[i] = makeTigers(rx);
    }

    //set up August
    for (var i = 0; i < 1; i++){
        var hy = random(height/3, height);
        hurricane[i] = makeHurricane(hy);
    } 
    
    //set up September
    //set up mountains
    for (var i = 0; i <= 100; i++) {
        var n = noise(noiseParam);
        var value = map(n, 0, 1, 0, height/2);
        mountain.push(value);
        noiseParam += noiseStep;
    }  

    //set up fire
    for (var i = 0; i <= 100; i++) {
        var n = noise(fNoiseParam);
        var value = map(n, 0, 1, 0, height);
        fire.push(value);
        fNoiseParam += fNoiseStep;
    }  
    
    //draw initial trees
    for (var i = 0; i < 10; i++){
        var rx = random(width);
        trees[i] = makeTree(rx);
    }
    
    //draw initial smoke clouds
    for (var i = 0; i < 10; i++){
        var cx = random(width);
        smoke[i] = makeSmoke(cx);
    }
    
}

function draw() {
	clickMonthJan();
	clickMonthFeb();
	clickMonthMar();
	clickMonthApr();
	clickMonthMay();
	clickMonthJun();
	clickMonthJul();
	clickMonthAug();
	clickMonthSep();
	clickMonthOct();
	clickMonthNov();
	clickMonthDec();
	backButton();
}

function makeCalendar() {
	fill(0);
    strokeWeight(1);
    //draw lines between the months on the calendar
    for (let i = 0; i < 3; i++) {
        line(0, i*133.33 + 133, width, i*133.33 + 133);
        line(i*125 + 125, 0, i*125 + 125, height);
    }

    //background pictures
    var calPics = [imgJanCal, imgFebCal, imgMarCal, imgAprCal, imgMayCal, imgJunCal, imgJulCal, imgAugCal, imgSepCal, imgOctCal, imgNovCal, imgDecCal];
    var xCo = [0.5, 125.5, 250.5, 375.5, 0, 125.5, 250.5, 375.5, 0.5, 125.5, 250.5, 375.5];
    var yCo = [0, 0, 0, 0, 132.83, 132.83, 132.83, 132.83, 267.16, 267.16, 267.16, 267.16];
    for (var i = 0; i < calPics.length; i++) {
    	image(calPics[i], xCo[i], yCo[i], 124.5, 132.83);
    }

    writeMonths();

}

function writeMonths() {
	//display text on calendar
	var monthText = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	var monthCode = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", " ", "="];
	var monthX = [55, 180, 305, 430, 55, 180, 305, 430, 55, 180, 305, 430];
	var monthY = [65, 65, 65, 65, 200, 200, 200, 200, 335, 335, 335, 335];
	strokeWeight(1);
	textFont('Times');
    textSize(24);
    textAlign(CENTER);
    stroke(0);
    fill(255);
    for (var i = 0; i < monthText.length; i++) {
    	text(monthText[i], monthX[i], monthY[i]);
    	text(monthCode[i], monthX[i], monthY[i] + 30);
    }
    textSize(40);
    text("-", 300, 363);
    textSize(15);
    textAlign(LEFT);
    text("Press a key to begin", 3, 25); //written instruction
    text("Press ESC to return", 380, 25);
}

function backButton() { //click to return to calendar
    if (keyCode === 27) {
        clearBkrd();
        makeCalendar();

        //reset March
        v.diam = 25;

        //reset November
        pCount = 0;
        vpCount = 0;
    }
}

function clearBkrd() { //clear background
    background(255);
}

//Shaun's Code

function clickMonthJan() {
	//Referencing the anticipation of North Korea's overdue X-mas gift
    if (keyCode === 49) {
        clearBkrd();
        frameRate(30);
        JanBackground();
        USflag();
        NKflag();
        nuclear(width/2, height/2);
        JanText(45, height-85);
        backButton(); 
    }
         
}

	function JanBackground() {
		image(imgJan2, 0, 0, width, height);
	}

    function starJan() {
        var x1 = [340, 348, 364, 354, 356, 340, 324, 326, 315, 332]; //star points
        var y1 = [44, 58, 62, 75, 92, 85, 92, 75, 62, 58];
        var nPoints= x1.length;
        beginShape();
        fill('Red');
        for (var i= 0; i< nPoints; i++) {
            vertex(x1[i] + 35, y1[i] + 5);
        }
        endShape(CLOSE);
    }

    function USflag() {// United States Flag minus stars
        fill('Red');
        rect(25, 25, width/3, height/4);
        for(let i = 0; i < 7; i++) { //white rects on flag
            fill('white');
            rect(25, 30 + (i * 13.5), width/3, 7);
        }
        fill(0, 0, 155);
        rect(25, 25, 50, 50);
    }

    function NKflag() { //North Korean Flag
        fill('Blue');
        rect(width-164, 25, width/3, height/4);
        push();
        fill('Red');
        strokeWeight(5);
        noStroke();
        rect(width-163, 40, width/3 + 6, 70); //white border in flag
        stroke('White');
        line(width, 40, width-161, 40);
        line(width, 110, width-161, 110);
        pop();
        noStroke();
        fill('White');
        circle(width-125, 75, 53);
        stroke(0);
        push();
        starJan();
        pop();
    }

    function nuclear(x, y) { //nuclear symbol
        push();
        translate(x, y);
        let d = 80
        let d1 = 10
        stroke(0);
        strokeWeight(3);
        fill('yellow'); //draw circles
        circle(0, 0, d);
        fill('black');
        circle(0, 0, d1);

        let deg = 120;
        let dx = 5;
        let angle = 45;

        rotate(radians(angle));
        for (let i = 0; i < 3; i++) { //draw triangles 
            rotate(radians(deg));
            beginShape();
            fill('black');
            vertex(-7, -7);
            vertex(-30, -10);
            vertex(-10, -30);
            endShape(CLOSE);
        }

        angle = angle + dx;
        pop();

        push();
        rotate(radians(-20));
        image(imgJan, 135, 185, 100, 100); //santa hat
        pop();

    }

    function JanText(x, y) { //display text for Jan
        push();
        translate(x, y);
        textSize(23);
        fill(255);
        text("United Shaysh of America VS. North Korea", 0, 0);
        pop();
    }

//Global variables for Feb
var rip = 0//checks to see if SotU is ripped

function clickMonthFeb() {
	//Referencing the ripped speech at the State of the Union address
    if (keyCode === 50) {
        clearBkrd();
        frameRate(30);
        drawPaper();
		drawRip();
		mendPaper();
        backButton();
    }   
    
}

	//February helper functions
	function drawPaper() { //draw initial SotU
		push();
		background('grey');
		image(imgFeb, 0, 0);
		fill('white');
		rectMode(CENTER);
		rect(width/2+30, height/2, 200, 300);
		rect(width/2+15, height/2, 200, 300);
		rect(width/2, height/2, 200, 300);
		textStyle(ITALIC);
		textSize(22);
		fill('black');
		text("State of the Union", 160, 80);
		fill('white');
		text("Click and hold to rip!", width-205, 25);
		text("Nancy Pelosi Simulator", 10, 25);
		line(180, 110, 320, 110);
		for (let i = 0; i < 20; i++) {
			line(165, 120 + i*11, 335, 120 + i*11);
		}
		pop();
	}

	function drawRip() { //Rip SotU
		push();
		if (mouseIsPressed) {
			background('grey');
			image(imgFeb, 0, 0);
			textStyle(ITALIC);
		    textSize(22);
			fill('white');
			text("Release mouse to mend...", 10, 25);
			push();
			rotate(radians(-30));
			fill('white');
			rectMode(CORNER);
			rect(width/2-300, height/2-80, 100, 300);
			for (let i = 0; i < 20; i++) {
				line(-40, 190 + i*11, 40, 190 + i*11);
			}
			fill('black');
			text("State of t", -50, 160);
			rotate(radians(60));
			fill('white');
			rect(width/2+160, height/2-345, 100, 300);
			for (let j = 0; j < 20; j++) {
				line(width/2+175, height/2-280 + j*11, width/2+250, height/2-280 + j*11);
			}
			fill('black');
			text("he Union", width/2+162, height/2-300);
			pop();
			pop();
			rip = 1;
		}
	}

	function mendPaper() { //Tape SotU back together like a good American
		push();
		if (rip == 1 & !mouseIsPressed) {
			background('grey');
			image(imgFeb, 0, 0);
			fill('white');
			rectMode(CENTER);
			rect(width/2+30, height/2, 200, 300);
			rect(width/2+15, height/2, 200, 300);
			rect(width/2, height/2, 200, 300);
			textStyle(ITALIC);
			textSize(22);
			fill('black');
			text("State of the Union", 160, 80);
			fill('white');
			text("Click and hold to rip!", width-205, 25);
		    text("Nancy Pelosi Simulator", 10, 25);
			fill('black');
			line(180, 110, 320, 110);
			for (let i = 0; i < 20; i++) {
				line(165, 120 + i*11, 335, 120 + i*11);
			}
	        fill(255, 248, 220);
			rect(width/2-15, height/2, 30, 300);
			pop();
		}
	}
//Global variable for March
var viruses = [];

function clickMonthMar() {
	//Referencing the spread of COVID-19 in the U.S.
    if (keyCode === 51) {
        clearBkrd();
        backButton();
        frameRate(15);
        image(imgMar, 0, 0, 500, 400);

	    for (var i = 0; i < viruses.length; i++) {
	        var v = viruses[i];
	        v.stepFunction();
	        v.drawFunction();
	        if (v.diam > 450) {
	        	background(0);
	        	stroke(255, 0, 0);
	        	strokeWeight(4);
	        	push();
	        	textSize(48);
	        	translate(width/2, height/2)
	        	rotate(radians(90));
	        	text(":(", 0, 0);
	        	pop();
	        	stroke(0);
	        	strokeWeight(2);
	        	fill('white');
	        	text("Sad", width/2, height/2 + 100);
	        }
	    }
    }   
    
}

	//March Helper Functions
	function virusStep() {
    this.age++;
    this.x += this.dx;
    this.y += this.dy;
    if (this.x > width) { // bounce off right wall
        this.x = width - (this.x - width);
        this.dx = -this.dx;
        this.diam *= 1.25;
    } else if (this.x < 0) { // bounce off left wall
        this.x = -this.x;
        this.dx = -this.dx;
        this.diam *= 1.25;
    }
    if (this.y > height) { // bounce off bottom
        this.y = height - (this.y - height);
        this.dy = -this.dy;
        this.diam *= 1.25;
    } else if (this.y < 0) { // bounce off top
        this.y = -this.y;
        this.dy = -this.dy;
        this.diam *= 1.5;
    }
	}


	function virusDraw() {
		stroke('black');//body of virus
		strokeWeight(2);
		fill('red');
		push();
	    translate(this.x, this.y);
		circle(0, 0, this.diam);
		strokeWeight(3);//stems of virus
		var angle = 45;
		for (let i = 0; i < 8; i++) {
			rotate(radians(angle));
			beginShape();
	        vertex(this.diam/2 - 10, 0)
	        vertex(random(this.diam/2 + 4, this.diam/2 + 8), random(-2, 2));
	        endShape(CLOSE);
	        ellipse(random(this.diam/2 + 8, this.diam/2 + 6), random(1, 3), 11, 9);
	    }
	    pop();
	}


	// create a "Particle" object with position and velocity
	function makeVirus(vx, vy, vdx, vdy) {
	    v = {x: vx, y: vy,
	         dx: vdx, dy: vdy,
	         age: 0,
	         diam: 25,
	         stepFunction: virusStep,
	         drawFunction: virusDraw
	        }
	    return v;
	}	

// Global variables for April
var tigers = [];
var deg = 10
var joe = 1;

function clickMonthApr() {
	//Referencing the popularity of the Tiger King documentary on NETFLIX in March/April
    if (keyCode === 52) {
        clearBkrd();
        frameRate(12);
        displayHorizon();
   		updateAndDisplayTigers();
    	removeTigersThatHaveSlippedOutOfView();
    	addNewTigersWithSomeRandomProbability();
        backButton();
    }
       
}

	function updateAndDisplayTigers(){
	    // Update the cats' positions, and display them.
	    for (var i = 0; i < tigers.length; i++){
	        tigers[i].move();
	        tigers[i].display();
	    }
	}


	function removeTigersThatHaveSlippedOutOfView(){
	    var tigersToKeep = [];
	    for (var i = 0; i < tigers.length; i++){
	        if (tigers[i].x + tigers[i].breadth > 0) {
	            tigersToKeep.push(tigers[i]);
	        }
	    }
	    tigers = tigersToKeep; // remember the surviving tigers
	}


	function addNewTigersWithSomeRandomProbability() {
	    // With a very tiny probability, add a new cat to the end.
	    var newTigersLikelihood = 0.03; 
	    if (random(0,1) < newTigersLikelihood) {
	        tigers.push(makeTigers(width));
	    }
	}


	// method to update position of cat every frame
	function tigersMove() {
	    this.x += this.speed;
	}
	    

	// draw the cat and more cats
	function tigersDisplay() {
	    push();
	    translate(this.x, height - floor(random(30, 40))); 
	    image(aprImg, 0, -15, 80, 35);
	    pop();
	}


	function makeTigers(birthLocationX) {
	    var tgs = {x: birthLocationX,
	                breadth: 50,
	                speed: -1.0,
	                move: tigersMove,
	                display: tigersDisplay}
	    return tgs;
	}

	function displayHorizon(){
		image(aprImg2, 0, 0, width, height);
		push();
		translate(60, 80);
		imageMode(CENTER);
		rotate(radians(deg));
		for (let i = 0; i < joe; i++) {
			image(aprImg3, 0, 0, 80, 80);
		}
		pop();
		deg = deg + 10;
	}

function clickMonthMay() {
	//Referencing Kim Jong Un's questionable health and reappearance
    if (keyCode === 53) {
        clearBkrd();
        frameRate(60);
        drawBackdrop();
		leader();
		drawPodium();
        backButton(); 
    }  
    
}

	//May helper functions
	function leader() {
		push();
		var top = height/2;
	    var bottom = height;
	    var conY = constrain(mouseY, top, bottom);
		imageMode(CENTER);
		image(mayImg1, width/2, conY, 120, 180);
		pop();
	}

	function drawPodium() {
		push();
		imageMode(CENTER);
		image(mayImg2, 250, 400, 300, 250);
		pop();
	}

	function drawBackdrop() {
		push();
		imageMode(CENTER);
		image(mayImg3, width/2, height/2, 500, 400);
		textSize(20);
		fill('black');
		text("N.K. Leader Simulator", 10, 30);
		text("Moves with your mouse!", width-210, 30);
		pop();
	}

//Global variable June
var moveJun = 1;

function clickMonthJun() {
	//Referencing President Trump's removal of protesters from St. John's church in D.C.
    if (keyCode === 54) {
        clearBkrd();
        frameRate(30);
        drawChurch();
	    drawPres();
	    drawProtest();
	    fightBack();
        backButton();  
    } 
}

	function drawChurch() {
		push();
		imageMode(CENTER);
		image(imgJun1, width/2, height/2, 500, 400);
		textSize(20);
		fill('black');
		text("Click and hold mouse to fight back!", 10, 25);
		pop();
	}

	function drawPres() {
		push();
		var junX1 = width - 50;
		var conX1 = constrain(junX1 - moveJun, 230, width + 60);
		imageMode(CENTER);
		image(imgJun2, conX1 , height-50, 120, 130);
		pop();
	}

	function drawProtest() {
		push();
		var junX2 = 80;
		var conX2 = constrain(junX2 - moveJun, -100, 230);
		imageMode(CENTER);
		image(imgJun3, conX2, height-50, 200, 150);
		pop();
	}

	function fightBack() {
		push();
		moveJun ++;
		print(moveJun);

		if (mouseIsPressed) {
			moveJun -= 2;
		}

		moveJun = constrain(moveJun, -150, 230);
		pop();
	}

//Diana's Code

var julXPoints = [];
var julYPoints = [];
var julClr = [];

function clickMonthJul() {
//Remembering John Lewis
    if (keyCode === 55) {
    	clearBkrd();
    	frameRate(60);
        imgJul.resize(width, height);
        imgJul.loadPixels();
        var x = random(width); //randomly draw pixels for a portrait of John Lewis
	    var y = random(height);
	    var clr = imgJul.get(x, y);
    	stroke(clr);
		strokeWeight(5);
	   	noFill();
	   	point(x, y); 
	   	julXPoints.push(x); //push the coordinates into arrays so it doesn't look like the background keeps drawing over it
	   	julYPoints.push(y);
	   	julClr.push(clr);
	   	for (var i = 0; i < julXPoints.length; i++) {
	   		stroke(julClr[i]);
	   		point(julXPoints[i], julYPoints[i]);
	   	}
        backButton(); 
    }
      
}

function clickMonthAug() {
//SpaceX Launch
	strokeWeight(1);
	stroke(0);
    if (keyCode === 56) {
        clearBkrd();
        background(0);
        frameRate(30);
		for (var i = 0; i < 3; i++) {
			for(var j = 0; j < 4; j++){
				star(i*200 + 25, j*100);
			}	
		}

		for (var a = 0; a < 2; a++) {
			for (var b = 0; b < 4; b++) {
				star(a*200 + 125, b*100 + 50);
			}
		}
		spaceship(200, 150);
		backButton(); 
	    }
}
    //August Helper Functions
	function spaceship(x, y) {
		push();
		translate(x, y);
		rotate(radians(30));
		fill(255);
		ellipse(25, 0, 50, 100); //spaceship body
		rect(0, 0, 50, 150);
		stroke(255, 0, 0);
		strokeWeight(3);
		push();
		rotate(radians(-90));
		text("SpaceX", -120, 25);
		pop();
		stroke(0);
		strokeWeight(1);
		triangle(0, 75, 0, 150, -35, 150); //wings
		triangle(50, 75, 50, 150, 85, 150);
		push();
		translate(-35, 150);
		for (var i = 0; i < 3; i++) { //draw flames
			fill(255, 175, 0);
			triangle(i*40, 0, (i+1)*40, 0, (i*40 + random(15, 25)), random(95, 105));
		}
		pop();
		pop();
	}

	function star(x, y) {
		var sx = [0, 5.5, 16.5, 9.5, 10.5, 0, -10.5, -9.5, -16.5, -5.5];
		var sy = [0, 9.5, 12.5, 21, 32, 27.5, 32, 21, 12.5, 10.5];
		push();
		translate(x, y);
		fill(255, 255, 0);
	    var nPoints = sx.length;
	    beginShape();
	    for (var i = 0; i < nPoints; i++) {
	    	vertex(sx[i] + random(-1, 1), sy[i] + random(-1, 1));
	    }
	    endShape(CLOSE);
	    pop();
	}

//Global Variables for September
var trees = [];
var smoke = [];
var mountain = [];
var fire = [];
var noiseParam = 0; //controls mountain landscape
var noiseStep = 0.01;
var fNoiseParam = 0; //controls fire
var fNoiseStep = 0.05;

function clickMonthSep() {
//West Coast Wildfires
    if (keyCode === 57) {
        clearBkrd();
        text("Sep TEST", width/2, height/2);
        backButton();
        frameRate(10);
        background(100); //dark grey

	    updateAndDisplaySmoke();
	    removeSmokeThatHasSlippedOutOfView();
	    addNewSmokeWithSomeRandomProbability();

	    mountains();
	    makeFire();
	    fill(75);
	    rect(0, 335, width, 65); //ground

	    updateAndDisplayTrees();
	    removeTreesThatHaveSlippedOutOfView();
	    addNewTreesWithSomeRandomProbability();   
	}
}

//September Helper Functions
	function updateAndDisplayTrees(){
	    // Update the trees' positions
	    for (var i = 0; i < trees.length; i++){
	        trees[i].move();
	        trees[i].display();
	    }
	}


	function removeTreesThatHaveSlippedOutOfView(){
	    //remove these trees from the array
	    var treesToKeep = [];
	    for (var i = 0; i < trees.length; i++){
	        if (trees[i].x + trees[i].breadth > 0) {
	            treesToKeep.push(trees[i]);
	        }
	    }
	    trees = treesToKeep;
	}


	function addNewTreesWithSomeRandomProbability() {
	    // Add a new tree to the end of the array
	    var newTreeLikelihood = 0.05; 
	    if (random(0,1) < newTreeLikelihood) {
	        trees.push(makeTree(width));
	    }
	}

	function treeMove() {
	    this.x += this.speed;
	}
	    
	function treeDisplay() {
	    //draw the tree
	    var tHeight = 90; 
	    strokeWeight(5);
	    stroke(0); 
	    push();
	    translate(this.x, height - 40);
	    line(0, -tHeight, 0, 0);
	    line(0, -40, -22, -75);
	    line(0, -40, 22, -75);
	    line(0, -50, -15, -85);
	    line(0, -50, 15, -85);
	    line(0, -30, -30, -65);
	    line(0, -30, 30, -65);
	    stroke(200); 
	    pop();
	}


	function makeTree(birthLocationX) {
	    var tr = {x: birthLocationX,
	                breadth: 50,
	                speed: -3.5,
	                move: treeMove,
	                display: treeDisplay}
	    return tr;
	}

	//Smoke Clouds

	function updateAndDisplaySmoke(){
	    // Update the smoke positions
	    for (var i = 0; i < smoke.length; i++){
	        smoke[i].move();
	        smoke[i].display();
	    }
	}


	function removeSmokeThatHasSlippedOutOfView(){
	    // remove clouds that are no longer visible
	    var smokeToKeep = [];
	    for (var i = 0; i < smoke.length; i++){
	        if (smoke[i].x + smoke[i].breadth > 0) {
	            smokeToKeep.push(smoke[i]);
	        }
	    }
	    smoke = smokeToKeep;
	}


	function addNewSmokeWithSomeRandomProbability() {
	    // Add smoke clouds to the end of the arrayS
	    var newSmokeLikelihood = 0.02; 
	    if (random(0,1) < newSmokeLikelihood) {
	        smoke.push(makeSmoke(width));
	    }
	}

	function smokeMove() {
	    this.x += this.speed;
	}
	    

	// draw smoke
	function smokeDisplay() { 
	    fill(50); 
	    noStroke(); 
	    push();
	    translate(this.x, this.y);
	    ellipse(0, this.y, 90, 15);
	    ellipse(0, this.y+10, 100, 15);
	    ellipse(0, this.y-10, 80, 15);
	    pop();
	}


	function makeSmoke(birthLocationX) {
	    var smk = {x: birthLocationX,
	    	        y: random(0, height/2),
	                breadth: 50,
	                speed: -3.,
	                move: smokeMove,
	                display: smokeDisplay}
	    return smk;
	}


	function mountains() {
	    //use random noise to draw mountains
	    mountain.shift();
	    var n = noise(noiseParam);
	    var value = map(n, 0, 1, 0, height);
	    mountain.push(value);
	    noiseParam += noiseStep;
	    
	    
	    fill(0); //black - mountain shadows
	    beginShape();
	    vertex(0, height);
	    for (var i = 0; i <= 100; i++) {
	        vertex(i*5, mountain[i]);
	    }
	    vertex(width, height);
	    endShape(); 
	}

	function makeFire() {
	    //use random noise to draw mountains
	    fire.shift();
	    var n = noise(fNoiseParam);
	    var value = map(n, 0, 1, 0, height);
	    fire.push(value);
	    fNoiseParam += fNoiseStep;
	    
	    
	    fill(255, 0, 0); //red layer
	    beginShape();
	    vertex(0, height);
	    for (var i = 0; i <= 100; i++) {
	        vertex(i*5, fire[i]);
	    }
	    vertex(width, height);
	    endShape(); 

	    fill(255, 175, 0); //orange layer
	    beginShape();
	    vertex(0, height);
	    for (var j = 0; j <= 100; j++) {
	    	vertex(j*5, fire[j] + 50);
	    }
	    vertex(width, height);
	    endShape();

	    fill(255, 255, 0); //yellow layer
	    beginShape();
	    vertex(0, height);
	    for (var p = 0; p <= 100; p++) {
	    	vertex(p*5, fire[p] + 100);
	    }
	    vertex(width, height);
	    endShape();
     
}

//October Global Variables
var hurricane = [];
var xMove = [];
var imgOct;

function clickMonthOct() {
	//Busiest hurricane season on record
    if (keyCode === 48) {
        clearBkrd();
        frameRate(15);
        translate(width, 0);
	    image(imgOct, -width-50, -107, 650, 560);
		updateAndDisplayHurricane(); 
		removeHurricanesThatHaveSlippedOutOfView();
		addNewHurricanesWithSomeRandomProbability();
        backButton();
    }
}

	//October Helper Functions
		function updateAndDisplayHurricane(){
	    // Update the hurricanes' positions
	    for (var i = 0; i < hurricane.length; i++){
	        hurricane[i].move();
	        hurricane[i].display();
	    }
	}

	function removeHurricanesThatHaveSlippedOutOfView(){
	    //remove these hurricanes from the array
	    var hurricanesToKeep = [];
	    for (var i = 0; i < hurricane.length; i++){
	        if (hurricane[i].x > -550 || hurricane[i].y > -50) {
	            hurricanesToKeep.push(hurricane[i]);
	        }
	    }
	    hurricane = hurricanesToKeep;
	}

	function addNewHurricanesWithSomeRandomProbability() {
	    // Add a new hurricane to the end of the array
	    var newHurricaneLikelihood = 0.025;
	    var newHY = random(height/3, height);
	    this.xMove = random(10);
	    this.yMove = random(10);
	    if (random(0,1) < newHurricaneLikelihood) {
	        hurricane.push(makeHurricane(newHY));
	    }
	}

	function hurricaneMove() {
		this.x -= this.hxMove;
		this.y -= this.hyMove;
		this.spin += 10;
	}

	function hurricaneDisplay() {
		push();
		translate(this.x, this.y);
		rotate(radians(this.spin));
	    noStroke();
	    fill(255, 0, 0);
	    ellipse(0, 0, 30, 30);
	    fill(230);
	    ellipse(0, 0, 10, 10);
		push();
		scale(0.7);
		translate(-40, 5);
		stroke(255, 0, 0);
		strokeWeight(5);
		noFill();
		beginShape();
		for (var i = 2; i <= 4; i += 0.1) {
			var y1 = Math.pow(2.6, i);
	    	vertex(i*25, -y1);
		}
		endShape();
		pop();
	    
	    push();
	    scale(0.7);
	    stroke(255, 0, 0);
		strokeWeight(5);
		noFill();
	    translate(40, -5);
	    rotate(radians(180));
		beginShape();
		for (var i = 2; i <= 4; i += 0.1) {
			var y1 = Math.pow(2.6, i);
	    	vertex(i*25, -y1);
		}
		endShape();
		pop();
		pop();
	}

	function makeHurricane(birthLocationY) {
		var h = {x: 0, y: birthLocationY, hxMove: xMove, hyMove: 5, move: hurricaneMove, spin: 0, display: hurricaneDisplay}
	    return h;
	}

//November Global Variables
var theta = 0;
var txp = 0;
var typ = 0;
var thetavp = 0;
var txvp = 0;
var tyvp = 0;
//counters
var pCount = 0;
var vpCount = 0;

function clickMonthNov() {
//2020 US Presidential Election
    strokeWeight(1);
	stroke(0);
	textSize(14);

    if (keyCode === 189) {
        clearBkrd();
        frameRate(15);
        backButton();
        image(imgNov, -150, -60, 800, 650);
        stroke(255);
		president(150, 200);
		vicePresident(350, 200);
		fill(255);
		text("Who will be the first to 270?", 150, 20);
		text("Click the mouse on the left to give Alec Baldwin electoral votes", 75, 45)
		text("Click the mouse on the right to give Jim Carrey electoral votes", 75, 70);
		text(pCount, 150, 120);
		text(vpCount, 350, 120);
		debate();
	}

    	if (pCount >= 270) {
			background(255, 0,0);
			textSize(30);
			stroke(0);
			fill(0);
			text("I did it! It was RIGGED but I won!", 20, height/2 - 15);
			text("Very good for our Great Country", 25, height/2 + 15);
		}

		if (vpCount >= 270) {
			background(0, 0, 255);
			textSize(50);
			stroke(255);
			fill(255);
			text("Will you shut up man!", 5, height/2);
		}
	
}
    //November Helper Functions    
	function debate(){
		if (mouseIsPressed) {
			if (mouseX < width/2) { //move president
				theta = 15;
				txp = 150;
				typ = -100
				pCount = pCount + 5;				
			}

			if (mouseX >= width/2) { //move vice president
				thetavp = -15;
				txvp = -150;
				tyvp = 0;
				vpCount = vpCount + 5;
			}
		}
	} 

	function mouseReleased() {
		if (theta === 15) { //reset president
			theta = 0;
			txp = 0;
			typ = 0;					
		}

		if (thetavp === -15) { //reset vice president
			thetavp = 0;
			txvp = 0;
			tyvp = 0;				
		}
	}

	function president(x, y) {
		push();
		rotate(radians(theta));
		translate(x + txp, y + typ);
		noStroke();
		fill(255, 175, 0);
		push();
		rotate(radians(75)); //mouth
		ellipse(17, -12, 4, 15);
		rotate(radians(30));
		ellipse(15, -17, 4, 15);
		pop();
		fill(255, 175, 0); //head
		ellipse(0, 0, 40, 50);
		fill(255, 255, 0); //hair
		ellipse(3.5, -20, 45, 15);
		fill(255); //eyes
		ellipse(10, -2, 8, 8);
		fill(0);
		ellipse(10, -2, 4, 4);
		stroke(0);
		line(25, 17, 40, 17);
		line(25, 9, 40, 1);
		line(25, 25, 40, 33);
		noStroke();

		//suit
		fill(255); //shirt
		rect(-15, 23, 32, 50);
		fill(0, 0, 255); //suit jacket
		rect(-15, 23, 25, 50);
		fill(255, 0, 0); //tie
		rect(14, 23, 3, 30);
		fill(0); //shoes
		ellipse(3, 133, 35, 15);
		fill(0, 0, 255); //pants
		rect(-15, 73, 27, 60);
		push(); //arm
		rotate(radians(-40));
		fill(255, 175, 0);
		ellipse(15, 40, 15, 10);
		fill(0, 0, 255);
		rect(-35, 35, 50, 10);
		pop();
		pop();
	}

	function vicePresident(x, y) {
		push();
		rotate(radians(thetavp));
		translate(x + txvp, y + tyvp);
		noStroke();
		fill(250, 237, 203); //head
		ellipse(-2, 0, 40, 50);
		fill(255); //hair
		ellipse(0, -22, 35, 8);
		fill(255); //eyes
		ellipse(-10, -4, 8, 8);
		fill(0);
		ellipse(-10, -4, 4, 4);
		fill(255, 0, 0); //mouth
		ellipse(-12, 13, 8, 8);
		stroke(0);
		line(-25, 13, -40, 13);
		line(-25, 8, -40, 0);
		line(-25, 18, -40, 26);
		noStroke();

		//suit
		fill(255); //shirt
		rect(-15, 23, 25, 50);
		fill(0, 0, 255); //suit jacket
		rect(-8, 23, 18, 50);
		fill(255, 0, 0); //tie
		rect(-15, 23, 3, 30);
		fill(0); //shoes
		ellipse(-7, 133, 35, 15);
		fill(0, 0, 255); //pants
		rect(-15, 73, 25, 60);
		push(); //arm
		rotate(radians(40));
		fill(250, 237, 203);
		ellipse(-18, 45, 10, 10);
		fill(0, 0, 255);
		rect(-18, 40, 50, 10);
		pop();
		pop()
		}

//December global variables - firework coordinate arrays     
var xpos = 0;
var xcoord = [35, 25, 55, 200, 240, 400, 470, 440, 455, 230, 280, 415, 100, 280];
var ycoord = [25, 100, 350, 120, 150, 75, 45, 175, 300, 320, 365, 340, 215, 50];

function clickMonthDec() {
	//abstract clock to wait for the end of 2020
    if (keyCode === 187) {
        clearBkrd();
        backButton();
        frameRate(5);
    	background(0);
	    var sec = second();
	    var min = minute();
	    var hr = hour();
	    var d = day();
	    background(0);

	    //draw fireworks in the background
	    for (var i = 0; i < 14; i++) {
	        firework(xcoord[i], ycoord[i]);
	    }

	    push();
	    scale(0.5);
	    president(16*d, 40); //moves with day
	    pop();
	    decVirus(20*hr, 150); //hour
	    image(aprImg3, 8*min, 200, 80, 80); //minute
	    decHurricane(8*sec, 350); //second

	}
}

	//December helper functions
	function firework(x, y) { 
	    var r = random(255);
	    var g = random(255);
	    var b = random(255);
	    push();
	    translate(x, y);
	    stroke(r, g, b);
	    for (var i = 0; i < 12; i++) { //draw lines
	        push();
	        rotate(radians(i*30));
	        line(xpos, 0, xpos + 15, 0);
	        pop();
	    }

	    if (xpos <= 25) { //grow
	    xpos += 1;
	    }

	    else if (xpos > 25) { //reset
	        xpos = 0;
	    }
	    pop();
	}

	function decVirus(x, y) { //design taken from Shaun's virus object - I did not code
	        stroke('black');//body of virus
	        strokeWeight(2);
	        fill('red');
	        push();
	        translate(x, y);
	        circle(0, 0, 35);
	        strokeWeight(3);//stems of virus
	        var angle = 45;
	        for (let i = 0; i < 8; i++) {
	            rotate(radians(angle));
	            beginShape();
	            vertex(35/2 - 10, 0)
	            vertex(random(35/2 + 4, 35/2 + 8), random(-2, 2));
	            endShape(CLOSE);
	            ellipse(random(35/2 + 8, 35/2 + 6), random(1, 3), 11, 9);
	        }
	        pop();
	}

    function decHurricane(x, y) { //from October 
        push();
        translate(x, y);
        noStroke();
        fill(255, 0, 0);
        ellipse(0, 0, 30, 30);
        fill(230);
        ellipse(0, 0, 10, 10);

        //hurricane lines
        push(); 
        scale(0.7);
        translate(-40, 5);
        stroke(255, 0, 0);
        strokeWeight(5);
        noFill();
        beginShape();
        for (var i = 2; i <= 4; i += 0.1) {
            var y1 = Math.pow(2.6, i);
            vertex(i*25, -y1);
        }
        endShape();
        pop();
        push();
        scale(0.7);
        stroke(255, 0, 0);
        strokeWeight(5);
        noFill();
        translate(40, -5);
        rotate(radians(180));
        beginShape();
        for (var i = 2; i <= 4; i += 0.1) {
            var y1 = Math.pow(2.6, i);
            vertex(i*25, -y1);
        }
        endShape();
        pop();
        pop();
    }
      

Press any key in the row from “1” to “=” to select a month

Press “esc” to return to the main calendar and select another month

Shaun and I made this interactive monthly calendar recap of 2020 based on the memes from the beginning of the year that something big and strange was happening every month. It was not that hard to come up with events. I picked the events that I did partly based on what I had programming ideas for and partly in order to include some variety and show how many different things happened this year. We have many different types of events, from satire to more serious ones that we wanted to commemorate.
To use the program, press a key in line from “1” down to “=” to display a different month (“-” corresponds to November and “=” is December). Press “esc” to leave the month and return to the main calendar, or you can move between the months themselves. The counters in the March and November functions will reset if you leave the month by hitting “esc” so you can go back and run the simulation again, but they will not reset if you leave the month and return to it from another month (without hitting “esc” in between). I never have July reset because the portrait takes awhile to draw, so I didn’t think it needed to start over every time the month is replayed.
If I had more time, I would have liked to do more with the August function to make it interactive in some way, but I didn’t want to just link the spaceship to mouseX and mouseY, so I left it as is for now. Maybe eventually I could make it so that you can steer the spaceship through space or something.

Final Project – Maze

    For my project, I created a maze with a turtle guiding the path to get out of the maze. My goal was to make this environmentally themed because this is still a persistent issue. The wonderful thing about where technology is headed, however, we can do a lot more to solve some of these issues. For example, electric automobiles replacing gas ones. Another motivator was to continue to bring self awareness. It’s crazy to think that people were freaking out in the 2020 debates/election over the fear that Biden would “force” everyone to get an electric car. Of course I see the issue in getting rid of gas cars all of the sudden, but 1) he isn’t going to do it “all of the sudden” and 2) electric cars should replace gas cars completely, eventually. 

Anyway, the difference between this and most standard mazes is that there is always one clear path. However, my maze doesn’t have any clear paths. It does have one distinct path, but it is blocked by obstacles. There are six obstacles that are each a factor of environmental issues. In order to get rid of them, and clear the path for the turtle, you have to click on them once the turtle approaches each obstacle. Once you click on one, a fact will appear at the bottom of the page relating to environmental issues. Once you make it to the end, you are done and there will be an ending page, with a smiling earth. The idea of this project is to continue to bring awareness to the climate crisis/environmental issues and the player gets to “clean up” the messes or “get rid” of the issues along the way.

Some side notes: movement is with the wasd keys, instead of the arrow keys. So, “w” is up, “a” is left, “s” is down, and “d” is right. Also, sometimes the turtle may get stuck, just play around with the movement keys if this happens. I apologize for this, but I couldn’t figure out how to fix it. Of course if I had more time, I would’ve liked to figure out this problem, Overall, it works pretty well, so enjoy!

sketch.slmazeDownload
//Sarah Luongo
//sluongo
//Section A

// This code aims to create a maze with obstacles that are causes of
// environmental problems. As you go through, click on the obstacles to
// clear the path for the turtle and learn some facts along the way.

var walls = [];
var x = 120; // x location of circle
var y = 25; // y location of circle
var obstaclesx = []; // array to hold the x location of the obstacles
var obstaclesy = []; // array to hold the y location of the obstacles
var industry;
var litter;
var light;
var tree;
var car;
var rings;
var obstaclesarealive = [];
var facts = '';
var earth;
var facing = 0;
var turtlecol; // boolean for collision as turtle rotates

function preload() {
    industry = loadImage('https://i.imgur.com/kT2IbbF.png');
    litter = loadImage('https://i.imgur.com/iQ2mdUY.png');
    light = loadImage('https://i.imgur.com/uMRxZlH.png');
    tree = loadImage('https://i.imgur.com/vn4OlLX.png');
    car = loadImage('https://i.imgur.com/i4iop8I.png');
    rings = loadImage('https://i.imgur.com/BAAbVNY.png');
    earth = loadImage('https://i.imgur.com/RfrmGyt.png');
}

function setup() {
    createCanvas(600, 600);
    frameRate(60);
    // Maze lines are are drawn somewhat like a grid, so they are separated by
    // Row and column and seperated further to make up to rows and columns

    // Maze lines (columns) starting from left to right
    maze(140, 50, 140, 90, true);    
    maze(140, 130, 140, 210, true);
    maze(140, 250, 140, 330, true);
    maze(140, 370, 140, 410, true);

    maze(180, 50, 180, 130, true);
    maze(180, 170, 180, 250, true);
    maze(180, 370, 180, 410, true);

    maze(220, 170, 220, 210, true);
    maze(220, 250, 220, 330, true);

    maze(260, 90, 260, 170, true);
    maze(260, 210, 260, 250, true);
    maze(260, 290, 260, 330, true);
    maze(260, 410, 260, 450, true); 

    maze(300, 90, 300, 130, true);
    maze(300, 250, 300, 330, true);
    maze(300, 370, 300, 410, true);

    maze(340, 90, 340, 170, true);
    maze(340, 330, 340, 370, true);

    maze(380, 50, 380, 250, true);

    maze(420, 90, 420, 130, true);
    maze(420, 170, 420, 250, true);
    maze(420, 290, 420, 410, true);

    maze(460, 90, 460, 290, true);
    maze(460, 330, 460, 370, true);

    // Maze lines (rows) starting from top to bottom
    maze(220, 90, 260, 90, false);
    maze(300, 90, 340, 90, false);
    maze(420, 90, 460, 90, false);

    maze(140, 130, 220, 130, false);
	
    maze(220, 170, 340, 170, false);
    maze(380, 170, 420, 170, false);

    maze(180, 210, 340, 210, false);

    maze(220, 250, 260, 250, false);
    maze(300, 250, 380, 250, false);
    
    maze(140, 290, 220, 290, false);
    maze(260, 290, 300, 290, false);
    maze(340, 290, 460, 290, false);

    maze(100, 330, 180, 330, false);
    maze(300, 330, 380, 330, false);
    maze(460, 330, 500, 330, false); 

    maze(140, 370, 300, 370, false);
    maze(340, 370, 380, 370, false);

    maze(180, 410, 260, 410, false);
    maze(300, 410, 460, 410, false);

    // Resize images
    industry.resize(35, 40);
    litter.resize(35, 35);
    light.resize(35, 35);
    tree.resize(30, 30);
    car.resize(35, 35);
    rings.resize(60, 60);
    earth.resize(300, 300);

    obstaclesx = [140, 260, 223, 385, 462, 440]
    obstaclesy = [210, 53, 333, 255, 150, 410]

    obstaclesarealive = [true, true, true, true, true, true]
}

function draw() {
    background(220);
    
    // Maze background
    strokeWeight(1);
    stroke(0);
    fill(255);
    square(100, 50, 400);

    for (var i = 0; i < walls.length; i++) {
        line(walls[i].x1, walls[i].y1, walls[i].x2, walls[i].y2);
    }

    // Maze start and finish
    stroke(255);
    strokeWeight(1);
    line(101, 50, 139, 50);
    line(461, 450, 499, 450);
    
    noStroke();
    turtle(x, y);

    if (obstaclesarealive[0] == true) {
        image(industry, 140, 210);
    }
    if (obstaclesarealive[1] == true) {  
        image(litter, 260, 53);
    }
    if (obstaclesarealive[2] == true) {  
        image(light, 223, 333);
    }
    if (obstaclesarealive[3] == true) {  
       image(tree, 385, 255);
    }
    if (obstaclesarealive[4] == true) {  
        image(car, 462, 150);
    }
    if (obstaclesarealive[5] == true) {  
        image(rings, 440, 410);
    }

    // If statements to move and rotate the turtle:
    // Key 'w' moves up
    if (keyIsDown(87)) {
	facing = 180;
	turtlecol = false;
	y--;
	if (collision()) {
	    y++;
	}
    // Key 'a' moves left
    } else if (keyIsDown(65)) {
	facing = 90;
	turtlecol = true;
	x--;
	if (collision()) {
	    x++;
	}
    // Key 's' moves down
    } else if (keyIsDown(83)) {
	facing = 0;
	turtlecol = false;
	y++;
	if (collision()) {
	    y--;
	}
    // Key 'd' moves right
    } else if (keyIsDown(68)) {
	facing = -90;
	turtlecol = true;
	x++;
	if (collision()) {
	    x--;
	}
    }
    
    // Text attributes and placement after each obstacle is clicked
    textSize(15);
    fill(0);                         
    text(facts, 100, 500);
}

function turtle(a, b) {
    push();
    translate(a, b);
    // Rotate based on direction it's traveling
    rotate(radians(facing));

    // Head
    fill(153, 200, 130);
    ellipse(0, 9, 7, 8);

    // Tail
    strokeWeight(3);
    stroke(153, 200, 130);
    line(0, -10, 0, -8); 

    // Legs
    strokeWeight(4);
    line(-7, -8, -6, -7);
    line(7, 8, 6, 7);
    line(-7, 8, -6, 7);
    line(7, -8, 6, -7);

    noStroke();

    // Eyes
    fill(88, 130, 96);
    circle(-2, 11, 2); 
    circle(2, 11, 2);

    // Body
    fill(204, 223, 156);
    circle(0, 0, 16);
    pop();
}

// Maze object 
function maze(xone, yone, xtwo, ytwo, pos) {
    var mz = {x1: xone, y1: yone, x2: xtwo, y2: ytwo, p: pos}
    walls.push(mz);
}

// Function that deals with all collision types
function collision() {
    var xoffset = (turtlecol)? 12 : 13;
    var yoffset = (turtlecol)? 13 : 12;

    // Collision against maze border
    if (x == 111 || x == 489 || y == 65 || y == 430) {
        if (x >= 112 & x <= 128 && y <= 65) {
	    return false;
	}
	// End of maze
	if (x >= 450 & x <= 488 && y == 430) {
            endscreen();
        }
	return true;
    }
    
    // Collision against maze walls
    for (var i = 0; i < walls.length; i++) {
        if (walls[i].p == true) {
            if ((y+yoffset) > walls[i].y1 & (y-yoffset) <= walls[i].y2) {
	        if ((x+xoffset) >= walls[i].x1 && (x-xoffset) <= walls[i].x1) {
		    return true;
		}
	    }
	} else {
            if ((x+xoffset) >= walls[i].x1 & (x-xoffset) <= walls[i].x2) {
	        if ((y+yoffset) >= walls[i].y1 && (y-yoffset) <= walls[i].y1) {
		    return true;
		}
	    }
	}
    }
    return obstacleCollision();
}

// Collision against images
function obstacleCollision() {
    var xoffset = (turtlecol)? 12 : 13;
    var yoffset = (turtlecol)? 13: 12;

    for (var i = 0; i < obstaclesx.length; i++) {
        if ((x+xoffset) >= obstaclesx[i] & (x-xoffset) <= (obstaclesx[i] + 40)) {
	    if ((y+yoffset) >= obstaclesy[i] && (y-yoffset) <= (obstaclesy[i] + 40)) {
	        return obstaclesarealive[i];
	    }
	}
    }
    return false;
}

// Facts from the industry, electricity, and transportation obstacles come from
// the following website:
// https://www.epa.gov/ghgemissions/sources-greenhouse-gas-emissions
// Litter obstacle fact:
// https://www.metrobinhire.com.au/blog/9-surprisingly-and-alarming-facts-about-littering
// Deforestation obstacle fact:
// https://www.greenmatters.com/p/why-is-deforestation-a-problem
// 6 Pack Ring obstacle fact:
// https://www.nationalgeographic.com/environment/2018/09/news-plastic-six-pack-rings-alternatives-history/#close
function mousePressed() {
    if (mouseX >= 140 & mouseX <= 175 && mouseY >= 210 && mouseY <= 250) {
        obstaclesarealive[0] = false;
	facts = 'Greenhouse gas emissions from industry primarily come \nfrom burning fossil fuels for energy, as well as greenhouse \ngas emissions from certain chemical reactions necessary to \nproduce goods from raw materials.';
    }
    if (mouseX >= 260 & mouseX <= 295 && mouseY >= 53 && mouseY <= 88) {
	obstaclesarealive[1] = false;
	facts = 'Some alarming quick facts about littering: almost all litter \nends up in the ocean. The most littered item is fast food \npackaging many animals die from littering. Cigarette butts \nmake up 1/2 the amount of littered objects.';
	    
    }
    if (mouseX >= 223 & mouseX <= 258 && mouseY >= 333 && mouseY <= 368) {
        obstaclesarealive[2] = false;
	facts = 'Electricity production generates the second largest share \n(26.9% in 2018) greenhouse gas emissions. Approximately \n63 percent of our electricity comes from burning fossil fuels, \nmostly coal and natural gas.';
    }
    if (mouseX >= 385 & mouseX <= 415 && mouseY >= 255 && mouseY <= 285) {
        obstaclesarealive[3] = false;
	facts = 'Deforestation has many major (and way too often unforeseen) \nimpacts on the environment. There’s soil erosion, water cycle \ndisruption, greenhouse gas emissions, and biodiversity \nlosses with every tree that is chopped, and the planet feels its \nimpact.';
    }
    if (mouseX >= 462 & mouseX <= 499 && mouseY >= 150 && mouseY <= 185) {
        obstaclesarealive[4] = false;
	facts = 'The transportation sector generates the largest share (28.2%\nin 2018) of greenhouse gas emissions. Greenhouse gas \nemissions from transportation primarily come from burning \nfossil fuel for our cars, trucks, ships, trains, and planes.';
    }
    if (mouseX >= 440 & mouseX <= 500 && mouseY >= 410 && mouseY <= 440) {
        obstaclesarealive[5] = false;
	facts = 'Almost 700 species are now known to have been harmed \nby ocean plastic, and every year, around 18 billion pounds \nof plastic flows into the ocean. Producing plastic rings also \nrequires using petroleum—around eight percent of global \noil production is to make plastic.';
    }
}

function endscreen() {
    facts = '';
    fill(0, 0, 102);
    push();
    translate(width/2, height/2);
    square(-300, -300, 600);
    image(earth, -150, -200);
    textSize(50);
    fill(255);
    textAlign(CENTER);
    text('THE END', 0, 200);
    pop();
    noLoop();
}

// Code used to make the building/first obstacle
/*function industry() {
     // Building
     fill(139, 69, 19);
     rect(145, 225, 8, 20);
     rect(153, 234, 20, 11);

     //CO2
      fill(70);
      circle(149, 222, 5);
      circle(153, 220, 8);
      circle(159, 214, 11);
}*/

Project 15: Final Project

finalYeung2020Download
//stores all the changes
var changes={
    activism: false, //political poster on the wall, b
    cramps: false, //typing sound, c
    battery: false, //low battery, d
    voted: false, //i voted sticker on wall, e
    text: false, //text notif from friend to hangout, f
    delivery: false, //notif that grubhub is here, g
    canvasNotifs: false, //notif that new assignment was posted, h
    mask: false, //mask on wall, i
    handshake: false, //handshake homepage, j
    rust: false, //keys turn brown, k
    night: false, //outside window is night now, l
    maskBox: false, //box of masks appear on desk, m
    dino: false, //dino game, n
    zeroPercent: false, //canvas grade page with a 0, o
    parents: false, //knocking sound, p
    askText: false, //text notif to ask if you're okay, q
    grenell: false, //grenell petition, r
    netflix: false, //netflix home page, s
    tikTok: false, //tik tok home page, t
    unmuted: false, //eating sound, u
    chegg: false, //chegg home page, w
    pills: false, //pill bottle on desk, x
    muted: false, //zoom page, muted y
    zoomFatigue: false, //yawn sound, z
}

//triggers for sound
var fr1=0;
var fr2=0;
var fr3=0;
var fr4=0;

//triggers congrats
var fr5=0

//arrays to store letters and corresponding messages
var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
var letterMessage = [
    "An optimistic start: you're kind of excited that spring break got extended by a week!\nyou'll be back on campus in no time", //no change
    "Black Lives Matter: you do whatever you can to help the cause",
    "Cramps: you've typed so much in the past few months that your fingers start cramping", //typing sound
    "Dying: crap, your battery is low",
    "Election: you sent in your mail-in ballot",
    "Friends: your friend asks you to hangout but you feel too guilty to do anything",
    "Grubhub: I don't feel like making food so I'll just waste $20 on a $10 meal",
    "Homework: homework assignments just seem to pile up, but you're so unmotivated",
    "I forgot a mask: you walked to the store but forgot your mask, so you had to come back",
    "Job Applications: you know you have to applying for internships,\nbut you just don't have the effort to",
    "Keys: you haven't gone outside in so long, your keys are rusting",
    "Long Hours: time seems nonexistent when you work from home",
    "Masks: your mom buys you a giant box of masks", 
    "No Internet: oh no! Your internet went out, time to play the dino game :(",
    "Oops, I forgot: without your friends to remind you,\nyou accidentally forget to do your homework",
    "Parents: even though you're in lecture,\nyour parents don't understand and still try to talk to you", //knocking sound
    "Questions: it seems like every two seconds someone's asking if you're okay",
    "Richard Grenell: you sign the petition to fire him,\neven though you're not sure if anything will happen",
    "Streaming: you feel like you've watched everything on Netflix in the past few months",
    "Tik Tok: you spend your time endlessly scrolling",
    "Unmuted: you forgot to mute yourself so your entire class heard you eat your lunch!", //eating sound
    "Vaccine: you're just hoping there's a vaccine in time for summer", //no change
    "Work: has homework always been this hard?",
    "Xanax: you start having panic attacks and your doctor prescribes you Xanax",
    "You're Muted: you try to answer a question in class but forget you're muted,\nso you just look stupid",
    "Zoom Fatigue: after hours on Zoom for lectures, you feel exhausted", //yawn sound
]

//images that need to be loaded
var blm;
var boxOfMasks;
var canvasNotification;
var cheggHomePage;
var dinoGame;
var grenellPetition;
var grubhubText;
var handshakeHomePage;
var hangOutText;
var iVotedSticker;
var lowBatteryNotif;
var netflixHomePage;
var questionText;
var tikTokHomePage;
var zeroPercentGrade;

//sounds that need to be loaded
var eating;
var knockKnock;
var tired;
var type;

function preload(){
    //loads images
    blm=loadImage("https://i.imgur.com/JFLSHwn.jpg");
    boxOfMasks=loadImage("https://i.imgur.com/XEQ2DIE.png");
    canvasNotification=loadImage("https://i.imgur.com/iI0fpJP.png");
    cheggHomePage=loadImage("https://i.imgur.com/hdPz4NX.png");
    dinoGame=loadImage("https://i.imgur.com/tvKCVyP.png");
    grenellPetition=loadImage("https://i.imgur.com/i7QTQyK.png");
    grubhubText=loadImage("https://i.imgur.com/YROzHtr.png");
    handshakeHomePage=loadImage("https://i.imgur.com/K36qX37.png");
    hangOutText=loadImage("https://i.imgur.com/Nqt81BJ.png");
    iVotedSticker=loadImage("https://i.imgur.com/SfQn4pk.png");
    lowBatteryNotif=loadImage("https://i.imgur.com/cC8hsTT.png");
    netflixHomePage=loadImage("https://i.imgur.com/N9BohE8.jpg");
    questionText=loadImage("https://i.imgur.com/rQHSMwT.png");
    tikTokHomePage=loadImage("https://i.imgur.com/DlDOeHF.png");
    zeroPercentGrade=loadImage("https://i.imgur.com/exTf7NY.png");
    zoomMeeting=loadImage("https://i.imgur.com/RcF2XKO.jpg");
    xanaxBottle=loadImage("https://i.imgur.com/EcRn3JI.png");
    maskMessage=loadImage("https://i.imgur.com/qR7W3rv.png");

    //loads sounds
    eating=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/crunch.wav");
    knockKnock=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/knock.wav");
    tired=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/yawn.wav");
    type=loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/typing.wav");
}
//setup functions
function setup() {
    createCanvas(600, 550);
    useSound();
    frameRate(1);
}

function soundSetup(){
    eating.setVolume(0.5);
    knockKnock.setVolume(0.5);
    tired.setVolume(0.5);
    type.setVolume(0.5);
}

function draw() {
    covid(); //changes the booleans
    drawRoom(); //draws the room

    typeAlphabet(); //types the alphabet and messages
    typeMessages();

    ifStatements(); //adds all the if statements to make the images and sounds appear/play
}

function covid(){ //when a key is pressed, boolean changes
    if (key == 'b') {
        changes.activism =true;
    }
    if (key == 'c') {
        changes.cramps =true;
    }
    if (key == 'd') {
        changes.battery =true;
    }
    if (key == 'e') {
        changes.voted =true;
    }
    if (key == 'f') {
        changes.text =true;
    }
    if (key == 'g') {
        changes.delivery =true;
    }
    if (key == 'h') {
        changes.canvasNotifs =true;
    }
    if (key == 'i') {
        changes.mask =true;
    }
    if (key == 'j') {
        changes.handshake =true;
    }
    if (key == 'k') {
        changes.rust =true;
    }
    if (key == 'l') {
        changes.night =true;
    }
    if (key == 'm') {
        changes.maskBox =true;
    }
    if (key == 'n') {
        changes.dino =true;
    }
    if (key == 'o') {
        changes.zeroPercent =true;
    }
    if (key == 'p') {
        changes.parents =true;
    }
    if (key == 'q') {
        changes.askText =true;
    }
    if (key == 'r') {
        changes.grenell =true;
    }
    if (key == 's') {
        changes.netflix =true;
    }
    if (key == 't') {
        changes.tikTok =true;
    }
    if (key == 'u') {
        changes.unmuted =true;
    }
    if (key == 'w') {
        changes.chegg =true;
    }
    if (key == 'x') {
        changes.pills =true;
    }
    if (key == 'y') {
        changes.muted =true;
    }
    if (key == 'z') {
        changes.zoomFatigue =true;
    }
}

function drawRoom(){
    background(230, 234, 245);
    noStroke();
    fill(74, 40, 2);
    rect(0, 350, 600, 130);
    drawWindow();
    fill(77, 77, 77);
    rect(0, 200, 400, 280);
    fill(0);
    rect(0, 215, 385, 270);
    fill(220);
    rect(0, 425, 600, 175);
    drawKey();
    push();
    translate(150, 40);
    scale(0.15);
    drawClock();
    pop();

    //draws sign with instructions
    fill(255, 255, 204);
    rect(15, 15, 80, 70);

    fill(0, 0, 51);
    textAlign(CENTER);
    textSize(12);
    text("Press keys\nin ABC order\nto finish", 55, 35);

}

function drawWindow(){
    //changes background to show time elapsed
    if (changes.night==true){
        fill(0, 20, 37);
        rect(300, 40, 300, 250);
    }
    if (changes.night==false){
        fill(81, 174, 255);
        rect(300, 40, 300, 250);
    }

    //grass
    fill(0, 102, 0);
    rect(300, 220, 300, 70);

    //mountains
    stroke(135, 126, 138);
    strokeWeight(1);
    for (var x=300; x<width; x++){
        var l=x*0.01;
        var y=map(noise(l), 0, 1, 170, 220);
        line(x, y, x, 220);
    }

    //window pane
    noFill();
    stroke(255);
    strokeWeight(15);
    rect(300, 40, 350, 250);
    strokeWeight(10);
    line(300, 165, 600, 165);
    line(550, 40, 550, 290);
    noStroke();  
}

function drawKey(){
    //changes color of key
    if (changes.rust==false){
        fill(180); //grey
    }
    if (changes.rust==true){
        fill(204, 102, 0) //orange
    }

    //draws key
    push();
    scale(0.5);
    translate(1000, 800);
    rotate(radians(10));
    ellipse(0, 0, 20, 40);
    rect(0, -5, 60, 10);
    //draws key's spokes(?)
    var keyLengths=[15, 20, 13];
    for (var i=0; i<4; i++){
        rect(25+(i*10), 0, 6, keyLengths[i]);
    }
    pop();

}

function ifStatements(){ //inputs images and sounds for the key presses
    //images triggered
    if (changes.activism==true){
        image(blm, 45, 100, 70, 91);
    }
    if (changes.battery==true){
        image(lowBatteryNotif, 185, 215, 200, 52);
    }
    if (changes.voted==true){
        image(iVotedSticker, 225, 150, 50, 50);
    }
    if (changes.text==true){
        image(hangOutText, 185, 215, 200, 52);
    }
    if (changes.delivery==true){
        image(grubhubText, 185, 215, 200, 52);
    }
    if (changes.canvasNotifs==true){
        image(canvasNotification, 185, 215, 200, 52);
    }
    if (changes.mask==true){
        image(maskMessage, 185, 215, 200, 52);
    }
    if (changes.handshake==true){
        image(handshakeHomePage, 0, 215, 385, 211);
    }
    if (changes.maskBox==true){
        image(boxOfMasks, 500, 300, 150, 113);
    }
    if (changes.dino==true){
        image(dinoGame, 0, 215, 385, 211);
    }
    if (changes.zeroPercent==true){
        image(zeroPercentGrade, 0, 215, 385, 211);
    }
    if (changes.askText==true){
        image(questionText, 185, 215, 200, 52);
    }
    if (changes.grenell==true){
        image(grenellPetition, 0, 215, 385, 211);
    }
    if (changes.netflix==true){
        image(netflixHomePage, 0, 215, 385, 211);
    }
    if (changes.tikTok==true){
        image(tikTokHomePage, 0, 215, 385, 211);
    }
    if (changes.pills==true){
        image(xanaxBottle, 410, 340, 25, 44);
    }
    if (changes.muted==true){
        image(zoomMeeting, 0, 215, 385, 211);
    }
    if (changes.chegg==true){
        image(cheggHomePage, 0, 215, 385, 211);
    }

    //sounds triggered
    if (changes.cramps==true){
        fr1++;
        if (fr1==1){
            type.play();
        }
        fr1++;
        
    }
    if (changes.parents==true){
        fr2++;
        if (fr2==1){
            knockKnock.play();
        }
        fr2++;
    }
    if (changes.unmuted==true){
        fr3++;
        if (fr3==1){
            eating.play();
        }
        fr3++;
    }
    if (changes.zoomFatigue==true){
        fr4++;
        if (fr4==1){
            tired.play();
        }
        fr4++;

    }

    //triggers the congrats message
    if (changes.activism & changes.cramps && changes.voted && changes.text && changes.delivery && changes.canvasNotifs && changes.mask && changes.handshake && changes.rust && changes.night && changes.maskBox && changes.dino && changes.zeroPercent && changes.parents && changes.askText && changes.grenell && changes.netflix && changes.tikTok && changes.unmuted && changes.chegg && changes.pills && changes.muted && changes.zoomFatigue){
        fr5++;
        if (fr5>5){
            textAlign(CENTER);
            textSize(25);
            text("Congrats, you finished 2020!", width/2, height-50);
        }
    }
    
}

//types the alphabet on screen
function typeAlphabet() {
    for (var i = 0; i < 26; i ++) {
        textAlign(CENTER);
        textSize(20);
        noStroke();
        var yLocation = 540;
        var x = map(i, 0, alphabet.length, 50, width - 30);
        if (keyCode === 65 + i) { //when key is down, letter turns grey
            fill(100);
            text(alphabet[i], x, yLocation);
        } else {
            fill(0, 0, 51);
            text(alphabet[i], x, yLocation);
        } 
    }
}

function keyReleased() { //replaces already clicked letters and their info with spaces in the respective arrays
    for (var i = 0; i < 26; i ++) {
        if (keyCode == 65 + i) {
            alphabet.splice(i, 1, " ");
            letterMessage.splice(i, 1, " ");
        }       
    }
}

//types the messages on screen
function typeMessages() {
    textAlign(CENTER);
    textSize(15);
    fill(0, 0, 51);
    for (var i = 0; i < 26; i ++) {
        if (keyCode === 65 + i) {
            text(letterMessage[i], width / 2, height - 60);  
        } 
    }   
}

//draws accurate clock on the wall
function drawClock(){
    //from https://p5js.org/examples/input-clock.html
    var cx;
    var cy;
    var secR;
    var minR;
    var hrR;
    var cD;
  
    var radius=width/2;
    secR=radius*0.71;
    minR=radius*0.6;
    hrR=radius*0.5;
    cD=radius*1.7
  
    cx=width/2;
    cy=height/2;
  
    noStroke();
    fill(15);
    ellipse(cx, cy, cD+25, cD+25);
    fill(255);
    ellipse(cx, cy, cD, cD);
  
    var s=map(second(), 0, 60, 0, TWO_PI)-HALF_PI;
    var m=map(minute()+norm(second(), 0, 60), 0, 60, 0, TWO_PI)-HALF_PI;
    var h=map(hour()+norm(minute(), 0, 60), 0, 24, 0, TWO_PI*2)-HALF_PI;
  
    stroke(0);
    strokeWeight(1);
    line(cx, cy, cx+cos(s)*secR, cy+sin(s)*secR);
    strokeWeight(2);
    line(cx, cy, cx+cos(m)*minR, cy+sin(m)*minR);
    strokeWeight(4);
    line(cx, cy, cx+cos(h)*hrR, cy+sin(h)*hrR);
  
    strokeWeight(2);
    beginShape(POINTS);
    for(var i=0; i<360; i+=6){
        var angle=radians(i);
        var x=cx+cos(angle)*secR;
        var y=cy+sin(angle)*secR;
        vertex(x, y);
    }
    endShape();
  }

My final project was inspired by working from home as a full time student last semester and this semester. Like many other students, I experienced a lot of difficulties and setbacks we don’t usually have at school and I wanted to show all the tiny things that happen to us everyday. I also wanted it to reflect the political unrest that was happening at the same time due to the rise of the Black Lives Matter movements, the election, and for CMU students the hiring of Richard Grenell.
My program is interactive and each change is triggered by the keyboard. Users are supposed to follow the alphabet and something will change on the screen or a sound will be played. Since there are some sounds, you will need to use a localhost in order to hear them or view it from WordPress.

Final Project – Survive 2020 Game

Our project is inspired by the game Flappy Bird. In our rendition, 2020 events are the obstacles on the pipes and the goal is to “survive” 2020. The character moves up when you hit the letter ‘m’, the game ends if you hit one of the pipes, hit the ground or if you win by passing 12 pairs of pipes. If you lose by hitting a pipe or win you can play the game again, but if you hit the ground you lose and cannot restart the game. The two sounds you hear are the bounce when you move the character and the clash when the character hits one of the pipes. Based on which pipe you hit, you see a different “game over” message. We chose a darker color scheme and used a fire in the background to match the mood of 2020. If we had more time with this project, we would add a webcam function so that the character would be the user’s face instead of just a smiley face. Overall, this project was definitely challenging but also really fun to create.

final project
/* 
 * Final Project 
 * Rishi Karthikeyan and Amy Lee 
 * rkarthik and amyl2
 * Section B 
 */ 

// Run a local server to hear sounds used 
// Press the letter m to control character
// The game ends if the character hits the ground or the pipes 
// If you lose by hitting a pipe or win you can play the game again 
// but if you hit the ground you lose and cannot restart the game

var score = 0;
var count = 0;
var faceX = 50; 
var faceY = 200; 
var hitPipe = false; 
var endGame = false; 
var gameOn = true;
var gameStart = true;
var characterOn = true;
var pipes = []; 
var fire = [];
var pipeImages = []; // an array to store the images 
var factImages = []; // an array to store the dates between the pipes 
var gameOverImages = []; // an array to store the customized game over images 

var timeline1 = ["1/1/20", "1/16/20", "1/19/20", "2/2/20", "3/11/20", 
    "3/19/20", "3/20/20", "4/1/20", "5/1/20", "5/26/20", "11/6/20", "11/7/20"]

var timeline2=["Australian Bush Fire","Trump Impeached","COVID-19","Superbowl",
    "Parasite Wins Oscars","Zoom University","Tiger King","Royal Family Split",
    "Murder Hornets", "BLM Movement", "Election", "First Female VP Elect"]

function preload() {
    // Circular images that go in the pipes 
    var filenames = []; 
    filenames[0] = "https://i.imgur.com/tP1n00I.png"; // Fire 
    filenames[1] = "https://i.imgur.com/sY9uWvm.png"; // Trump 
    filenames[2] = "https://i.imgur.com/lCBeEEt.png"; // Covid 
    filenames[3] = "https://i.imgur.com/3Rckn2m.png"; // Superbowl 
    filenames[4] = "https://i.imgur.com/ul9jOdN.png"; // Oscar 
    filenames[5] = "https://i.imgur.com/iWRAmux.png"; // Zoom 
    filenames[6] = "https://i.imgur.com/dbYhauj.png"; // Tiger King
    filenames[7] = "https://i.imgur.com/lVbGhGa.png"; // Meg and Harry 
    filenames[8] = "https://i.imgur.com/U1PoDE5.png"; // Hornets 
    filenames[9] = "https://i.imgur.com/nqwizdc.png"; // BLM
    filenames[10] = "https://i.imgur.com/xtEZvMR.png"; // Election 
    filenames[11] = "https://i.imgur.com/1lZjhEQ.png"; // Kamala

    for (var i = 0; i < filenames.length; i ++) {
        pipeImages.push(loadImage(filenames[i])); 
    }

    // Displays game over message based on which pipe the character dies on
    var filenames2 = []; 
    filenames2[0] = "https://i.imgur.com/ibfDcOO.png"; // Fire  
    filenames2[1] = "https://i.imgur.com/vFpcofS.png"; // Trump 
    filenames2[2] = "https://i.imgur.com/NMyD9W2.png"; // Covid 
    filenames2[3] = "https://i.imgur.com/aU3iUST.png"; // Superbowl 
    filenames2[4] = "https://i.imgur.com/hqLtxr4.png"; // Oscar 
    filenames2[5] = "https://i.imgur.com/59MSAMG.png"; // Zoom 
    filenames2[6] = "https://i.imgur.com/ArzVHYU.png"; // Tiger King
    filenames2[7] = "https://i.imgur.com/up0miQL.png"; // Meg and Harry 
    filenames2[8] = "https://i.imgur.com/pSRx5bC.png"; // Hornets 
    filenames2[9] = "https://i.imgur.com/EzfHYCr.png"; // BLM
    filenames2[10] = "https://i.imgur.com/wJvHY17.png"; // Election 
    filenames2[11] = "https://i.imgur.com/929AM73.png"; // Kamala

    for (var i = 0; i < filenames2.length; i ++) {
        gameOverImages.push(loadImage(filenames2[i])); 
    }

    // Load sounds for when the character moves or hits the pipes 
    characterSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/bounce.wav");
    clashSound = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/clash.wav"); 
}

function setup() {
    createCanvas(450, 400);
    background(12, 22, 24);
    imageMode(CENTER); 
    useSound();

    if (gameOn == true) {
        fire.push(makeFire());
        pipes.push(makePipes());
    } 
}

function soundSetup() { 
    // Set the volume for the sound effects 
    characterSound.setVolume(0.01);
    clashSound.setVolume(0.05); 
}

function draw() {
    background(12, 22, 24);
    gradientSky();

    if (gameOn == true) {
        // Start the count once the game is on 
        count++
        // Display & add fire
        updateAndDisplayFire(); 
        if (count % 50 == 10){
            fire.push(makeFire()); 
        }
        updateAndDisplayPipes();
        // Add new pipes 
        if (count % 120 == 0){
            if (gameOn == true) {
            }

            if (pipes.length < 12) {
                pipes.push(makePipes()); 
            }

            if (count > 300) {
                score += 150;
            }
        }
    }

    // Score tracker  
    textSize(15);
    fill(72,160,141);
    noStroke();
    text('SCORE ' + score, 50, 23);

    drawFace(); 

    if (count >= 1690){ 
        gameOn = false; 
    } 

    if (gameOn == false) {
        gameWon();
    }

    if (hitPipe == true){
        gameOver(round((count/120) - ((120*3)/120))); 
    }
    
}

function gradientSky() {
    // Background color gradient 
    var darkCol = color(0,12,15); 
    var lightCol = color(14,38,39); 
    for (var y = 0; y < height; y ++){
        var backG = map(y, 0, height, 0, 1); 
        var backGColor = lerpColor(darkCol, lightCol, backG); 
        stroke(backGColor); 
        line(0, y, width, y); 
    }

    // Fire Embers 
    for (var i = 0; i < 35; i++) {
        strokeWeight(4);
        if (round(random(1)) == 0 ) {
            stroke(148, 67, 43);
        } else {
            stroke(81, 33, 22);
        }
        point(random(0,width), random(-0, height));
    }
}

// *************** FIRES *************** //
function updateAndDisplayFire(){
    // Update the fire's positions, and display them.
    for (var i = 0; i < fire.length; i++){
        fire[i].move();
        fire[i].draw();
    }
}

// Method to update position of fire every frame
function fireMove() {
    this.x += this.speed;
}

// Draw the fire 
function fireDraw() {
    push();
    translate(0, height - 220);
    scale(1.2, 1.75);
    noStroke();
    fill(81, 33, 22);   //red fire
        beginShape();
        vertex(this.x, this.y + 125);
        vertex(this.x, this.y  + 115);
        vertex(this.x + 5, this.y  + 115);
        curveVertex(this.x + 4, this.y  + 113);
        curveVertex(this.x + 3, this.y  + 112);
        curveVertex(this.x + 3, this.y  + 108);
        curveVertex(this.x + 5, this.y  + 102);
        curveVertex(this.x + 9, this.y  + 98);
        vertex(this.x + 18 + random(-1, 1), this.y + 93+ random(-1, 1));

        curveVertex(this.x + 17, this.y  + 110);
        curveVertex(this.x + 21, this.y  + 112);
        curveVertex(this.x + 31, this.y  + 109);
        curveVertex(this.x + 31, this.y  + 102);
        curveVertex(this.x + 25, this.y  + 95);
        curveVertex(this.x + 24, this.y  + 89);
        curveVertex(this.x + 27, this.y  + 83);
        curveVertex(this.x + 34, this.y  + 77);
        curveVertex(this.x + 40, this.y  + 70);
        curveVertex(this.x + 34, this.y  + 56);
        vertex(this.x + 30 + random(-1, 1), this.y  + 53 + random(-1, 1));

        curveVertex(this.x + 40, this.y  + 56);
        curveVertex(this.x + 50, this.y  + 64);
        curveVertex(this.x + 48, this.y  + 75);
        curveVertex(this.x + 41, this.y  + 83);
        curveVertex(this.x + 38, this.y  + 90);
        curveVertex(this.x + 40, this.y  + 98);
        curveVertex(this.x + 49, this.y  + 99);
        curveVertex(this.x + 52, this.y  + 95);
        curveVertex(this.x + 48, this.y  + 90);
        curveVertex(this.x + 48, this.y  + 84);
        vertex(this.x + 55 + random(-1, 1), this.y  + 75 + random(-1, 1));

        curveVertex(this.x + 54, this.y  + 81);
        curveVertex(this.x + 56, this.y  + 89);
        curveVertex(this.x + 60, this.y  + 97);
        curveVertex(this.x + 56, this.y  + 104);
        curveVertex(this.x + 62, this.y  + 117);
        curveVertex(this.x + 72, this.y  + 118);
        curveVertex(this.x + 80, this.y  + 112);
        curveVertex(this.x + 75, this.y  + 99);
        curveVertex(this.x + 68, this.y  + 92);
        curveVertex(this.x + 63, this.y  + 83);
        curveVertex(this.x + 70, this.y  + 63);
        curveVertex(this.x + 84, this.y  + 54);
        vertex(this.x + 94 + random(-1, 1), this.y  + 50 + random(-1, 1));

        curveVertex(this.x + 85, this.y  + 56);
        curveVertex(this.x + 77, this.y  + 65);
        curveVertex(this.x + 73, this.y  + 73);
        curveVertex(this.x + 77, this.y  + 77);
        curveVertex(this.x + 87, this.y  + 75);
        vertex(this.x + 89 + random(-1, 1), this.y  + 63 + random(-1, 1));

        curveVertex(this.x + 93, this.y  + 68);
        curveVertex(this.x + 93, this.y  + 78);
        curveVertex(this.x + 87, this.y  + 86);
        curveVertex(this.x + 81, this.y  + 93);
        curveVertex(this.x + 87, this.y  + 99);
        curveVertex(this.x + 92, this.y  + 99);
        curveVertex(this.x + 97, this.y  + 92);
        curveVertex(this.x + 94, this.y  + 87);
        curveVertex(this.x + 94, this.y  + 84);
        vertex(this.x + 98 + random(-1, 1), this.y  + 77 + random(-1, 1));

        curveVertex(this.x + 101, this.y  + 85);
        curveVertex(this.x + 104, this.y  + 89);
        curveVertex(this.x + 107, this.y  + 97);
        curveVertex(this.x + 104, this.y  + 104);
        curveVertex(this.x + 101, this.y  + 110);
        curveVertex(this.x + 109, this.y  + 115);

        vertex(this.x + 113, this.y  + 115);
        vertex(this.x + 113, this.y  + 128);
        endShape(CLOSE);
    pop();

    push();
    translate(0, height - 125);
    scale(1, 1);
    noStroke();
    fill(148, 67, 43);  //orange fire   
        beginShape();
        vertex(this.x, this.y + 125);
        vertex(this.x, this.y  + 115);
        vertex(this.x + 5, this.y  + 115);
        curveVertex(this.x + 4, this.y  + 113);
        curveVertex(this.x + 3, this.y  + 112);
        curveVertex(this.x + 3, this.y  + 108);
        curveVertex(this.x + 5, this.y  + 102);
        curveVertex(this.x + 9, this.y  + 98);
        vertex(this.x + 18 + random(-1, 1), this.y + 93+ random(-1, 1));

        curveVertex(this.x + 17, this.y  + 110);
        curveVertex(this.x + 21, this.y  + 112);
        curveVertex(this.x + 31, this.y  + 109);
        curveVertex(this.x + 31, this.y  + 102);
        curveVertex(this.x + 25, this.y  + 95);
        curveVertex(this.x + 24, this.y  + 89);
        curveVertex(this.x + 27, this.y  + 83);
        curveVertex(this.x + 34, this.y  + 77);
        curveVertex(this.x + 40, this.y  + 70);
        curveVertex(this.x + 34, this.y  + 56);
        vertex(this.x + 30 + random(-1, 1), this.y  + 53 + random(-1, 1));

        curveVertex(this.x + 40, this.y  + 56);
        curveVertex(this.x + 50, this.y  + 64);
        curveVertex(this.x + 48, this.y  + 75);
        curveVertex(this.x + 41, this.y  + 83);
        curveVertex(this.x + 38, this.y  + 90);
        curveVertex(this.x + 40, this.y  + 98);
        curveVertex(this.x + 49, this.y  + 99);
        curveVertex(this.x + 52, this.y  + 95);
        curveVertex(this.x + 48, this.y  + 90);
        curveVertex(this.x + 48, this.y  + 84);
        vertex(this.x + 55 + random(-1, 1), this.y  + 75 + random(-1, 1));

        curveVertex(this.x + 54, this.y  + 81);
        curveVertex(this.x + 56, this.y  + 89);
        curveVertex(this.x + 60, this.y  + 97);
        curveVertex(this.x + 56, this.y  + 104);
        curveVertex(this.x + 62, this.y  + 117);
        curveVertex(this.x + 72, this.y  + 118);
        curveVertex(this.x + 80, this.y  + 112);
        curveVertex(this.x + 75, this.y  + 99);
        curveVertex(this.x + 68, this.y  + 92);
        curveVertex(this.x + 63, this.y  + 83);
        curveVertex(this.x + 70, this.y  + 63);
        curveVertex(this.x + 84, this.y  + 54);
        vertex(this.x + 94 + random(-1, 1), this.y  + 50 + random(-1, 1));

        curveVertex(this.x + 85, this.y  + 56);
        curveVertex(this.x + 77, this.y  + 65);
        curveVertex(this.x + 73, this.y  + 73);
        curveVertex(this.x + 77, this.y  + 77);
        curveVertex(this.x + 87, this.y  + 75);
        vertex(this.x + 89 + random(-1, 1), this.y  + 63 + random(-1, 1));

        curveVertex(this.x + 93, this.y  + 68);
        curveVertex(this.x + 93, this.y  + 78);
        curveVertex(this.x + 87, this.y  + 86);
        curveVertex(this.x + 81, this.y  + 93);
        curveVertex(this.x + 87, this.y  + 99);
        curveVertex(this.x + 92, this.y  + 99);
        curveVertex(this.x + 97, this.y  + 92);
        curveVertex(this.x + 94, this.y  + 87);
        curveVertex(this.x + 94, this.y  + 84);
        vertex(this.x + 98 + random(-1, 1), this.y  + 77 + random(-1, 1));

        curveVertex(this.x + 101, this.y  + 85);
        curveVertex(this.x + 104, this.y  + 89);
        curveVertex(this.x + 107, this.y  + 97);
        curveVertex(this.x + 104, this.y  + 104);
        curveVertex(this.x + 101, this.y  + 110);
        curveVertex(this.x + 109, this.y  + 115);

        vertex(this.x + 113, this.y  + 115);
        vertex(this.x + 113, this.y  + 128);
        endShape(CLOSE);
    pop();
}

function makeFire() {
    var fire = {x: width,
                y: 0,
                speed: -2,
                move: fireMove,
                draw: fireDraw}
    return fire;
}

// *************** CHARACTER *************** //
function drawFace() {
    if (characterOn == true) { 
        push(); 
        // Head 
        noStroke();
        fill(72,160,141); 
        ellipse(faceX, faceY, 30, 30); 
        // Eyes 
        fill(12, 22, 24); 
        ellipse(faceX - 9, faceY - 1, 3.5, 3.5); 
        ellipse(faceX + 9, faceY - 1, 3.5, 3.5); 
        // Mouth 
        noFill(); 
        stroke(12, 22, 24); 
        strokeWeight(1); 
        arc(faceX, faceY, 5, 5, 0, PI, OPEN);
        pop(); 
        faceY += 1; 

        // Keep face from going off of the canvas
        if (faceY < 15){
            faceY += 5;
        }
        // Game over if you hit the bottom of the canvas
        if (faceY > height - 15){
           hitBottomGameOver();
        }
    }
}

// *************** PIPES *************** //
function updateAndDisplayPipes(){

    // Update the pipe's positions, and display them
    for (var i = 0; i < pipes.length; i++) {
        pipes[i].move();

        // Game over if face hits the pipes 
        if (((faceY < pipes[i].pipeHeight + 30) & (faceX > pipes[i].x && 
            faceX < pipes[i].x + pipes[i].pipeWidth)) || ((faceY > 400 - 
            ((400 - (pipes[i].pipeHeight + (200 - pipes[i].pipeHeight) + 
            (122 - (200 - pipes[i].pipeHeight)))) + 55)) && 
            (faceX > pipes[i].x && faceX < pipes[i].x + pipes[i].pipeWidth))){

            hitPipe = true; 
            clashSound.play();
        }

        if (gameStart == true) {
            pipes[i].draw();
        }

        // Display image on pipe 
        pipes[i].imageNumber = i;
        if ( pipes[i].imageNumber > 11) {
            pipes[i].imageNumber = 0;
        }

        // Display timeline date in between pipes 
        pipes[i].timelineNumber = i; 
        if ( pipes[i].timelineNumber > 11) {
            pipes[i].timelineNumber = 0;
        }
    } 
}

// Method to update position of pipe every frame
function pipesMove() {
    this.x += this.speed;
}
    
// Draw the pipe 
function pipesDraw() {
    var pipe1Height = this.pipeHeight - 30; 
    var pipe2Height = 400 - (this.pipeHeight + (200 - this.pipeHeight) + 
                    (126 - (200 - this.pipeHeight)) ); 

    fill(34,79,82); 
    noStroke(); 

    // Top Pipe 
    rect(this.x, -30, this.pipeWidth, this.pipeHeight); 
    ellipse(this.x + 40, pipe1Height, this.pipeWidth, this.pipeWidth); 
    image(pipeImages[this.imageNumber], this.x + 40, pipe1Height, 60, 60); 

    // Fact in middle of pipe 
    textSize(15);
    textAlign(CENTER); 
    fill(148, 67, 43);
    text(timeline1[this.timelineNumber], this.x + 40, (pipe1Height + 
        ((400 - ((pipe1Height) + (pipe2Height)))/2)) - 2);
    text(timeline2[this.timelineNumber], this.x + 40, (pipe1Height + 
        ((400 - ((pipe1Height) + (pipe2Height)))/2)) + 15);

    // Bottom Pipe 
    push(); 
    fill(34,79,82); 
    translate(0,400); 
    rect(this.x, -pipe2Height, this.pipeWidth, pipe2Height); 
    ellipse(this.x + 40, -pipe2Height, this.pipeWidth, this.pipeWidth);
    image(pipeImages[this.imageNumber], this.x + 40, -pipe2Height, 60, 60);     
    pop(); 
}

function makePipes() {
    var pipe = {x: 650,
                pipeWidth: 80, 
                pipeHeight: random(130, 200),
                speed: -2, 
                move: pipesMove,
                draw: pipesDraw,
                imageNumber: 0,
                timelineNumber: 0
                }
    return pipe;
}

function keyPressed() {
    if (key == 'm'){ 
        faceY -= 20; 

        if (characterOn == true) {
            characterSound.play();
        }
    }
}

// Function that is run when character hits the bottom of the canvas 
function hitBottomGameOver() {
    push();
    gradientSky();

    noStroke();
    fill(72,160,141);
    rectMode(CENTER);
    rect(width/2, height/2, 227, 55);
    textAlign(CENTER);
    textSize(20);
    fill(148, 67, 43);
    text(' Y O U  L O S T  2 0 2 0 ! ', width/2, height/2);

    characterOn = false;
    noLoop();
    pop();
}

// Function that is run when the character hits the pipe 
function gameOver(pipeNumber){
            // Display the gradient sky
            gradientSky();

            // Display game over image depending on which pipe was hit 
            image(gameOverImages[pipeNumber], width/2, height/2, 250, 250); 

            // Display play again button 
            fill(148, 67, 43);
            stroke(180, 67, 43);
            strokeWeight(2);
            push();
            rectMode(CENTER);
            rect(width/2, height/2 + 160, 110, 35);
            pop();
            textSize(15);
            noStroke();
            fill(255);
            text('PLAY AGAIN', width/2, height/2 + 165);

            gameStart = false;
            characterOn = false;
            hitPipe = true; 
            gameOn = false;
}

// Function that is run when the character wins the entire game 
function gameWon() {
    push();

    // "YOU WON 2020" sign in center of screen 
    noStroke();
    fill(72,160,141);
    rectMode(CENTER);
    rect(width/2, height/2, 225, 55);
    textAlign(CENTER);
    textSize(20);
    fill(148, 67, 43);
    text(' Y O U  W O N  2 0 2 0 ! ', width/2, height/2);

    // Play again button
    fill(148, 67, 43);
    stroke(180, 67, 43);
    strokeWeight(2);
    rect(width/2, height/2 + 55, 110, 35);
    textSize(15);
    noStroke();
    fill(255);
    text('PLAY AGAIN', width/2, height/2 + 55);

    characterOn = false;
    pop();
}

function mousePressed() {
    // Press to play again after a user wins the game 
    if (count >= 1689 & gameOn == false) {
        if (mouseX > width/2 - 55 && mouseX < width/2 + 55 && 
            mouseY < height/2 + 72.5 && mouseY > height/2 + 37.5) {
                gameOn = true;
                gameStart = true;
                characterOn = true;
                endGame = false; 
                count = -50;
                score = 0; 
                pipes = []; 
                fire = [];
        }
    }

    // Press to play again when user lost the game by hitting a pipe 
    if (hitPipe == true) {
        if (mouseX > width/2 - 55 & mouseX < width/2 + 55 && 
            mouseY < height/2 + 177.5 && mouseY > height/2 + 142.5) {
                hitPipe = false; 
                endGame = false; 
                gameStart = true;
                gameOn = true; 
                characterOn = true;
                count = -50;
                score = 0; 
                pipes = []; 
                fire = [];
        }
    }
}





original proposal mockup

***on our Autolab submission we use the up arrow to control the character but here we used the letter m because with the up arrow it would move the whole page up and not just the canvas***

Final Project: survive Covid

sketch

Introduction:
This is a survive Covid game. The goal is to help a ninja who’s trapped in a covid world avoid viruses, obtain masks, and eat sushi! I want to make this educational game to show that to fight covid one needs to wear a mask, stay safe, and eat well. The game is easy to play and has a lighthearted atmosphere. People can play this browser game to kill time and have fun.

Guidelines:
There will be viruses coming from the right of the screen and the player needs to press the space to make the ninja jump over the virus barricades. The player loses if the ninja hits the viruses for more than three times. The player gets an extra life when the ninja gets a mask. The player gets 20 extra points when the ninja eats a sushi. The game gets harder as the player gets higher scores.

Applications:
If I have more time, I wish to implement a shop feature which allows the player to buy new characters and items such as sanitizers and napkins, making the game more interesting.

//Name: Heying Wang  Andrew id: heyingw
//Section B
var ninja;
var ninjaSize=50;
var sushiSize=50;
var virus;
var virusSize=40;
var viruses=[];
var virusImages=[];
var clouds=[];
var sushiArray=[];
//The player has an initial score of 0 and life of 3
var score=0;
var life=3;
var timer=0;

var circleColor = [];
var r=50; //radius
var theta=0; 
var startAngles=[];
var xvalues=[];
var yvalues=[];


function preload() {
    //ninja image
    ninjaImage=loadImage('https://i.imgur.com/kpI63Vj.png')
    //background image
    bgImage=loadImage("https://i.imgur.com/S5mfVFp.jpg");
    //three kinds of covid virus
    virusImage1=loadImage("https://i.imgur.com/SjGhpnK.png")
    virusImage2=loadImage("https://i.imgur.com/AKjfL9n.png")
    virusImage3=loadImage("https://i.imgur.com/nYvztEk.png")
    virusImages.push(virusImage1);
    virusImages.push(virusImage2);
    virusImages.push(virusImage3);

    cloudImg=loadImage("https://i.imgur.com/fLez1dg.png");
    sushiImg=loadImage("https://i.imgur.com/oz3ud5W.png");

    //load the sounds
    game=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/game.wav');
    sushiSound=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/sushi.wav');
    jump=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/jump.wav');
    mask=loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/mask.wav');
}


function setup() {
    createCanvas(600, 250);
    useSound();
    //set up with constructors
    ninja=makeNinja(20,height-100,ninjaImage,ninjaSize);
    virus=makeVirus(width-100,height-50,virusSize,random(virusImages));
    viruses.push(virus);
    sushi=makeSushi(width*3,100,sushiImg,sushiSize);
    sushiArray.push(sushi); 

    for (var i = 0; i < 2; i++){
        var rx = random(width,width*2);
        clouds[i] = makeCloud(rx);
    }

    for (var i = 0; i < 12; i++) {
        circleColor[i] = color(random(0,256), random(0, 256), random(0, 256),120);
        startAngles[i] = i*30;
    }
    
}

//set up the sounds
function soundSetup() { 
    game.loop();
    game.setVolume(0.5);
    jump.setVolume(0.1);

    
 
}



function draw() {
    //set a timeCounter
    timer+=1;
    console.log(timer);
    image(bgImage,0,0,600,250);
    fill(255);
    textSize(20);
    text("score: "+score,470,30);
    text("life: "+life,30,30);
    push();
    drawCircles();
    pop();
    //draw ninja. Move ninja
    ninja.show();
    ninja.move();
    for(var i=0;i<sushiArray.length;i++){
        sushiArray[i].show();
        sushiArray[i].move();
    }

    //draw and move every virus in the viruses array
    if(timer>150){
        for(var i=0;i<viruses.length;i++){
            viruses[i].show();
            viruses[i].move();
        }
    }
    console.log(timer);

    //level up as the player gets higher scores
    if(score>50){
        virusSize=50;
    }
    else if(score>120){
        ninjaSize=60;
    }
    else if(score>200){
        virusSize=60;
    }

    /*append new viruses to the list if the virus array is about to 
    running out of virus*/
    if(viruses.length<10){
        makeFiveNewViruses()};
    if(sushiArray.length<2){
        makeNewSushi()};
    //console.log(viruses.length)

    //check collision for every virus in the array
    //check collision only when the timeCounter%10==0
    //we can't check collision at every frame otherwise life will be reducted mulpital times for one collision
    for(var i=0;i<viruses.length;i++){
        if(timer%10==0){
            checkCollision(ninja,viruses[i]);
        }

        //remove the virus that goes off the screen 
        if(viruses[i].x<=-20){
            viruses.splice(viruses[i],1);
            score+=1;
            
        } 



    }

    for(var i=0;i<clouds.length;i++){
        checkCloudCollision(ninja,clouds[i]);
    
    }
    for(var i=0;i<sushiArray.length;i++){
        checkSushiCollision(ninja,sushiArray[i]);
    
    }
    updateAndDisplayClouds();
    removeCloudsThatHaveSlippedOutOfView();
    addNewCloudsWithSomeRandomProbability();
    //constantly check if the game is over
    //gameover condition: life is used up

    checkGameOver(); 

    
  
    
}

//if gameover, clear the canvas, stop the loop
function checkGameOver(){
    if(life==0){
        background(220);
        fill('red');
        text("Game Over!",250,100);
        noLoop();
        game.stop();
    }
}

function drawCircles(){
    noStroke();
    translate(307,85);
    for(var i = 0; i < 12; i++){
        xvalues[i]=r*cos(radians(startAngles[i]+theta));
        yvalues[i]=r*sin(radians(startAngles[i]+theta));
        fill(circleColor[i]);
        circle(xvalues[i],yvalues[i],10);
        theta-=0.05;
    }
}

//ninja consructor
function makeNinja(sx,sy,ninjaImage,ninjaSize){
    var ninja={x: sx, y: sy, sz:ninjaSize,vy: 0, gravity: 1.9, img:ninjaImage, show: ninjaDraw, jump:ninjaJump,
        move:ninjaMove

    }
    return ninja
}


//virus constructor
function makeVirus(sx,sy,virusSize,virusImage){
    var virus={x: sx, y: sy, sz:virusSize, vx:-7, img:virusImage, show: virusDraw, 
        move:virusMove

    }
    return virus
}

//sushi constructor
function makeSushi(sx,sy,sushiImg,sushiSize){
    var ss={x: sx, y: sy, sz:sushiSize, vx:-1, img:sushiImg, show: sushiDraw, 
        move:sushiMove

    }
    return ss
}

//make new viruses when needed
function makeFiveNewViruses(){
    for(var i=0;i<5;i++){
        viruses.push(makeVirus(viruses[viruses.length-1].x+random(120,800),height-50,virusSize,random(virusImages)));
    }
}

function makeNewSushi(){
        sushiArray.push(makeSushi(sushiArray[sushiArray.length-1].x+random(width*2,width*4),random(20,190),sushiImg, sushiSize));
    
}

function ninjaDraw(){
    image(this.img,this.x,this.y,this.sz,this.sz);
}

function virusDraw(){
    image(this.img,this.x,this.y,this.sz,this.sz);
}

function sushiDraw(){
    image(this.img,this.x,this.y,this.sz,this.sz);
}

function ninjaJump(){
    //prevents the ninja from sticking at the top (if player keeps pressing space)
    if(this.y>=height-100){
        this.vy=-25;
    }

    

}


//implement gravity
//use constrain to prevent the ninja from going offscreen
function ninjaMove(){
    this.y+=this.vy;
    this.vy+=this.gravity;
    this.y=constrain(this.y,0,height-this.sz);
 
  

  
    
}


//collision detection
function checkCollisionAandB(A,B){
    if(A.x < B.x + B.sz &
        A.x + A.sz > B.x &&
        A.y < B.y + B.sz &&
        A.y + A.sz > B.y){
            return true
    }
    

}
function checkCollision(ninja,virus){
    if(checkCollisionAandB(ninja,virus)){
            life-=1
    }
    

}

//masks give players life
function checkCloudCollision(ninja,cloud){
    if(checkCollisionAandB(ninja,cloud)){
            mask.play();
            clouds.splice(cloud,1);
            life+=1
    }
    

}

//sushi give players scores
function checkSushiCollision(ninja,sushi){
    if(checkCollisionAandB(ninja,sushi)){
        sushiSound.play();
        sushiArray.splice(sushi,1);
        score+=20; 
    }
    

}




function virusMove(){
    this.x+=this.vx;
  

    
}

function sushiMove(){
    this.x+=this.vx;
  

    
}

//ninja jumps when player presses the space
function keyPressed(){
    if(key==' '){
        ninja.jump();
        jump.play();
    }
}

function updateAndDisplayClouds(){
    // Update the clouds(masks)' positions, and display them.
    for (var i = 0; i < clouds.length; i++){
        clouds[i].move();
        clouds[i].display();
    }
}    

function removeCloudsThatHaveSlippedOutOfView(){
    var cloudsToKeep = [];
    for (var i = 0; i < clouds.length; i++){
        if (clouds[i].x + clouds[i].sz > 0) {
            cloudsToKeep.push(clouds[i]);
        }
    }
    clouds = cloudsToKeep; 
}

function addNewCloudsWithSomeRandomProbability() {
    var newCloudLikelihood = 0.01; 
    if (random(0,5) < newCloudLikelihood) {
        clouds.push(makeCloud(width));
    }
}

function makeCloud(birthLocationX) {
    var cld = {x: birthLocationX,
                cloudImage:cloudImg,
                y:random(10,100),
                speed: -0.5,
                sz:random(25,60),
                move: cloudMove,
                display: cloudDisplay}
    return cld;
};

function cloudMove() {
    this.x += this.speed;
}
function cloudDisplay() {
    image(this.cloudImage,this.x,this.y,this.sz,this.sz*0.5);

}





PROJECT-15 (covid-simulator)

For this project, I decided to go in a direction of analyzing covid spread through showing how if you infect one person, how the others will get infected through probability and chance. I will use an array of people and if one or more is clicked, a droplet of covid is “given” to the person to “infect” them. Over time, the nearby people will heal and recover or pass away. If all people are infected, the population will never recover.

sketch
// 15-104
// SEAN CHEN
// FINAL PROJECT


var people = [];
var wNum = 14;
var hNum = 12;
var chance = .1; // chance of transmission
var speed = 20; // speed of transmission
var deathRate = 0.02; // death rate
var body;

// image for the body
function preload() {
    body = loadImage('https://i.imgur.com/BBvwTQi.png');
}

// creating the heads array
function setup() {
    createCanvas(600, 400);
    for (var i = 0; i < wNum; i++) {
        var temp = []
        for (var j = 0; j < hNum; j++) {
            temp.push(createPerson(i, j));
        }
        people.push(temp);
    }
    frameRate(speed);
}

// drawing people + infection spreading
function draw() {
    background(235);
    updatePerson();
    infectPerson();
}

// step and drawing of people
function updatePerson() {
    for (var i = 0; i < wNum; i++) {
        for (var j = 0; j < hNum; j++) {
            people[i][j].draw();
            people[i][j].step();
        }
    }
}

// creating person object
function createPerson(x, y) {
    var p = {
        px: x*(width/(wNum-1)),
        py: y*(height/(hNum-1)),
        infected: 0,
        age: 0,
        col: 0,
        draw: thePerson,
        step: stepPerson,
    }
    return p;
}

// individual people
function thePerson() {
    stroke(0);
    push();
    translate(-20, 5);
    image(body, this.px, this.py, 40, 80);
    pop();

    push();
    fill(colPerson(this.col));
    circle(this.px, this.py, 30);
    fill(255);
    ellipse(this.px-8, this.py-2, 7, 10);
    ellipse(this.px+8, this.py-2, 7, 10);
    pop();

    push();
    noStroke();
    fill(0);
    circle(this.px-8, this.py-2, 4, 4);
    circle(this.px+8, this.py-2, 4, 4);
    pop();
}

// red for most infected
// green for temp immunity
// black for death
function colPerson(colNum) {
    if (colNum == 0) {
        return color(255);
    } else if (colNum == 1) {
        return color(255, 0, 0);
    } else if (colNum == 2) {
        return color(255, 65, 65);
    } else if (colNum == 3) {
        return color(255, 130, 130);
    } else if (colNum == 4) {
        return color(255, 195, 195);
    } else if (colNum == 5) {
        return color(0, 255, 0);
    } else if (colNum == 6) {
        return color(0);
    }
}

// if infected, what stage infection
function stepPerson() {
    if (this.infected == 2) {
        this.col = 6;
        this.age = 0;
    }
    if (this.infected == 1) {
        this.age++;
        if (this.age <= 10) {
            this.col = 1;
        } else if (this.age > 10 & this.age <= 20) {
            this.col = 2;
        } else if (this.age > 20 & this.age <= 30) {
            this.col = 3;
        } else if (this.age > 30 & this.age < 40) {
            this.col = 4;
        } else if (this.age < 60) {
            if (random(0, 10) < deathRate) {
                this.infected = 2;
            } else {
                this.col = 5;
            }
        } else if (this.age == 60) {
            this.col = 0;
            this.age = 0;
            this.infected = 0;
        }
    }
}

function mouseClicked() {
    clickPerson();
}

// clicking persons to give covid
function clickPerson() {
    for (var i = 0; i < wNum; i++) {
        for (var j = 0; j < hNum; j++) {
            if (dist(mouseX, mouseY, people[i][j].px, people[i][j].py) < 20)  {
                people[i][j].infected = 1;
                people[i][j].col = 1;
                people[i][j].age = 0;
            }
        }
    }
}

// infecting right
function r(i, j) {
    if (random(0, 10) < chance & people[i+1][j].infected != 2) {
        people[i+1][j].infected = 1;
    }
}
// infecting left
function l(i, j) {
    if (random(0, 10) < chance & people[i-1][j].infected != 2) {
        people[i-1][j].infected = 1;
    }
}
// infecting up
function u(i, j) {
    if (random(0, 10) < chance & people[i][j-1].infected != 2) {
        people[i][j-1].infected = 1;
    }
}
// infecting down
function d(i, j) {
    if (random(0, 10) < chance & people[i][j+1].infected != 2) {
        people[i][j+1].infected = 1;
    }
}

// probability and chance of spread
function infectPerson() {
    for (var i = 0; i < wNum; i++) {
        for (var j = 0; j < hNum; j++) {
            if (people[i][j].age >= 20) {
                if (i > 0 & j > 0 && i < wNum-1 && j < hNum-1) {
                    r(i, j);
                    l(i, j);
                    u(i, j);
                    d(i, j);
                } else if (i == 0 & j == hNum-1) {
                    r(i, j);
                    u(i, j);
                } else if (i == wNum-1 & j == 0) {
                    l(i, j);
                    d(i, j);
                } else if (i == 0 & j == 0) {
                    r(i, j);
                    d(i, j);
                } else if (i == 0) {
                    r(i, j);
                    u(i, j);
                    d(i, j);
                } else if (j == 0) {
                    r(i, j);
                    l(i, j);
                    d(i, j);
                } else if (i == wNum-1 & j == hNum-1) {
                    l(i, j);
                    u(i, j);
                } else if (i == wNum-1) {
                    l(i, j);
                    u(i, j);
                    d(i, j);
                } else if (j == hNum-1) {
                    r(i, j);
                    l(i, j);
                    u(i, j);
                }
            }
        }
    }
}