From 0b02a03559a0ee166b059220e0e8e25d40175f17 Mon Sep 17 00:00:00 2001 From: Davy Ling Date: Sun, 22 May 2022 20:10:04 -0400 Subject: [PATCH] PlayerStats --- src/entities/units/player/Player.java | 12 ++---------- src/gamestates/Game.java | 8 ++++---- src/playerdata/PlayerStats.java | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/entities/units/player/Player.java b/src/entities/units/player/Player.java index bcb3063..ca8b5ba 100644 --- a/src/entities/units/player/Player.java +++ b/src/entities/units/player/Player.java @@ -41,7 +41,6 @@ public PlayerState getState() { protected Arte move; protected int queue; protected PlayableCharacter character; - protected PlayerStats stats; // Abbreviations: LVL, EXP, HP, ATK, DEF, CR, CD, EATK, EDEF, AFF public Player(Coordinate pos) throws SlickException { @@ -191,21 +190,14 @@ public void battleRender(Graphics g, float plrX, float plrY) { public void gainExp(int amount) { this.character.gainExp(amount); - this.stats.exp+=amount; - } - public void gainMoney(int amount) { - this.stats.gold+=amount; } public int getExp() { - return this.stats.exp; - } - public int getMoney() { - return this.stats.gold; + return character.getExp(); } public int getLevel() { - return this.stats.level; + return character.getLevel(); } @Override diff --git a/src/gamestates/Game.java b/src/gamestates/Game.java index eddb47f..f7258d6 100644 --- a/src/gamestates/Game.java +++ b/src/gamestates/Game.java @@ -129,9 +129,9 @@ public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws Slic npc.render(gc, plrPosition.getX(), plrPosition.getY()); plr.render(g); g.drawString("Coords: " + plr.getPosition().toString(), 100, 200); - DrawUtilities.drawStringCentered(g,"Level: " + plr.getLevel(), 100, 50); - DrawUtilities.drawStringCentered(g, "Exp: " + plr.getExp(), 100, 100); - DrawUtilities.drawStringCentered(g, "Money: " + plr.getMoney(), 100, 150); + DrawUtilities.drawStringCentered(g,"Level: " + Main.stats.level, 100, 50); + DrawUtilities.drawStringCentered(g, "Exp: " + Main.stats.exp + "/" + Main.stats.maxExp, 100, 100); + DrawUtilities.drawStringCentered(g, "Gold: " + Main.stats.gold, 100, 150); if(Main.debug) { plr.drawHitBox(g); enemy.drawHitBox(g); @@ -183,7 +183,7 @@ public void update(GameContainer gc, StateBasedGame sbg, int delta) throws Slick public void enter(GameContainer gc, StateBasedGame sbg) throws SlickException { System.out.println("Entering game"); plr.gainExp(BattleState.expGain); - plr.gainMoney(BattleState.currencyGain); + Main.stats.gainGold(BattleState.currencyGain); // Reset time time = 0; System.out.println("[VERBOSE] Time reset"); diff --git a/src/playerdata/PlayerStats.java b/src/playerdata/PlayerStats.java index d7cf8ff..9051bbe 100644 --- a/src/playerdata/PlayerStats.java +++ b/src/playerdata/PlayerStats.java @@ -20,5 +20,25 @@ public PlayerStats() { public void update() { maxExp = Constants.LevelingConstants.MAX_EXP(level); + if (exp >= maxExp) { + level++; + exp = exp - maxExp; + } + } + + public void gainGold(int amount) { + gold += amount; + } + + public void gainExp(int amount) { + exp += amount; + if (exp >= maxExp) { + level++; + exp = exp - maxExp; + } + } + + public void gainLevel(int amount) { + level += amount; } }