Current File : /home/jeshor13/11bsouth.com/EvilPeep0.5/sketch.js
/* What I'm tring to do is make it so that peeps shoot out of the coursor at an increasing 
rate and walk around, if you place one ontop of another they attack your cursor and you lose. */

var gameMode = 1;
var screenSizeX = 2208 / 2;
var screenSizeY = 1242 / 2;
var score = 0;
var peeps = [];
var circles = [];
var gameClock = 0;
var gameClock0 = 0;
var peepCount = 0;
var colors = [255, 125, 100, 175, 225];
var faceColor = 0; // zero or one = white or black
var areYouOnTopOfMe = false;
var peepLocX;
var peepLocY;
var onOff = 0;
var randomGauss1;
var constrainedRand1;
var constrainedRand2;
var endTimes = 0;
var endTimes0 = 0;

function setup() {
  createCanvas(screenSizeX, screenSizeY); // Half of my phones screen resoulution
  windowWidth = screenSizeX;
  windowHeight = screenSizeY;

}

function draw() {
  if (gameMode == 1) {
    startScreen();
    if (mouseIsPressed) {
      background(50, 50, 50, 1000);
      startTime = millis();
      gameMode = 2;
      areYouOnTopOfMe = false;

    }
  }
  if (gameMode == 2) {
    gameScreen(); // sets the background and visuals of play screen
    gameMetrics(2) // score, peep frequency, next peep light, etc. are controlled here. 
    for (var i = 0; i < peeps.length; i++) {
      peeps[i].display();
      peeps[i].mouseDetect();
    }
    if (areYouOnTopOfMe === true) {
      endTimes = millis();
      gameMode = 3
    }
  }
  if (gameMode == 3) {
    endScreen()
    for (var j = 0; j <= circles.length; j++) {
      circles[j].move();
      circles[j].display();
      circles[j].bounce();
    }

  }
}

function startScreen() {
  fill(10)
  rect(0, 0, screenSizeX, screenSizeY);
  fill(200, 50, 50);
  rect(10, 10, (screenSizeX) - 20, 50);
  fill("white");
  text("Evil Peeps need their space", 20, 25);
  text("see how long you can avoid an overlap", 20, 40);
  text("Click To Start", 100, 100);
}

function endScreen() {
  fill(50, 50, 200);
  rect(10, 10, (screenSizeX) - 20, 50);
  fill("white");
  text("Game", 20, 25);
  text("Over", 20, 40);
  text("Score:" + score, 20, 55);
  if (endTimes - endTimes0 > 1) {
    circles.push(new Ball());
    endTimes = endTimes0;
  }
}

function gameScreen() {
  fill(200, 50, 50);
  rect(10, 10, screenSizeX - 20, 50);
  fill("white");
  text("Evil Peeps need their space", 20, 25);
  text("see how long you can avoid an overlap", 20, 40);
  text("Score:" + score, 20, 55);
}

function gameMetrics(difficulty) {
  gameClock = ((millis() - startTime) / 1000); //Time since game start in seconds 
  score = ceil(gameClock);
  if (gameClock - gameClock0 > 1 / log(gameClock + (difficulty))) {
    peepLocX = mouseX;
    peepLocY = mouseY;
    randomGauss1 = ceil(randomGaussian(2, 1));
    randomGauss2 = ceil(randomGaussian(2, 1));
    constrainedRand1 = constrain(randomGauss1, 0, 4);
    constrainedRand2 = constrain(randomGauss2, 0, 4);
    peeps.push(new Peep(peepLocX, peepLocY, colors[constrainedRand1], constrainedRand2))
    gameClock0 = gameClock;
  }
}

function Peep(x, y, color, type) {
  this.x = x;
  this.y = y;
  this.color = color;
  this.onOff = onOff;
  if (type === 0 && constrainedRand1 == constrainedRand2) {
    type = 5;
  }
  this.display = function() {
    if (type == 5) {
      fill(this.color, this.color - 100, this.color + 50);
      noStroke();
      arc(this.x, this.y, 65, 100, PI, 0); //REAlly Big Blue 
      onOff = !onOff;
      fill(this.onOff * 1000);
      ellipse(this.x, this.y - 55, 15, 15);
      fill("red")
      noStroke();
      ellipse(this.x - 3.5, this.y - 55, 7, 8);
      ellipse(this.x + 3.5, this.y - 55, 7, 8);
    }
    if (type === 0 && constrainedRand1 != constrainedRand2) {
      fill(this.color, this.color - 100, this.color + 50);
      noStroke();
      arc(this.x, this.y, 25, 40, PI, 0); //Big Blue 
      onOff = !onOff;
      fill(this.onOff * 1000);
      ellipse(this.x, this.y - 24, 9, 9);
      fill("red")
      noStroke();
      ellipse(this.x - 2, this.y - 25, 4, 4);
      ellipse(this.x + 2, this.y - 25, 4, 4);
    }
    if (type == 1) {
      fill(this.color + 50, this.color - 100, this.color - 100);
      noStroke();
      arc(this.x, this.y, 10, 30, PI, 0); //Skinny red
      onOff = !onOff;
      fill(this.onOff * 1000);
      ellipse(this.x, this.y - 17, 7, 7);
      fill("red");
      noStroke();
      ellipse(this.x - 1.5, this.y - 18, 3, 3);
      ellipse(this.x + 1.5, this.y - 18, 3, 3);

    }
    if (type == 2) {
      /*if (type == 2 && constrainedRand1 == constrainedRand2) {
        this.x = lerp(x, this.x + random(50, screenSizeX));
        this.y = lerp(y, this.y + random(50, screenSizeY));
      }*/
      fill(this.color + 50, this.color - 100, this.color - 100);
      noStroke();
      arc(this.x, this.y, 18, 30, PI, 0); //Normal red
      onOff = !onOff;
      fill(this.onOff * 1000);
      ellipse(this.x, this.y - 17, 7, 7);
      fill("red");
      noStroke();
      ellipse(this.x - 1.5, this.y - 18, 3, 3);
      ellipse(this.x + 1.5, this.y - 18, 3, 3);

    }
    if (type == 3) {
      fill(this.color, this.color - 100, this.color - 100);
      noStroke();
      arc(this.x, this.y, 15, 20, PI, 0); //short Red
      onOff = !onOff;
      fill(this.onOff * 1000);
      ellipse(this.x, this.y - 13, 7, 7);
      fill("red");
      noStroke();
      ellipse(this.x - 1.5, this.y - 14, 3, 3);
      ellipse(this.x + 1.5, this.y - 14, 3, 3);

    }
    if (type == 4) {
      fill(this.color - 100, this.color + 50, this.color - 100);
      noStroke();
      arc(this.x, this.y, 16, 45, PI, 0); //tall green
      onOff = !onOff;
      fill(this.onOff * 1000);
      ellipse(this.x, this.y - 25, 7, 9);
      fill("red");
      noStroke();
      ellipse(this.x - 1.5, this.y - 26, 3, 3);
      ellipse(this.x + 1.5, this.y - 26, 3, 3);

    }
    this.mouseDetect = function() {
      for (var i = 0; i < peeps.length; i++) {
        if (abs(peeps[i].x - this.x) < 10 && abs(peeps[i].y - this.y) < 10 && peeps[i] != this) {
          areYouOnTopOfMe = true;
        }
      }
    }
  }
}

function Ball() {
  this.xpos = random(width);
  this.ypos = random(height);
  this.xdir = random(-5, 5);
  this.ydir = random(-5, 5);

  this.display = function() {
    noStroke();
    ellipse(this.xpos, this.ypos, 20, 20);
  };

  this.move = function() {
    this.xpos = this.xpos + this.xdir;
    this.ypos = this.ypos + this.ydir;

  };

  this.bounce = function() {
    if (this.xpos >= width || this.xpos <= 0) {
      this.xdir = this.xdir * -1;
    }
    if (this.ypos >= height || this.ypos <= 0) {
      this.ydir = this.ydir * -1;
    }
  };
}