xxxxxxxxxx
93
let goo = [];
let randI;
let photo;
let p1Click = false;
let p2Click = false;
let p1Tally;
let p2Tally;
function preload() {
photo = loadImage("Goomba.png");
}
class Tally {
constructor(){
this.p1Number = 0;
this.p2Number = 0;
}
checkP1Click(){
if (p1Click == true){
this.p1Number ++;
}
}
checkP2Click(){
if (p2Click == true){
this.p2Number ++;
}
}
p1Results(){
print(this.p1Number)
}
p2Results(){
print(this.p2Number)
}
}
class Goo {
constructor(){
this.xPos = 0;
this.yPos = 400;
this.xSpeed = random(0, 10);
this.ySpeed = 0;
}
move(){
this.xPos += this.xSpeed;
this.yPos += this.ySpeed;
}
draw(){
//rect(this.xPos, this.yPos, 20, 40);
image(photo, this.xPos, this.yPos, 60, 70);
}
}
function setup() {
createCanvas(800, 616);
randI = random(10, 20);
randI = Math.round(randI);
print(randI);
//Generate Multiple Values in Array for Multiple Fish
for (let i = 0; i < randI; i++){
goo[i] = new Goo();
}
p1Tally = new Tally();
p2Tally = new Tally();
}
function draw() {
background(220);
image(photo, 0, 0, 60, 70);
for (let i = 0; i < randI; i++){
goo[i].move();
goo[i].draw();
}
p1Tally.checkP1Click();
p2Tally.checkP2Click();
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
p1Click = true;
} else {
p1Click = false;
}
if (keyCode === RIGHT_ARROW) {
p2Click = true;
} else {
p2Click = false;
}
}
function mousePressed(){
p1Tally.p1Results();
p2Tally.p2Results();
}