Untitled
unknown
plain_text
a year ago
8.3 kB
4
Indexable
Never
//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; // 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; // Backgorund Image PImage gameBG; // 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"); _pop = new SoundFile(this, "pop.mp3"); backgroundMusic.amp(.01); backgroundMusic.play(); //Stuff to do With Images smooth(0); egg1 = loadImage("LightBrownEgg.png"); blockyFont = createFont("BlockyFont.TTF", 16); whiteChicken = loadImage("WhiteChicken.png"); gameBG = loadImage("gameBG.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(gameBG); textFont(blockyFont); musicLoopCheck(); drawEgg(); showUI(); checkEggHealth(); drawUpgradeMPClick(); drawUpgradeDPClick(); // showGizmos(); setEggSize(); for (Chick chick : chicks) { chick.update(); chick.display(); chick.damage(); chick.startAnim(); } } 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(egg1, eggX, eggY, spriteEggW, spriteEggH); textAlign(CENTER, CENTER); fill(0); textSize(eggText); text("Egg: " + round, eggX, eggY); } 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 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, 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; // Anim vars boolean playStartAnim; boolean growing; 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.growing = true; } void update() { cooldownCounter -= 1; } void display() { strokeWeight(3); stroke(10); fill(230, 220, 10); if (x >= width / 4 && y > 300) { _pop.play(); 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; } } // Animations void startAnim() { if (playStartAnim) { if (growing) { radius += 2.5; } if (radius >= 35) { growing = false; } if (!growing) { radius -= 1; if (radius <= 30) { playStartAnim = 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(); } }