xxxxxxxxxx
var circleX = 25
var circleY = 25
var x = 25
var y = 25
var grassList = []
var grassCount = 0
var timer
var gameOver = false
var playerWin = false
function setup() {
createCanvas(400, 400);
rectMode(CENTER)
timer = setTimeout(checkIfWinOrLose, 25000);
for(var i = 0; i < 64; i++){
for(x = 25; x < 400; x+= 50){
for(y = 25; y < 400; y+= 50){
grassList.push(new Grass(x,y))
}
}
}
}
function draw() {
background(71,37,18);
for(var i = 0; i < 4096; i++){
grassList[i].display()
grassList[i].mow()
}
fill(0)
ellipse(circleX,circleY,50)
if (gameOver){
if(playerWin){
youWin()
}
else
{
youLose()
}
}
}
function youWin(){
background(255)
fill(0)
textAlign(CENTER)
text("YOU WIN!", height/2, width/2)
}
function youLose(){
background(0)
fill(255)
textAlign(CENTER)
text("YOU LOSE :(", height/2, width/2)
}
function checkIfWinOrLose() {
gameOver = true
if (grassCount >= 4096) {
playerWin = true
}
else {
playerWin = false
}
}
function endScreen() {
if (grassCount > 4096) {
youWin()
}
else {
youLose()
}
}
function keyPressed() {
if (keyCode == LEFT_ARROW) {
circleX -= 25;
}
if (keyCode == RIGHT_ARROW) {
circleX += 25;
}
if (keyCode == DOWN_ARROW) {
circleY += 25;
}
if (keyCode == UP_ARROW) {
circleY -= 25;
}
if (circleX < 0){
circleX = 375
}
if (circleX > 400){
circleX = 25
}
if (circleY < 0){
circleY = 375
}
if (circleY > 400){
circleY = 25
}
}
class Grass {
constructor(x,y) {
this.x = x;
this.y = y;
this.s = 50;
this.c = color(0, 200,0);
}
display(){
fill(this.c);
noStroke();
rect(this.x, this.y, this.s);
}
mow(){
if (dist(circleX,circleY,this.x,this.y) <= 25)
{
this.x = -1000000
grassCount++
}
}
}