Index / 2017 / Cookie Clicker
640×480 · p5.js instance mode
Cookie_Clicker.pde 192 lines
/*

 Personal Project 01
 
 -=-=- Cookie Clicker -=-=-
 
 03/01/2017
 
 */

PImage cookie;
float cookies, cx, cy, cw, ch;
color brown, chocolate, backdrop;
float[] cost = new float[8];

void setup() {
  fullScreen();
  smooth(8);
  frameRate(30);

  brown = #EA8F49;
  chocolate = #;
  backdrop = #;

  background(backdrop);

  cx = width/2-250;
  cy = height/2-250;
  cw = ch = 500;

  cookieDraw(width/2, height/2, 400);
  cookie = get(int(cx), int(cy), int(cw), int(ch));
  cookies = 0;
  
  for (int i = 0; i < 8; i++) {
    cost[i] = 20 * pow(4,i);
  }
  
  amount[0] = 0.01;
  amount[1] = 0.2;
  amount[2] = 0.6;
  amount[3] = 1.2;
  amount[4] = 2.5;
  amount[5] = 6.0;
  amount[6] = 15.0;
  amount[7] = 25.0;
  
}

void draw() {
  background(backdrop);
  title();
  image(cookie, cx, cy, cw, ch);
  displayCookies(width/2, height/5*4);
  cookieButton(width/2, height/2, 400);
  
  upgradeButton("Autoclick (+0.01)\ncosts: ", width/6, height/8*3, 400, 100, 0);
  upgradeButton("Grandma (+0.2)\ncosts: ", width/6, height/8*4, 400, 100, 1);
  upgradeButton("Home Kitchen (+0.6)\ncosts: ", width/6, height/8*5, 400, 100, 2);
  upgradeButton("Bakery (+1.2)\ncosts: ", width/6, height/8*6, 400, 100, 3);
  upgradeButton("Cookie Specialty Shop (+2.5)\ncosts: ", width/6*5, height/8*3, 400, 100, 4);
  upgradeButton("Cookie Station (+6.0)\ncosts: ", width/6*5, height/8*4, 400, 100, 5);
  upgradeButton("Cookie Factory (+15.0)\ncosts: ", width/6*5, height/8*5, 400, 100, 6);
  upgradeButton("Cookie Conglomerate (+25.0)\ncosts: ", width/6*5, height/8*6, 400, 100, 7);
  
  autoClick();
}

float[] chocoX = new float[15];
float[] chocoY = new float[15];

void cookieDraw(float x, float y, float d) {

  stroke(#FFFFFF);
  strokeWeight(d/20);
  fill(brown);
  ellipse(x, y, d, d);

  for (int i = 0; i < 15; i++) {
    chocoX[i] = random(x-(d/3), x+(d/3));
    chocoY[i] = random(y-(d/3), y+(d/3));

    noStroke();
    fill(chocolate);
    ellipse(chocoX[i], chocoY[i], d/10, d/10);
  }
}

void cookieButton(float x, float y, float d) {
  noStroke();
  
  if (dist(mouseX, mouseY, x, y) <= d/2) {

    fill(#FFFFFF, 50);
    ellipse(x, y, d+20, d+20);

    cw = ch = 500;
    cx = width/2-250;
    cy = height/2-250;

    if (mousePressed) {

      cx -= 15;
      cy -= 15;
      cw = ch = 530;

      clickText("+1", width/24*15, height/2);

      cookies += 1;

      mousePressed = false;
    }
  }
}

void clickText(String t, float x, float y) {
  noStroke();
  fill(chocolate);
  textAlign(CENTER, CENTER);
  textSize(48);
  text(t, x, y);
}

void displayCookies(float x, float y) {
  noStroke();
  fill(chocolate);
  textAlign(CENTER, CENTER);
  textSize(48);
  text("cookies: " + int(cookies), x, y);
  
  text("auto: " + nf(auto,3,2), x, y+50);
}

void upgradeButton(String t, float x, float y, float w, float h, int c) {
  
  int opa = 200;

  if (mouseX >= (x-w/2) && mouseX <= (x+w/2) && mouseY >= (y-h/2) && mouseY <= (y+h/2)) {

    opa = 175;

    if (mousePressed) {

      if (cookies >= cost[c]) {
        cookies -= cost[c];
        cost[c] *= 1.10;
        auto += amount[c];
      }

      opa = 225;
      mousePressed = false;
    }
  }
  
  noStroke();
  rectMode(CENTER);
  fill(#000000, opa);
  rect(x, y, w, h);

  textAlign(CENTER, CENTER);
  textSize(24);
  fill(#FFFFFF);
  text(t + int(cost[c]), x, y, w, h);
}

float[] amount = new float[8];
float auto = 0;

void autoClick() {
  cookies += auto;
}

void title() {
  textSize(96);
  textAlign(CENTER,CENTER);
  strokeWeight(10);
  
  fill(255);
  stroke(255);
  text("COOKIE CLICKER",width/2+5,height/10+5);
  line(width/5+5,height/5.5+5,width/5*4+5,height/5.5+5);
  
  fill(chocolate);
  stroke(chocolate);
  text("COOKIE CLICKER",width/2+2.5,height/10+2.5);
  line(width/5+2.5,height/5.5+2.5,width/5*4+2.5,height/5.5+2.5);
  
  fill(brown);
  stroke(brown);
  text("COOKIE CLICKER",width/2,height/10);
  line(width/5,height/5.5,width/5*4,height/5.5);
}
read-only archive source from /2017/Project - Cookie Clicker/Cookie_Clicker/Cookie_Clicker.pde

Description

This page is generated from the Processing project folder at /2017/Project - Cookie Clicker/Cookie_Clicker/Cookie_Clicker.pde.

Archive

No companion assets were found in this sketch folder.