//Sound
int musicTimer = 0;
import processing.sound.*;
SoundFile backgroundMusic;
import processing.sound.*;
SoundFile _pop;
// Egg vars
int eggX, eggY;
int eggW = 160;
int eggH = 215;
float eggHealth = 20;
float eggStartingHealth = 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, egg2, egg3, egg4;
PImage eggSpriteState;
// Chicken Sprites
PImage whiteChicken;
// Background
PImage gameBG;
PImage cloud1, cloud2, cloud3, cloud4;
PImage[] cloudSprites = new PImage[4];
ArrayList<Cloud> clouds = new ArrayList<Cloud>();
float cloudSpawnTimer = 0;
// Font
PFont blockyFont;
int numChick;
float r = 0;
float spriteEggW = 240;
float spriteEggH = 240;
float eggText = 24;
void setup() {
frameRate(60);
size(640, 640);
eggX = width / 4;
eggY = 2 * height / 3;
//sound
backgroundMusic = new SoundFile(this, "backgroundMusic.mp3");
backgroundMusic.amp(.01);
backgroundMusic.play();
_pop = new SoundFile(this, "pop.wav");
//Stuff to do With Images
smooth(0);
egg1 = loadImage("LightBrownEgg1.png");
egg2 = loadImage("LightBrownEgg2.png");
egg3 = loadImage("LightBrownEgg3.png");
egg4 = loadImage("LightBrownEgg4.png");
blockyFont = createFont("BlockyFont.TTF", 16);
whiteChicken = loadImage("WhiteChicken.png");
for (int i = 0; i < cloudSprites.length; i++) {
cloudSprites[i] = loadImage("Cloud" + (i + 1) + ".png");
}
gameBG = loadImage("gameBG.png");
eggSpriteState = egg1;
//Chicken Spawning
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(gameBG);
spawnCloud();
if (clouds != null) {
for (Cloud cloud : clouds) {
cloud.move();
cloud.display();
}
}
textFont(blockyFont);
musicLoopCheck();
drawEgg();
showUI();
checkEggHealth();
drawUpgradeMPClick();
drawUpgradeDPClick();
// showGizmos();
setEggSize();
for (Chick chick : chicks) {
chick.update();
chick.display();
chick.damage();
chick.startAnim();
chick.damageAnim();
}
}
void keyPressed() {
}
void mousePressed() {
if (hoveringEgg()) {
eggHealth -= clickDamage;
money += moneyPerClick;
spriteEggW = 240;
spriteEggH = 240;
eggText = 24;
}
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(eggSpriteState, eggX, eggY, spriteEggW, spriteEggH);
textAlign(CENTER, CENTER);
fill(0);
textSize(eggText - 10);
text("Health Left: " + nf(eggHealth, 0, 0), eggX , eggY - 130);
textSize(eggText);
text("Egg: " + round, eggX, eggY - 170);
}
void setEggSize() {
if (hoveringEgg() && spriteEggW <= 255 && spriteEggH <= 255 && eggText <= 25.5) {
spriteEggW += 2;
spriteEggH += 2;
eggText += .4;
} else if (!hoveringEgg()) {
spriteEggW = 240;
spriteEggH = 240;
eggText = 24;
}
}
void spawnCloud() {
cloudSpawnTimer -= 1;
if (cloudSpawnTimer < 0) {
PImage sprite = cloudSprites[int(random(0, cloudSprites.length))];
Cloud newCloud = new Cloud(-50, random(0, 200), 1.5, sprite, int(random(80, 130)));
clouds.add(newCloud);
cloudSpawnTimer = 160;
}
}
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(#1B934A);
text("Money: $" + nf(money, 0, 2), 3 * width / 4, 3 * height / 4 - 55);
text("MPC: $" + moneyPerClick, 3 * width / 4, 3 * height / 4 + 55);
fill(#AA1530);
text("DPC: " + clickDamage, 3 * width / 4, 3 * height / 4);
fill(0);
text("# of Chickens: " + numChick, 3 * width / 4, 3 * height / 4 + 110);
}
void checkEggHealth() {
if (eggStartingHealth * 0.1 >= eggHealth) {
eggSpriteState = egg4;
} else if (eggStartingHealth * 0.35 >= eggHealth) {
eggSpriteState = egg3;
} else if (eggStartingHealth * 0.75 >= eggHealth) {
eggSpriteState = egg2;
} else {
eggSpriteState = egg1;
}
if (eggHealth <= 0) {
chickMoney = chickMoney + 1;
chickDamage = chickDamage * 2;
chickCooldown -= 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, chickDamage, chickCooldown, chickMoney);
chicks.add(newChick);
_pop.play();
// 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);
eggStartingHealth = eggHealth;
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;
// Anim vars
boolean playStartAnim;
boolean growing;
boolean playDamageAnim;
float initialX, initialY;
boolean hitting;
Chick(float x, float y, int damage, float cooldown, int _chickMoney) {
this.x = x;
this.y = y;
this.radius = 0;
this.damage = damage;
this.cooldown = cooldown;
this.cooldownCounter = cooldown;
this._chickMoney = _chickMoney;
this.playStartAnim = true;
this.playDamageAnim = false;
this.initialX = x;
this.initialY = y;
this.growing = true;
this.hitting = true;
}
void update() {
cooldownCounter -= 1;
}
void display() {
strokeWeight(3);
stroke(10);
fill(230, 220, 10);
if (initialX >= width / 4 && initialY > 300) {
pushMatrix();
translate(x + whiteChicken.width, y);
scale(-1, 1);
image(whiteChicken, 0, 0, radius * 1.6, radius * 2);
popMatrix();
} else {
image(whiteChicken, x, y, radius * 1.6, radius * 2);
}
}
void damage() {
if (cooldownCounter <= 0) {
eggHealth -= damage;
cooldownCounter = cooldown;
money += _chickMoney;
playDamageAnim = true;
}
}
// Animations
void startAnim() {
if (playStartAnim) {
if (growing) {
radius += 2.5;
}
if (radius >= 35) {
growing = false;
}
if (!growing) {
radius -= 1;
if (radius <= 30) {
playStartAnim = false;
}
}
}
}
void damageAnim() {
if (playDamageAnim) {
if (hitting) {
float targetX = eggX - x;
float targetY = eggY - y;
x += targetX * 0.25;
y += targetY * 0.25;
} else {
float returnPointX = initialX - x;
float returnPointY = initialY - y;
x += returnPointX * 0.25;
y += returnPointY * 0.25;
if (dist(x, y, initialX, initialY) <= 0.1) {
x = initialX;
y = initialY;
}
}
if (dist(x, y, eggX, eggY) <= eggW / 2) {
hitting = false;
}
if (x == initialX && y == initialY) {
playDamageAnim = false;
hitting = true;
}
}
}
}
class Cloud {
float x, y;
float speed;
PImage sprite;
int size;
boolean displayCloud;
Cloud(float x, float y, float speed, PImage sprite, int size) {
this.x = x;
this.y = y;
this.speed = speed;
this.size = size;
this.sprite = sprite;
this.displayCloud = true;
}
void display() {
if (displayCloud) {
image(sprite, x, y, size, size);
}
}
void move() {
if (displayCloud) {
x += speed;
if (x >= width + size * 1.2) {
displayCloud = false;
}
}
}
}
// // [CHECK CLICK FUNCTIONS] \\ \\
boolean hoveringEgg() {
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;
}
void musicLoopCheck() {
musicTimer += 1;
if (musicTimer % 6480 == 0) {
backgroundMusic.play();
}
}