xxxxxxxxxx
739
// Bitmap Game
var scene = 0;
let drops = [];
let minScore = 4;
var bucket, dropper;
var dropSpeed = 4;
var gap = -2000;
var dropSize = 20;
var bucketSpeed = 3;
var counter = 0;
var highscore = 0;
var interval = 20000;
var L1timer;
var countdown;
var gameOn1 = false;
let squirrel;
// Level 2 variables
var gameEnd = false;
var bgColor = 255;
var startBtn, restartBtn, nextBtn;
var showImg1 = false;
var showImg2 = false;
var showImg3 = false;
var showImg4 = false;
var showImg5 = false;
// Random Ball Placement
var xBall = Math.floor(Math.random() * 300) + 50;
var yBall = 50;
var xSpeed = (4, 9);
var ySpeed = (-9, -4);
var L2score = 0;
// Level 3 variables
var changeDir1 = false;
var changeDir2 = false;
var changeDir3 = false;
var aim = false;
var clicked = false;
var targets = [];
let L3timer = 20;
let L3score = 0;
let hearts = [];
function preload() {
// Level 1 images
L1bg = loadImage('forrest.jpg');
squirrel = loadImage('squirrel-clipart-climb-351736.png');
owl = loadImage('profowl.png');
acorn = loadImage('acorn.png');
// Level 2 images
L2bg = loadImage('Grass.jpeg');
mansion = loadImage('mansion.png');
// Eating clubs
cottage = loadImage('judgy_wypipo.jpg');
ti = loadImage('coolppl.jpg');
terrace = loadImage('potheads.jpg');
cap = loadImage('Unfriend.png')
colonial = loadImage('nerds.jpg')
// Level 3 images
L3bg = loadImage('nassauhall.jpg');
sHeart = loadImage('sanityheart.png');
gHeart = loadImage('gradesheart.png');
fHeart = loadImage('friendsheart.png');
tHeart = loadImage('thesisheart.png');
hHeart = loadImage('healthheart.png');
adminbull = loadImage('adminbull.png');
wine = loadImage('wine1.png');
meantig = loadImage('meantiger.png');
lastbg = loadImage('tigerfathersday.png');
}
function setup() {
createCanvas(700, 500);
changeDirection = false;
// LEVEL 1 ASSETS
bucket = new Bucket(width / 2, height - 60, 60, 60);
dropper = new Dropper(100, 150, 150, 150);
L1timer = millis() + interval;
startBtn = new Button(width / 2, height / 2, 100, 50, "PLAY", 255);
restartBtn = new Button(width / 2, height / 2, 200, 50, "RESTART", 255);
for (let i = 0; i < 5; i++) {
drops[i] = new Drop(random(width), random(-20, gap), dropSize, dropSpeed);
}
// LEVEL 2 ASSETS
nextBtn = new Button1(width / 2, height / 2, 200, 50, "YES");
main = new mainChar(0, height / 2, 60, 60);
house1 = new house(120, 20, 100, 100);
house2 = new house(320, 20, 100, 100);
house3 = new house(520, 20, 100, 100);
house4 = new house(120, 380, 100, 100);
house5 = new house(320, 380, 100, 100);
house6 = new house(520, 380, 100, 100);
nextBtn1 = new Button1(width / 2, height / 2, 200, 50, "FINE");
nextBtn2 = new Button1(width / 2, height / 2, 200, 50, "YES");
// LEVEL 3 ASSETS
obs1 = new Obs(adminbull,width / 2 - 20, height / 2 + 80, 100, 100);
obs2 = new Obs(wine,0, height / 2 - 50, 100, 100);
obs3 = new Obs(meantig,500, height / 2 - 150, 100, 100);
shooter = new Shooter(width / 2 - 25, height-60, 60, 60);
bullet = new Bullet(shooter.x, 450, 20, 20);
target1 = new Target(sHeart, 0, 0, 100, 100);
target2 = new Target(gHeart, 150, 0, 100, 100);
target3 = new Target(fHeart, 300, 0, 100, 100);
target4 = new Target(tHeart, 450, 0, 100, 100);
target5 = new Target(hHeart, 600, 0, 100, 100);
replayBtn = new Button(width / 2, 450, 200, 50, "PLAY AGAIN", 255);
}
function draw() {
background(bgColor);
textSize(32);
// SCENE CHANGES
switch (scene) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
if (scene === 0) { // START SCREEN
bgColor = color(255, 117, 26);
fill(0);
text('Do you have what it takes', 170, 100);
text('To SURVIVE Princeton University..?', 100, 150);
text("(because I barely did)", 190, 200);
startBtn.render();
startBtn.click();
} else if (scene === 1) { // LEVEL 1
//bgColor = 255;
image(L1bg, 0, 0, width, height);
fill(255);
if (L1timer < millis()) {
L1timer = millis() + interval;
}
if (gameOn1) {
countdown = ceil((L1timer - millis()) / 1000) - 1;
}
if (countdown == 0) {
gameOver1();
}
push();
textSize(22);
text("Time: " + countdown, 20, 50);
text("Intellectual Capability: ", 20, 80);
rect(20, 85, 10 + 10 * counter, 15);
pop();
for (let i = 0; i < 5; i++) {
drops[i].reset();
drops[i].move();
drops[i].render();
drops[i].caught();
}
// Main character movement
bucket.render();
bucket.move();
// Prof movement
dropper.move();
dropper.render();
if (countdown <= 17 && countdown >= 16) {
fill(0);
text("Aquire knowledge, or Professor Owl will keep it!", width / 2 - 335, height / 2 - 120);
}
} else if (scene === 2) { // restart
bgColor = 0;
fill(255);
//text("Score: " + counter, width/2-60, height/2-150);
text("Looks like you didn't make it.", width / 2 - 200, height / 2 - 100);
text("Remember: C's get degrees. Try again?", width / 2 - 280, height / 2 - 50);
restartBtn.render();
restartBtn.click();
} else if (scene === 3) { // LEVEL 2 TRANSITION
bgColor = color(255, 117, 26);
push();
fill(0);
text("Score: " + counter, width / 2 - 60, height / 2 - 150);
text("You passed! But do you have what it takes", 50, height / 2 - 100);
text("to survive the eating club scene?", 120, height / 2 - 50);
pop();
nextBtn.render();
nextBtn.click();
} else if (scene === 4) { // LEVEL 2
//bgColor = 255;
image(L2bg, 0, 0, width, height);
// fill(0);
main.render();
main.move();
house1.render();
house2.render();
house3.render();
house4.render();
house5.render();
house6.render();
if (main.x == 0 && main.y == height / 2) {
textSize(28);
fill(255, 117, 26);
text('Welcome to the infamous Prospect St.', 130, height / 2 - 30);
text('Check out each eating club to find where you belong!', 30, height / 2);
}
// bounds of house, load image
if (main.x > house1.x && main.x + main.w < 220 && main.y - main.h < house1.y + house1.h) showImg1 = true;
else showImg1 = false;
if (showImg1) {
image(cottage, -45, 0, width + 90, height);
textSize(100);
text("Too ethnic", width / 2 - 200, height / 2);
}
if (main.x > house2.x && main.x + main.w < 420 && main.y - main.h < house2.y + house2.h) showImg2 = true;
else showImg2 = false;
if (showImg2) {
image(ti, 0, 0, width, height);
textSize(100);
text("Too academic", 50, height / 2 + 50);
}
if (main.x > house3.x && main.x + main.w < 620 && main.y - main.h < house3.y + house3.h) showImg3 = true;
else showImg3 = false;
if (showImg3) {
image(terrace, 0, 0, width, height);
textSize(80);
text("Not chill enough", 80, height / 2 + 50);
}
if (main.x > house4.x && main.x + main.w < 220 && main.y > house4.y) showImg4 = true;
else showImg4 = false;
if (showImg4) {
image(cap, 0, 0, width, height);
textSize(80);
text("Not ethnic enough", 40, height / 2 + 50);
}
if (main.x > 320 && main.x + main.w < 420 && main.y > 380) showImg5 = true;
else showImg5 = false;
if (showImg5) {
image(colonial, -25, 0, width + 50, height);
textSize(100);
text("Too chill", width / 2 - 150, height / 2 + 50);
}
if (main.x > 520 && main.x + main.w < 620 && main.y > 380) scene = 5; // correct house!
} else if (scene === 5) { // transition to pong
bgColor = color(255, 117, 26);
fill(0);
text("Congratulations! You found your people.", 70, 85);
text("Quick! Play a drunken game of pong--", 85, 165);
text("Before you lose your cool factor!", 130, 200);
nextBtn1.render();
nextBtn1.click();
} else if (scene === 6) { // pong
bgColor = color(0, 36, 2);
// Paddle
fill('white');
rect(mouseX, height - 25, 90, 15);
//Functions
move();
display();
bounce();
paddle();
//Score
fill(204, 153, 255);
textSize(24);
text("Score: " + L2score, 10, 25);
if (L2score >= 8) scene = 7;
} else if (scene === 7) {
bgColor = 0;
fill(255);
text("Great.", 310, height / 2 - 150);
text("Now you'll have to complete the final test drunk.", 15, height / 2 - 100);
text("Oh well. Peer pressure sucks. Let's do this?", 40, height / 2 - 50);
nextBtn2.render();
nextBtn2.click();
} else if (scene === 8) { // LEVEL 3
fill(255, 117, 26);
image(L3bg, 0, 0, width, height);
textSize(22);
text('Time: ' + L3timer, 20, 450);
text('Score: ' + L3score, 20, 480);
if (frameCount % 60 == 0 && L3timer > 0) L3timer--;
// move obstacles
if (obs1.x > width - obs1.w) changeDir1 = true;
else if (obs1.x <= 0) changeDir1 = false;
if (obs1.x >= 0 && changeDir1 == false) obs1.x += 10;
else if (changeDir1 == true) obs1.x -= 10;
if (obs2.x > width - obs2.w) changeDir2 = true;
else if (obs2.x <= 0) changeDir2 = false;
if (obs2.x >= 0 && changeDir2 == false) obs2.x += 5;
else if (changeDir2 == true) obs2.x -= 5;
if (obs3.x > width - obs3.w) changeDir3 = true;
else if (obs3.x <= 0) changeDir3 = false;
if (obs3.x >= 0 && changeDir3 == false) obs3.x += 10;
else if (changeDir3 == true) obs3.x-=10;
obs1.render();
obs1.collide();
obs2.render();
obs2.collide();
obs3.render();
obs3.collide();
shooter.render();
shooter.move();
bullet.render();
if (clicked) {
bullet.y -= 10;
bullet.x = shooter.x;
}
if (bullet.y == 0) bullet.y = 450;
target1.render();
target1.collide();
target2.render();
target2.collide();
target3.render();
target3.collide();
target4.render();
target4.collide();
target5.render();
target5.collide();
//push();
if (L3timer <= 20 && L3timer >= 17) text('Hit the targets in the back, not the moving obstacles!', 100, height / 2);
//pop();
if (L3score >= 100 && L3timer == 0) scene = 9;
else if (L3score < 100 && L3timer == 0) scene = 2; // restart
} else if (scene === 9) { // final scene
bgColor = 255;
image(lastbg, 50, 0, width-50, height);
replayBtn.render();
replayBtn.click();
fill(255, 117, 26);
text('CONGRATULATIONS!', 190, 50);
push();
textSize(22);
text("You're a tiger. Try not to become a douchebag, okay?", 90, 80);
pop();
}
}
// LEVEL 1 FUNCTIONS
function gameOver1() {
for (let i = 0; i < 5; i++) {
drops[i].alive = false;
}
gameOn1 = false;
if (counter < minScore) scene = 2; // determines min score to move on
else if (counter >= minScore) scene = 3;
}
function start1() {
L1timer = millis() + interval;
for (let i = 0; i < 5; i++) {
drops[i].alive = true;
}
bucket.alive = true;
//body.alive = true;
//dropper.alive = true;
gameOn1 = true;
counter = 0;
}
class Drop {
constructor(x, y, w, speed) {
this.x = x;
this.y = y;
this.w = w;
this.speed = speed;
this.alive = false;
}
reset() {
if (this.y > height) {
this.x = random(width);
this.y = random(-20, gap);
this.alive = true;
}
}
move() {
if (this.alive) {
this.y += this.speed;
} else {
this.x = random(width);
this.y = random(-20, gap);
}
}
render() {
if (this.alive) {
fill(0)
image(acorn, this.x, this.y, this.w, this.w);
}
}
caught() {
if (this.y >= bucket.y &&
this.x > bucket.x &&
this.x < bucket.x + bucket.w) {
counter++;
this.x = random(width);
this.y = random(-20, gap);
} else if (this.y > dropper.y &&
this.y < dropper.y + dropper.h &&
this.x > dropper.x &&
this.x < dropper.x + dropper.w) {
counter--;
this.x = random(width);
this.y = random(-20, gap);
}
}
}
class Bucket {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.alive = false;
}
render() {
if (this.alive) {
//fill(0);
image(squirrel, this.x - 2.5 * counter, this.y - 5 * counter, this.w + 5 * counter, this.h + 5 * counter);
}
}
move() {
if (keyIsDown(LEFT_ARROW)) {
this.x -= 5;
//body.x -= 5;
}
if (keyIsDown(RIGHT_ARROW)) {
this.x += 5;
//body.x += 5;
}
}
}
class Dropper {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
//this.alive = false;
}
move() {
if (dropper.x > width - dropper.w) changeDirection = true;
else if (dropper.x <= 0) changeDirection = false;
if (dropper.x >= 0 && changeDirection == false) dropper.x++;
else if (changeDirection == true) dropper.x--;
}
render() {
image(owl, this.x, this.y, this.w, this.h);
}
}
class Button {
constructor(x, y, w, h, text, c) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.text = text;
this.c = c;
}
render() {
push();
textAlign(CENTER);
stroke(0);
fill(this.c);
rectMode(CENTER);
rect(this.x, this.y, this.w, this.h);
fill(255);
strokeWeight(2);
text(this.text, this.x, this.y + 10);
pop();
}
click() {
if (
mouseIsPressed &&
mouseX > this.x - this.w / 2 &&
mouseX < this.x + this.w / 2 &&
mouseY > this.y - this.h / 2 &&
mouseY < this.y + this.h / 2) {
start1();
scene = 1;
}
}
}
// LEVEL 2 FUNCTIONS
class Button1 {
constructor(x, y, w, h, text) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.text = text;
}
render() {
push();
textAlign(CENTER);
stroke(0);
fill(255);
rectMode(CENTER);
rect(this.x, this.y, this.w, this.h);
text(this.text, this.x, this.y + 10);
pop();
}
click() {
if (
mouseIsPressed &&
mouseX > this.x - this.w / 2 &&
mouseX < this.x + this.w / 2 &&
mouseY > this.y - this.h / 2 &&
mouseY < this.y + this.h / 2) {
scene += 1;
}
}
}
class mainChar {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
fill(0);
image(squirrel, this.x, this.y, this.w, this.h);
}
move() {
if (keyIsDown(LEFT_ARROW)) this.x -= 5;
if (keyIsDown(RIGHT_ARROW)) this.x += 5;
if (keyIsDown(UP_ARROW)) this.y -= 5;
if (keyIsDown(DOWN_ARROW)) this.y += 5;
}
}
class house {
constructor(x, y, w, h, correct) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.correct = correct;
}
render() {
fill(255, 117, 26);
image(mansion, this.x, this.y, this.w, this.h);
}
}
// Pong functions
function move() {
xBall += xSpeed;
yBall += ySpeed;
}
function bounce() {
if (xBall < 10 ||
xBall > width - 10) {
xSpeed *= -1;
}
if (yBall < 10 ||
yBall > height - 10) {
ySpeed *= -1;
}
}
function display() {
fill(204, 153, 255);
ellipse(xBall, yBall, 20, 20);
}
// Bounce off Paddle
function paddle() {
if ((xBall > mouseX &&
xBall < mouseX + 90) &&
(yBall + 10 >= height - 25)) {
xSpeed *= -1;
ySpeed *= -1;
L2score++;
}
}
// LEVEL 3 FUNCTIONS
function mouseClicked() {
clicked = true;
}
class Obs {
constructor(img, x, y, w, h) {
this.img = img;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
image(this.img, this.x, this.y, this.w, this.h);
}
collide() {
if (bullet.y > this.y && bullet.y < this.y + this.h && bullet.x > this.x && bullet.x < this.x + this.w) L3score -= 10;
}
}
class Shooter {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
image(squirrel, this.x, this.y, this.w, this.h);
}
move() {
if (keyIsDown(LEFT_ARROW)) {
this.x -= 5;
}
if (keyIsDown(RIGHT_ARROW)) {
this.x += 5;
}
}
}
class Bullet {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
image(acorn, this.x, this.y, this.w, this.h);
}
}
class Target {
constructor(img, x, y, w, h) {
this.img = img;
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
image(this.img, this.x, this.y, this.w, this.h);
}
collide() {
if (bullet.y > this.y && bullet.y < this.y + this.h && bullet.x > this.x && bullet.x < this.x + this.w) L3score += 10;
}
}