Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
7.0 kB
4
Indexable
// Egg vars
int eggX, eggY;
int eggW = 160;
int eggH = 215;
float eggHealth = 20;

// Player stats
float money = 0;
int clickDamage = 1;
float moneyPerClick = .5;

// Round vars
int round = 1;
int mpClickRound = 2;
int dpClickRound = 2;

// Shop vars
float upgradeMPClickCost = 1;
float upgradeDPClickCost = 1000;

// Spawn points
int maxSpawnPoints = 8;
PVector[] spawnPoints = new PVector[maxSpawnPoints];
float distFromEgg = 50;

// Chick stuff
ArrayList<Chick> chicks = new ArrayList<Chick>();
boolean canSpawnChick = false;
int chickDamage = 1;
float chickCooldown = 60;
int chickMoney = 0;
boolean chickSpawnAnim = false;

// Egg Sprites
PImage egg1;

// Chicken Sprites
PImage whiteChicken;

// Font
PFont blockyFont;

int numChick;

float r = 0;

void setup() {
  frameRate(60);
  size(640, 640);
  eggX = width / 3;
  eggY = height / 3;


  //Stuff to do With Images
  smooth(0);
  egg1 = loadImage("LightBrownEgg.png");
  blockyFont = createFont("BlockyFont.TTF", 16, false);
  whiteChicken = loadImage("WhiteChicken.png");

  //Chicken Stuff
  for (int i = 0; i < maxSpawnPoints; i++) {
    float angle = TWO_PI / maxSpawnPoints * i;
    float x = eggX + (eggW / 2 + distFromEgg) * cos(angle);
    float y = eggY + (eggH / 2 + distFromEgg) * sin(angle);
    spawnPoints[i] = new PVector(x, y);
  }
}

void draw() {
  background(250);
  textFont(blockyFont);
  drawEgg();
  showUI();
  checkEggHealth();
  drawUpgradeMPClick();
  drawUpgradeDPClick();
  showGizmos();

  for (Chick chick : chicks) {
    chick.update();
    chick.display();
    chick.damage();
    
    if (chickSpawnAnim) {
      chick.startAnim();
    }
  }
}

void keyPressed() {
}

void mousePressed() {
  if (clickedEgg()) {
    eggHealth -= clickDamage;
    money += moneyPerClick;
  }
  if (upgradeMPClick()) {
    money = money - upgradeMPClickCost;
    moneyPerClick += moneyPerClick;
    mpClickRound +=1;
    upgradeMPClickCost = upgradeMPClickCost * mpClickRound;
  }
  if (upgradeDPClick()) {
    money = money - upgradeDPClickCost;
    clickDamage = clickDamage * 2;
    dpClickRound +=2;
    upgradeDPClickCost = upgradeMPClickCost * dpClickRound;
  }
}

void drawEgg() {
  strokeWeight(3);
  stroke(10);
  imageMode(CENTER);
  image(egg1, eggX, eggY, 240, 240);
  textAlign(CENTER, CENTER);
  textSize(24);
  fill(0);
  text("Egg: " + round, eggX, eggY);
}

void drawUpgradeMPClick() {
  strokeWeight(3);
  stroke(10);
  fill(4, 136, 184);
  rectMode(CENTER);
  rect(3 * width / 4, height / 6, 150, 60);
  strokeWeight(0);
  fill(3, 186, 252);
  stroke(3, 186, 184);
  rect(3 * width / 4, height / 6, 140, 50);
  textAlign(CENTER, CENTER);
  textSize(12);
  fill(0);
  text("Upgrade MPC: $" + nf(upgradeMPClickCost, 0, 0), 3 * width / 4, height / 6, 150, 60);
}

void drawUpgradeDPClick() {
  strokeWeight(3);
  stroke(10);
  fill(4, 136, 184);
  rectMode(CENTER);
  rect(3 * width / 4, 2 * height / 6, 150, 60);
  strokeWeight(0);
  fill(3, 186, 252);
  stroke(3, 186, 184);
  rect(3 * width / 4, 2 * height / 6, 140, 50);
  textAlign(CENTER, CENTER);
  textSize(12);
  fill(0);
  text("Upgrade DPC: $" + nf(upgradeDPClickCost, 0, 0), 3 * width / 4, 2 * height / 6, 150, 60);
}

void showUI() {
  textAlign(CENTER, CENTER);
  textSize(20);
  fill(3, 136, 184);
  stroke(0);
  strokeWeight(5);
  rect(3 * width / 4, 3 * height / 4, 250, 290);
  fill(3, 186, 252);
  stroke(3, 186, 252);
  rect(3 * width / 4, 3 * height / 4, 230, 270);
  fill(0);
  text("Health Left: " + nf(eggHealth, 0, 0), 3* width / 4, 3 * height / 4 - 110);
  text("Money: $" + nf(money, 0, 2), 3 * width / 4, 3 * height / 4 - 55);
  text("DPC: " + clickDamage, 3 * width / 4, 3 * height / 4);
  text("MPC: $" + moneyPerClick, 3 * width / 4, 3 * height / 4 + 55);
  text("# of Chickens: " + numChick, 3 * width / 4, 3 * height / 4 + 110);
}

void checkEggHealth() {
  if (eggHealth <= 0) {
    chickMoney = chickMoney + 1;
    chickDamage = chickDamage * 2;
    if (spawnPoints.length >= 1) {
    spawnChick();
    }
    numChick += 1;
    nextRound();
  }
}

void spawnChick() {
  int indexToRemove = int(random(spawnPoints.length));
  PVector spawnPoint = spawnPoints[indexToRemove];
  Chick newChick = new Chick(spawnPoint.x, spawnPoint.y, 0, chickDamage, chickCooldown, chickMoney);
  chicks.add(newChick);

  // Generate New Spawn Point
  PVector[] newSpawnPoints = new PVector[spawnPoints.length - 1];
  for (int i = 0, j = 0; i < spawnPoints.length; i++) {
    if (i != indexToRemove) {
      newSpawnPoints[j++] = spawnPoints[i];
    }
  }
  spawnPoints = newSpawnPoints;

  chickSpawnAnim = true;
}

//Change the "Pow" first number to change how  much increase or decrease
void nextRound() {
  round += 1;
  eggHealth = pow(5, round);
  money += money;
  if (round <= 3) {
    clickDamage += 1;
  } else {
    clickDamage += clickDamage;
  }
}

void showGizmos() {
  fill(255, 0, 0);
  for (PVector point : spawnPoints) {
    ellipse(point.x, point.y, 10, 10);
  }

  stroke(0, 255, 0);
  noFill();
  ellipse(eggX, eggY, eggW, eggH);
}

class Chick {
  float x, y, radius;
  int damage;
  float cooldown;
  int _chickMoney;

  float cooldownCounter;
  
  boolean playStartAnim;


  Chick(float x, float y, float radius, int damage, float cooldown, int _chickMoney) {
    this.x = x;
    this.y = y;
    this.radius = radius;
    this.damage = damage;
    this.cooldown = cooldown;
    this.cooldownCounter = cooldown;
    this._chickMoney = _chickMoney;
    this.playStartAnim = true;
  }

  void update() {
    cooldownCounter -= 1;
  }

  void display() {
    strokeWeight(3);
    stroke(10);
    fill(230, 220, 10);
    image(whiteChicken, x, y, radius * 1.6, radius * 2);
  }

  void damage() {
    if (cooldownCounter <= 0) {
      eggHealth -= damage;
      cooldownCounter = cooldown;
      money += _chickMoney;
    }
  }
  
  // Animations
  void startAnim() {
    if (playStartAnim) {
         radius += 2.5;
       if (radius >= 30) {
         playStartAnim = false;
       }
    }
  }
}


// // [CHECK CLICK FUNCTIONS] \\ \\
boolean clickedEgg() {
  if (dist(mouseX, 0, eggX, 0) <= eggW / 2 && dist(0, mouseY, 0, eggY) <= eggH / 2) {
    return true;
  }
  return false;
}

boolean upgradeMPClick() {
  if (mouseX >= 3 * width / 4 - 75 && mouseX <= 3 * width / 4 + 75) {
    if (mouseY >= height/ 6 - 30 && mouseY <= height / 6 + 30) {
      if (money >= upgradeMPClickCost) {
        return true;
      }
    }
  }
  return false;
}

boolean upgradeDPClick() {
  if (mouseX >= 3 * width / 4 - 75 && mouseX <= 3 * width / 4 + 75) {
    if (mouseY >= 2 * height/ 6 - 30 && mouseY <= 2 * height / 6 + 30) {
      if (money >= upgradeDPClickCost) {
        return true;
      }
    }
  }
  return false;
}