xxxxxxxxxx
231
let mpFont;
let gameState = 'start';
let goomba = [];
let randI;
let photo;
let p1Click = false;
let p2Click = false;
let p1Tally;
let p2Tally;
let restartCheck = false;
let frameCheck;
function preload() {
mpFont = loadFont('MPFont.ttf');
photo = loadImage("Goomba.png");
foreground = loadImage("Foreground.png")
backdrop = loadImage("Background.png")
}
class Tally {
constructor(){
this.p1Number = 0;
this.p2Number = 0;
}
checkP1Click(){
this.p1Number ++;
}
checkP2Click(){
this.p2Number ++;
}
checkP1Tally(){
print(this.p1Number);
}
checkP2Tally(){
print(this.p2Number);
}
checkP1Result(){
if(this.p1Number === randI){
print("P1 Win!");
}
}
checkP2Result(){
if(this.p2Number === randI){
print("P2 Win!");
}
}
}
class Goomba {
constructor(){
this.xPos = 0;
this.yPos = 492;
this.xSpeed = random(5, 10);
this.ySpeed = 0;
this.check = false;
}
stall(order){
if(frameCount % (20 * (order)) == 0){
this.check = true;
}
}
move(){
if(this.check == true){
this.xPos += this.xSpeed;
this.yPos += this.ySpeed;
}
}
draw(){
image(photo, this.xPos, this.yPos, 60, 70);
}
random(){
if(frameCount % 20 == 0){
this.xSpeed = random(0, 15);
}
}
reset(){
if(this.xPos > 820){
this.check = false;
this.xPos = 0;
this.xSpeed = random(5, 10);
}
}
}
function startScreen(){
let from = color(255, 135, 0);
let to = color(0, 240, 255);
let interA = lerpColor(from, to, 0);
background(interA);
noStroke();
for (let i = 0; i < 664; i = i + 6.64){
fill(lerpColor(from, to, 0 + i * 0.0015))
rect(0, i, 820, 7);
}
fill(200);
strokeWeight(4);
rect(15, 95, 785, 555, 20);
fill('#ED225D');
textFont(mpFont);
textSize(100);
text('Goomba Spotting', 60, 80)
textSize(50);
text('Goombas have invaded NYUAD!', 25, 130);
text('You two have been hired as', 25, 170);
text('Goomba Spotters to assist with', 25, 210);
text('the resistance effort.', 25, 250);
text('Your task: To count the exact', 25, 290);
text('number of Goombas that pass by.', 25, 330);
text('A last-minute refresher!', 25, 370);
text('Goombas look like:', 25, 430);
text('Tap once for each Goomba you see!', 25, 490);
text('Player 1: Tap on the A key!', 25, 530);
text('Player 2: Tap on the L key!', 25, 570);
text('Good luck, Spotters.', 25, 630);
image(photo, 420, 380, 58.8, 70);
strokeWeight(4);
rect(610, 510, 190, 140, 20);
fill(0);
text('START!', 615, 595);
}
function endScreen(){
let from = color(255, 135, 0);
let to = color(0, 240, 255);
let interA = lerpColor(from, to, 0);
background(interA);
noStroke();
for (let i = 0; i < 664; i = i + 6.64){
fill(lerpColor(from, to, 0 + i * 0.0015))
rect(0, i, 820, 7);
}
fill(200);
strokeWeight(4);
rect(15, 95, 785, 555, 20);
fill('#ED225D');
textFont(mpFont);
textSize(100);
text('Results', 250, 80)
textSize(50);
text("Okay, let's see here.", 25, 130);
text('Player 1.', 25, 170);
text('You counted Goombas.', 25, 210);
text('Player 2.', 25, 250);
text('You counted Goombas.', 25, 290);
text('There were N Goombas.', 25, 350);
text('Player, great work!', 25, 410);
text('Player, see me in my office.', 25, 450);
text('PLAYER WINS!', 25, 490);
strokeWeight(4);
rect(610, 510, 190, 140, 20);
fill(0);
textSize(39);
text('RESTART!', 613, 595);
}
function gameScreen(){
image(backdrop, 0, 0, 820, 664);
image(photo, 0, 0, 60, 70);
for (let i = 0; i < randI; i++){
goomba[i].stall(i + 1);
goomba[i].draw();
goomba[i].move();
goomba[i].random();
}
image(foreground, 0, 0, 820, 664);
}
function setup() {
createCanvas(820, 664);
//Generate Multiple Values in Array for Multiple Goombas
for (let i = 0; i < 30; i++){
goomba[i] = new Goomba();
}
p1Tally = new Tally();
p2Tally = new Tally();
}
function draw() {
if (gameState == 'start') {
startScreen();
} else if (gameState == 'playing') {
if (restartCheck == false){
restartCheck = true;
randI = random(15, 30);
randI = Math.round(randI);
print(randI);
frameCheck = frameCount;
print(frameCheck);
}
gameScreen();
} else if (gameState == 'end') {
if (restartCheck == true){
for (let i = 0; i < randI; i++){
goomba[i].reset();
}
restartCheck = false;
p1Tally.checkP1Tally();
p2Tally.checkP2Tally();
p1Tally.checkP1Result();
p2Tally.checkP2Result();
}
endScreen();
}
}
function keyPressed() {
while (gameState == 'playing'){
if (keyCode === LEFT_ARROW) {
p1Tally.checkP1Click();
}
if (keyCode === RIGHT_ARROW) {
p2Tally.checkP2Click();
}
}
}
function mousePressed() {
if (gameState == 'start') {
if (610 < mouseX && mouseX < 800 && 510 < mouseY && mouseY < 650){
gameState = 'playing';
}
} else if (gameState == 'playing'){
if (610 < mouseX && mouseX < 800 && 510 < mouseY && mouseY < 650){
gameState = 'end';
}
} else if (gameState == 'end'){
if (610 < mouseX && mouseX < 800 && 510 < mouseY && mouseY < 650){
gameState = 'start';
}
}
}