xxxxxxxxxx
761
// Bitmap Game Level 1 Greybox
let drops = [];
let minScore = 2;
var bucket, dropper;
var dropSpeed = 4;
var gap = -2000;
var dropSize = 10;
var bucketSpeed = 3;
var counter = 0;
var highscore = 0;
var interval = 20000;
var L1timer;
var countdown;
var gameOn1 = false;
//var gameOn2 = false;
var gameEnd = false;
var scene = 9; // 0=opening; 1=game play; 2=game over/restart screen; 3=level passed
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 = (2, 7);
var ySpeed = (-7, -2);
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;
function preload() {
cottage = loadImage('judgy_wypipo.jpg');
ti = loadImage('coolppl.jpg');
terrace = loadImage('potheads.jpg');
cap = loadImage('Unfriend.png')
colonial = loadImage('nerds.jpg')
}
function setup() {
createCanvas(700, 500);
changeDirection = false;
// LEVEL 1 ASSETS
bucket = new Bucket(width / 2, height - 100, 40, 40);
body = new Body(bucket.x-10, bucket.y+bucket.h, 60, 80)
dropper = new Dropper(100, 150, 80, 100);
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, 40, 40);
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(width / 2 - 20, height / 2 + 80, 50, 60);
obs2 = new Obs(0, height / 2, 50, 60);
obs3 = new Obs(500, height / 2 - 80, 50, 60);
shooter = new Shooter(width / 2 - 25, height, width / 2 + 25, height, width / 2, height - 50);
bullet = new Bullet(shooter.cx, 450, 3, 15);
for (var i = 0; i < 5; i++) {
targets[i] = new Target(i * 150, 0, 100, 100);
}
replayBtn = new Button(width / 2, 450, 200, 50, "PLAY AGAIN", 255);
}
function draw() {
background(bgColor);
textSize(32);
// if (timer < millis()) {
// timer = millis() + interval;
// }
// if (gameOn1 && scene == 1) {
// countdown = ceil((timer - millis()) / 1000) - 1;
// }
// if (countdown == 0) {
// gameOver1();
// }
// SCENE CHANGES
switch (scene) {
case 1:
//scene1();
break;
case 2:
//scene2();
break;
case 3:
//scene3();
break;
//default:
//
}
if (scene === 0) { // START SCREEN
bgColor = color(255, 117, 26);
//fill(255);
startBtn.render();
startBtn.click();
}
else if (scene === 1) { // LEVEL 1
bgColor = 255;
fill(0);
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();
body.render();
body.move();
// Prof movement
dropper.move();
dropper.render();
if (countdown <= 17 && countdown >= 16) {
fill(255, 117, 26);
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);
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);
nextBtn.render();
nextBtn.click();
}
else if (scene === 4) { // LEVEL 2
bgColor = 255;
fill(0);
main.render();
main.move();
house1.render();
house2.render();
house3.render();
house4.render();
house5.render();
house6.render();
// 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.", 65, 85);
text("Quick! Play a drunken game of pong--", 80, 165);
text("Before you lose your cool factor!", 100, 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.", 300, 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
bgColor = 255;
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.cx;
}
if (bullet.y == 0) bullet.y = 450;
for (var i = 0; i < 5; i++) {
targets[i].render();
targets[i].collide();
}
push();
fill(255, 117, 26);
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 = color(255, 117, 26);
replayBtn.render();
replayBtn.click();
}
}
// 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)
ellipse(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);
rect(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 Body {
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);
rect(this.x, this.y, this.w, this.h);
}
}
move() {
if (keyIsDown(LEFT_ARROW)) {
this.x -= 5;
} if (keyIsDown(RIGHT_ARROW)) {
this.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() {
//if (this.alive) {
fill('red');
rect(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) {
// switch to next level here
//start2();
scene += 1;
}
}
}
// function start2() {
// gameOn1 = true;
// }
class mainChar {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
fill(0);
rect(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, 0, 0);
rect(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(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
fill('red');
rect(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(ax, ay, bx, by, cx, cy) {
this.ax = ax;
this.ay = ay;
this.bx = bx;
this.by = by;
this.cx = cx;
this.cy = cy;
}
render() {
triangle(this.ax, this.ay, this.bx, this.by, this.cx, this.cy);
}
move() {
if (keyIsDown(LEFT_ARROW)) {
this.ax -= 5;
this.bx -= 5;
this.cx -= 5;
}
if (keyIsDown(RIGHT_ARROW)) {
this.ax += 5;
this.bx += 5;
this.cx += 5;
}
}
// shoot() {
// if (mouseIsPressed) {
// rect(this.cx-1.5, shootY, 3, 15);
// shootY--;
// }
// }
}
class Bullet {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
rect(this.x, this.y, this.w, this.h);
}
}
class Target {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
render() {
rect(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+=2;
}
}