package slimpleslickgame;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Vector2f;

import util.Logger;

public class Stats {
	
	private float x, y;
	private int credits = 0;
	private int level = 1;
	private int time = 0;
	private boolean tryUpgrade = false;
	private int hp = 100;
	private int incomeRate = 1000;
	
	public Stats(Vector2f scoreBoardPos) {
		this.x = scoreBoardPos.x;
		this.y = scoreBoardPos.y;
	}

	public void render(Graphics graphics){
		graphics.drawString("Credits: " + credits , x, y-graphics.getFont().getLineHeight());
		graphics.drawString("HP: "+ hp , x, y);
	}
	
	public boolean update(int delta, int score){
		credits = score;
		return this.update(delta);
	}
	
	public boolean update(int delta){
		int levelCredits = 1000;
		if(this.credits >= levelCredits && this.tryUpgrade){
			level++;
			this.credits -= levelCredits;
			Logger.log("Upgraded player!");
			return true;
		}
		this.tryUpgrade = false;
		return false;
	}

	public void putUpgradePressed() {
		this.tryUpgrade = true;
	}

	public int calcCredits(int delta, int scoreDiff) {
		int creditsDiff = scoreDiff;
		this.time += delta;
		while(time > incomeRate){
			time -= incomeRate;
			creditsDiff += level;
		}
		this.credits += creditsDiff;
		return this.credits;
	}

	private static final int CREEP_PRICE_1 = 100;
	private static final int CREEP_PRICE_5 = 400;
	private static final int CREEP_PRICE_20 = 1200;
	
	public int buyCreeps(int key) {
		switch(key){
			case 1:
				if(this.credits >= CREEP_PRICE_1){
					credits -= CREEP_PRICE_1;
					this.incomeRate--;
					return 1;
				}
				break;
			case 2:
				if(this.credits >= CREEP_PRICE_5){
					credits -= CREEP_PRICE_5;
					this.incomeRate -= 6;
					return 5;
				}
				break;
			case 3:
				if(this.credits >= CREEP_PRICE_20){
					credits -= CREEP_PRICE_20;
					this.incomeRate -= 25;
					return 20;
				}
				break;
		}
		return 0;
	}
	
	public int damaged() {
		hp--;
		return hp;
	}

	public void setHP(int playerHp) {
		this.hp = playerHp;
	}

}

@@ -758,19 +758,18 @@
 edits = 
-100
+75
 0;%0A%09%09if(
@@ -1366,10 +1366,10 @@
 5 = 
-40
+25
 0;%0A%09
@@ -1409,16 +1409,15 @@
 ICE_
-2
+1
 0 = 
-120
+45
 0;%0A%09
@@ -1788,17 +1788,17 @@
 P_PRICE_
-2
+1
 0)%7B%0A%09%09%09%09
@@ -1821,17 +1821,17 @@
 P_PRICE_
-2
+1
 0;%0A%09%09%09%09%09
@@ -1865,17 +1865,17 @@
 %09return 
-2
+1
 0;%0A%09%09%09%09%7D

change stats