xxxxxxxxxx
114
let goomba = [];
let randI;
let photo;
let p1Click = false;
let p2Click = false;
let p1Tally;
let p2Tally;
function preload() {
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(){
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);
}
}
}
function setup() {
createCanvas(820, 664);
background(220);
randI = random(15, 30);
randI = Math.round(randI);
print(randI);
//Generate Multiple Values in Array for Multiple Goombas
for (let i = 0; i < randI; i++){
goomba[i] = new Goomba();
}
p1Tally = new Tally();
p2Tally = new Tally();
}
function draw() {
//background(220);
image(backdrop, 0, 0, 820, 664);
image(photo, 0, 0, 60, 70);
for (let i = 0; i < randI; i++){
if(frameCount % (20 * (i + 1)) == 0){
goomba[i].stall();
}
goomba[i].draw();
goomba[i].move();
goomba[i].random();
}
image(foreground, 0, 0, 820, 664);
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
p1Tally.checkP1Click();
}
if (keyCode === RIGHT_ARROW) {
p2Tally.checkP2Click();
}
}
function mousePressed(){
p1Tally.checkP1Tally();
p2Tally.checkP2Tally();
p1Tally.checkP1Result();
p2Tally.checkP2Result();
}