xxxxxxxxxx
926
var myFont;
//Game 1
let bully1;
let bully2;
let bully3;
let canMove;
let moveLeft, moveUp;
tableArray = [];
//Game 2
let beararm;
let bullyarm;
var score = 0;
//Game 3
let bullyImg = [];
var scores = 0;
// Game 1 & 2 & 3
let move = 5;
let bearLives = 5;
let sceneNum = 0;
let keyArrow;
// Game 4
var timestamp = 0;
//Hooray!
var confetti = [];
let hoorayIsPlaying = false;
//GameOver
let timer = 5
function preload() {
myFont = loadFont("pixelated letters.ttf");
//images for opening
openImg = loadImage('Pixelated Opening Scene.png');
//image for all game
heartImg = loadImage('heart.png');
//images for game 1
bearFaceImg = loadImage('Bear Face.png');
bully1Img = loadImage('BullyH1.png');
bully2Img = loadImage('BullyH2.png');
bully3Img = loadImage('BullyH3.png');
goalImg = loadImage('goalbench.png');
triImg = loadImage('triangle.png');
//images for game 2
lunchImg = loadImage('Lunch.png');
bearArmImg = loadImage('BearArm.png');
bullyArmImg = loadImage('BullyArm.png');
//images for game 3
bullyImg[0] = loadImage('BullyW0.png');
bullyImg[1] = loadImage('BullyW1.png');
bullyImg[2] = loadImage('BullyW2.png');
bullyLunch = loadImage('Lunch Hand.png');
bearHead = loadImage('BearMouth.png');
bearMunch = loadSound('Bite.mp3');
//horray!
hooray = loadImage('hooray.png');
hooraySound = loadSound('hooray.mp3');
//game over
gameOverImg = loadImage('Game Over.png');
playAgainImg = loadImage('Play Again Button.png');
openMusic = loadSound('Opening Music.mp3');
gameMusic = loadSound('Song2.mp3');
bumpSound = loadSound('bump.mp3');
nextRound = loadSound('nextround.mp3');
slapSound = loadSound('slap.mp3');
}
function setup() {
createCanvas(600, 400);
openMusic.loop();
openMusic.play();
gameMusic.loop();
gameMusic.play();
// for Game 1
let tableGraphic = createGraphics(100, 80);
let table1 = new Table(75, 80, tableGraphic);
let table2 = new Table(425, 80, tableGraphic);
let table3 = new Table(245, 180, tableGraphic);
let table4 = new Table(75, 280, tableGraphic);
let table5 = new Table(425, 280, tableGraphic);
moveLeft = 0;
moveUp = 0;
canMove = true;
tableArray.push(table1, table2, table3, table4, table5);
bully1Speed = 1.5;
bully2Speed = 2.5;
bully3Speed = 1;
bear1 = new Bear(280, 320);
bully1 = new Bully(5, 175);
bully2 = new Bully(250, 10);
bully3 = new Bully(550, 175);
// for Game 2
beararm = new BearArm(200, 240);
bullyarm = new BullyArm(300, -300);
lunch = new Lunch(100, 245);
openImg.resize(350, 200);
heartImg.resize(20, 20);
bearFaceImg.resize(40, 40);
bully1Img.resize(85, 85);
bully2Img.resize(85, 85);
bully3Img.resize(85, 85);
goalImg.resize(105, 20);
triImg.resize(50, 20);
lunchImg.resize(400, 165);
bearArmImg.resize(100, 200);
bullyArmImg.resize(100, 300);
gameOverImg.resize(300, 200);
playAgainImg.resize(100, 40);
//Game 3
bearHeadSpeed = 1.5;
bullywords1 = new BullyWords(0, random(140, 145));
bullywords2 = new BullyWords(150, random(175, 180));
bullywords3 = new BullyWords(200, random(200, 205));
bullywords4 = new BullyWords(250, random(250, 255));
bullywords5 = new BullyWords(300, random(225, 275));
bullywords6 = new BullyWords(350, random(280, 300));
bearhands = new BearHands(300, height - 50);
bearhead = new BearHead(150,0);
bullyImg[0].resize(110, 40);
bullyImg[1].resize(110, 40);
bullyImg[2].resize(110, 40);
bullyLunch.resize(250, 400);
bearHead.resize(350, 140);
// hooray!
hooray.resize(100, 200);
for (var i = 0; i<43; i++){
confetti.push(new Confetti());
}
}
function draw() {
background(255);
switch (sceneNum) {
case 0:
scene0();
console.log('scene 0');
if (sceneNum === 0) {
frameRate(2);
openMusic.setVolume(1);
gameMusic.setVolume(0);
}
break;
// case 1:
// scene1();
// console.log('scene 1');
// break;
case 1:
scene2();
console.log('scene 2');
if (sceneNum === 1) {
frameRate(60);
gameMusic.setVolume(1);
openMusic.setVolume(0);
}
break;
case 2:
scene3();
console.log('scene 3');
if (sceneNum === 2){
frameRate(60);
}
break;
case 3:
scene4();
console.log('scene 4');
if (sceneNum === 3){
frameRate(60);
}
break;
case 4:
hooray1();
console.log('finished game');
if (sceneNum === 4){
frameRate(60);
}
break;
case 5:
gameOver();
if (sceneNum === 5) {
frameRate(2);
gameMusic.setVolume(0);
openMusic.setVolume(1);
console.log('scene 5');
}
break;
}
}
// for opening scene
function mousePressed() {
if (sceneNum == 0 && mouseX > 150 && mouseX < 450 && mouseY > 300 && mouseY < 390) {
sceneNum = 1;
}
}
// for game life
function currentBearLives() {
fill(255, 165, 0);
for (let i = 0; i < bearLives; i++) {
image(heartImg, i * 20 + 10, 10);
}
}
function reset(){
push();
fill(145, 182, 243);
textAlign(CENTER, CENTER);
textSize(30);
text(timer, width/2, height-40);
pop();
if (sceneNum === 5){
} if (frameCount % 2 == 0 && timer > 0) {
timer --;
} if (timer == 0) {
bearLives = 5;
sceneNum = 0;
textSize(12);
bear1.x = 280;
bear1.y = 320;
}
}
//classes for game 1
class Table {
constructor(x, y, table) {
this.x = x;
this.y = y;
this.table = createGraphics(100, 80);
}
display() {
// benches upper
this.table.fill(90);
this.table.strokeWeight(3);
this.table.rect(0, 0, 100, 15);
// tables
this.table.fill(90);
this.table.strokeWeight(3);
this.table.rect(0, 20, 100, 40);
// benches lower
this.table.fill(90);
this.table.strokeWeight(3);
this.table.rect(0, 65, 100, 15);
image(this.table, this.x, this.y);
}
}
class Bear {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = 40;
this.h = 40;
this.c = color(165, 83, 42)
}
body() {
fill(this.c);
image(bearFaceImg, this.x, this.y);
// ellipse(this.x, this.y, this.w, this.h);
}
move() {
if (keyIsDown(38)) {
this.y--;
keyArrow = "up";
}
//down
if (keyIsDown(40)) {
this.y++;
keyArrow = "down";
}
//right
if (keyIsDown(39)) {
this.x++;
keyArrow = "right";
}
//left
if (keyIsDown(37)) {
this.x--;
keyArrow = "left";
}
}
collide(x, y) {
for (let i = 1; i < 5; i++) {
if (this.x + this.w > x && this.x < x + 100 && this.y + this.h > y && this.y < y + 80) {
return true;
}
}
}
home() {
if (bear1.x + bear1.w > 75 && bear1.x < 175 && bear1.y + bear1.h >= 80 && bear1.y + bear1.h <= 85) {
nextRound.play();
sceneNum++;
}
}
}
class Bully {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = 85;
this.h = 85;
}
bully1body() {
fill(0);
image(bully1Img, this.x, this.y);
}
bully2body() {
fill(0);
image(bully2Img, this.x, this.y);
}
bully3body() {
fill(0);
image(bully3Img, this.x, this.y);
}
bully1move() {
this.x += bully1Speed;
if (this.x >= 160 || this.x <= 0) {
bully1Speed = -bully1Speed;
}
}
bully2move() {
this.x += bully2Speed;
if (this.x >= 350 || this.x <= 175) {
bully2Speed = -bully2Speed;
}
}
bully3move() {
this.x += bully3Speed;
if (this.x >= 551 || this.x <= 350) {
bully3Speed = -bully3Speed;
}
}
checkCollision() {
if (bear1.x + bear1.w > this.x && bear1.x < this.x + this.w && bear1.y + bear1.h > this.y && bear1.y < this.y + this.h) {
console.log('bumped');
bumpSound.play();
bear1.x = 280;
bear1.y = height - 80; //reset
bearLives--;
}
}
}
// classes for game 2
class Lunch {
constructor(x, y) {
this.x = x;
this.y = y;
this.w = 400;
this.h = 150;
this.r = 20;
}
display() {
push();
strokeWeight(5);
fill(255);
stroke(179, 0, 0);
image(lunchImg, this.x, this.y);
// rect(this.x, this.y, this.w, this.h, this.r);
pop();
}
collide() {
if (bullyarm.x + bullyarm.w > this.x && bullyarm.x < this.x + this.w && bullyarm.y + bullyarm.h > this.y) {
bullyarm.xspeed *= -1;
bullyarm.yspeed *= -1;
bumpSound.play();
bearLives--;
}
}
}
class BullyArm {
constructor(x, y) {
this.x = x;
this.y = y;
this.w = 60;
this.h = 300;
this.xspeed = 4;
this.yspeed = 2;
}
move() {
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
}
create() {
fill(0);
image(bullyArmImg, this.x, this.y);
// rect(this.x, this.y, this.w, this.h, 20);
}
wall() {
if (this.x < 0 || this.x > 590) {
this.xspeed *= -1;
}
if (this.y < -300 || this.y > -40) {
this.yspeed *= -1;
}
}
collide() {
if (this.x + this.w > beararm.x && this.x < beararm.x + 80 && this.y + 300 >= beararm.y) {
this.xspeed *= -1;
this.yspeed *= -1;
slapSound.play();
score++;
}
}
nextScene() {
if (score === 5) {
nextRound.play();
sceneNum = 3;
}
}
}
class BearArm {
constructor(x, y) {
this.x = x;
this.y = y;
// this.w = 75;
// this.h = 400;
this.r = 20;
this.xspeed = 3;
this.minusxspeed = -3;
}
move() {
if (keyIsDown(39)) {
this.x = this.x + this.xspeed;
keyArrow = "right";
}
if (keyIsDown(37)) {
this.x = this.x + this.minusxspeed;
keyArrow = "left";
}
}
create() {
// rect(5, this.y, 5, 80);
fill(0);
image(bearArmImg, this.x, this.y);
// rect(this.x, this.y, this.w, this.h, this.r);
}
walls() {
if (beararm.x < 0) {
beararm.x = beararm.x + move;
}
if (beararm.x + beararm.w > width) {
beararm.x = beararm.x - move;
}
if (beararm.y < 0) {
beararm.y = beararm.y + move;
}
if (beararm.y > height) {
beararm.y = beararm.y - move;
}
}
}
//classes for game 3
class BearHead{
constructor(x,y){
this.x = x;
this.y = y;
this.c = color(165, 83, 42)
this.w = 350;
this.h = 140;
this.r = 20;
}
display(){
push();
fill(165, 83, 42);
image(bearHead, this.x, this.y);
pop();
}
move(){
this.x += bearHeadSpeed;
if (this.x + this.w >= 600 || this.x <= 0) {
bearHeadSpeed = -bearHeadSpeed;
}
}
}
class BearHands {
constructor(x, y) {
this.x = x;
this.y = y;
this.c = color(165, 83, 42)
this.w = 250;
this.h = 400;
}
body() {
fill(this.c);
image(bullyLunch, this.x, this.y);
}
move() {
if (keyIsDown(38)) {
this.y--;
keyArrow = "up";
}
//down
if (keyIsDown(40)) {
this.y++;
keyArrow = "down";
}
//right
if (keyIsDown(39)) {
this.x++;
keyArrow = "right";
}
//left
if (keyIsDown(37)) {
this.x--;
keyArrow = "left";
}
}
mouth(){
if (this.x > bearhead.x + 50 && this.x + 50 < bearhead.x + bearhead.w - 50 && this.y > bearhead.y + 10 && this.y < bearhead.y + bearhead.h - 10){
this.x = width / 2;
this.y = height - 50;
bearMunch.play();
scores++;
}
}
nextScene() {
if (scores === 5) {
nextRound.play();
sceneNum++;
hooraySound.play();
}
}
}
class BullyWords {
constructor(x, y, w, h) {
this.x = x;
this.y = y;
this.w = 150;
this.h = 40;
this.img = random(bullyImg);
}
display() {
fill(255);
image(this.img, this.x, this.y);
// rect(this.x, this.y, this.w, this.h);
}
move() {
this.x++;
if (this.x >= width) {
this.x = -10
}
}
checkCollision() {
if (this.x + this.w > bearhands.x && this.x < bearhands.x + 50 && this.y + this.h > bearhands.y && this.y < bearhands.y) {
console.log('bumped');
bearhands.x = width / 2;
bearhands.y = height - 50; //reset
bumpSound.play();
bearLives--;
}
}
}
// hooray!
class Confetti{
constructor() {
this.x = random(width);
this.y = random(height);
this.w = 20;
this.h = 10;
this.xspeed = random(1,2);
this.yspeed = random(1,2);
}
display() {
var color1 = random(209);
var color2 = random(255);
var color3 = random(255);
noStroke();
fill(color1,color2,color3)
ellipse(this.x, this.y, this.w, this.h);
}
move() {
this.x += this.xspeed;
this.y += this.yspeed;
}
bounce() {
if (this.x > width - this.w || this.x < this.w) {
this.xspeed = -this.xspeed;
}
}
}
// function scene1() {
// background(220);
// //bullies
// rect(100, 100, 100, 200);
// rect(250, 100, 100, 200);
// rect(400, 100, 100, 200);
// //character
// ellipse(300, 400, 300, 200);
// }
function scene0() {
background(255, 238, 186);
push();
textFont(myFont);
textSize(random(43, 44));
fill(255);
textAlign(CENTER);
text("LET ME EAT MY LUNCH", width / 2, 100);
textSize(random(42, 43));
fill(0);
text("LET ME EAT MY LUNCH", width / 2, 100);
textSize(random(20, 22));
fill(0);
text("Click me to play", width / 2, 370);
imageMode(CENTER);
image(openImg, width / 2, random(224, 225));
pop();
}
function scene2() {
background(255, 238, 186);
if (keyIsPressed === false) {
push();
fill(0);
textFont(myFont);
textSize(12);
textAlign(CENTER);
text("Move the arrow keys to find your seat ", 300, height - 20);
text("without running into the bullies!", 300, height - 5);
pop();
}
for (let i = 0; i < tableArray.length; i++) {
tableArray[i].display();
}
for (let i = 0; i < tableArray.length; i++) {
if (bear1.collide(tableArray[i].x, tableArray[i].y) === true) {
if (keyArrow === "left") {
bear1.x = bear1.x + 5;
} else if (keyArrow === "right") {
bear1.x = bear1.x - 5;
}
if (keyArrow === "up") {
bear1.y = bear1.y + 5;
}
if (keyArrow === "down") {
bear1.y = bear1.y - 5;
}
}
}
//window boundries
if (bear1.x < 0) {
bear1.x = bear1.x + move;
}
if (bear1.x + bear1.w > width) {
bear1.x = bear1.x - move;
}
if (bear1.y < 0) {
bear1.y = bear1.y + move;
}
if (bear1.y + bear1.h > height + 5) {
bear1.y = bear1.y - move;
}
// target bench
push();
fill(255, 255, random(0, 200));
noStroke();
image(goalImg, 73, 75);
rect(76, 78, 100, 14);
triangle(103, 58, 147, 58, 125, 73);
image(triImg, 100, 55);
pop();
fill(0);
textFont(myFont);
textStyle(BOLD);
text('Sit here!', 100, 50)
//bear
bear1.body();
bear1.move();
bear1.home();
//bullies
bully1.bully1body();
bully2.bully2body();
bully3.bully3body();
bully1.bully1move();
bully2.bully2move();
bully3.bully3move();
bully1.checkCollision();
bully2.checkCollision();
bully3.checkCollision();
currentBearLives();
if (bearLives === 0) {
sceneNum = 5;
}
}
function scene3() {
background(255, 238, 186);
if (keyIsPressed === false) {
push();
fill(0);
textFont(myFont);
textSize(14);
textAlign(CENTER);
text("Move the arrow keys to protect your lunch!", 300, 200);
text("Swat the bully's hand 5 times to move on to the final game!", 300, 215);
pop();
}
lunch.display();
bullyarm.wall();
bullyarm.move();
bullyarm.create();
beararm.move();
beararm.walls();
beararm.create();
fill(0);
textSize(24);
text("Score: " + score, 10, 50);
bullyarm.nextScene();
currentBearLives();
lunch.collide();
var hit = bullyarm.collide();
if (hit) {
bullyarm.xspeed = 3;
}
if (bearLives === 0) {
sceneNum = 5;
}
}
function scene4() {
background(255, 238, 186);
if (keyIsPressed === false) {
push();
fill(0);
textFont(myFont);
textSize(12);
textAlign(CENTER);
text("Move the arrow keys to eat your lunch!", 150, height - 20);
text("Eat 5 eggs without running into the words!", 150, height - 5);
pop();
}
bearhead.display();
bearhead.move();
bearhands.body();
bearhands.move();
bearhands.mouth();
bearhands.nextScene();
fill(0);
textSize(24);
text("Score: " + scores, 10, 50);
bullywords1.display();
bullywords1.move();
bullywords2.display();
bullywords2.move();
bullywords3.display();
bullywords3.move();
bullywords4.display();
bullywords4.move();
bullywords5.display();
bullywords5.move();
bullywords6.display();
bullywords6.move();
bullywords1.checkCollision();
bullywords2.checkCollision();
bullywords3.checkCollision();
bullywords4.checkCollision();
bullywords5.checkCollision();
bullywords6.checkCollision();
//window boundries
if (bearhands.x < 0) {
bearhands.x = bearhands.x + move;
}
if (bearhands.x + 50 > width) {
bearhands.x = bearhands.x - move;
}
if (bearhands.y < 0) {
bearhands.y = bearhands.y + move;
}
if (bearhands.y > height) {
bearhands.y = bearhands.y - move;
}
currentBearLives();
if (bearLives === 0) {
sceneNum = 5;
}
}
function gameOver() {
background(255, 238, 186);
image(gameOverImg, 150, random(79, 80));
image(playAgainImg, 250, random(299, 300));
reset();
}
function hooray1(){
background(255, 238, 186);
for (var i = 0; i< confetti.length; i++){
confetti[i].display();
confetti[i].move();
confetti[i].bounce();
}
push();
image(hooray, 250, 100);
fill(0);
textAlign(CENTER, CENTER);
textSize(12);
text('Hooray! You made it through lunch!', 300, 50);
text('Get ready for tomorrow!', 300, 350);
pop();
}