xxxxxxxxxx
262
var main;
var showImg1 = false;
var showImg2 = false;
var showImg3 = false;
var showImg4 = false;
var showImg5 = false;
var scene = 4;
var bgColor = 255;
// Random Ball Placement
var xBall = Math.floor(Math.random() * 300) + 50;
var yBall = 50;
var xSpeed = (2, 7);
var ySpeed = (-7, -2);
var score = 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);
// LEVEL 2 ASSETS
main = new mainChar(0, height/2, 40, 40);
nextBtn = new Button1(width / 2, height / 2, 200, 50, "YES");
nextBtn1 = new Button1(width / 2, height / 2, 200, 50, "FINE");
// for loop for houses, if i = random, check index, pass true
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);
//correctHouse = random(houses);
}
function draw() {
background(bgColor);
textSize(32);
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();
if (main.x == 0 && main.y == height/2) {
fill(255, 117, 26);
textSize(28);
text('Check out each eating club! Find out where you belong.', 6, height/2-30);
}
// 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;
}
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) {
bgColor = 0;
// Paddle
fill('white');
rect(mouseX, height-25, 90, 15);
//Functions
move();
display();
bounce();
paddle();
//Score
fill(204, 153, 255);
textSize(24);
text("Score: " + score, 10, 25);
if (score >= 8) scene = 7;
}
}
// LEVEL 2 FUNCTIONS/CLASSES
class mainChar {
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;
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.alive = false;
this.correct = correct;
}
render() {
//if (this.alive) {
fill(255, 0, 0);
rect(this.x, this.y, this.w, this.h);
//}
}
}
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;
}
}
}
// 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;
score++;
}
}