Permalink
Browse files

Lesson 23: stat logic and display

  • Loading branch information...
vladimirslav committed Dec 26, 2016
1 parent 564990a commit c867d7ca47e0ea721353d03107ee7f9e160d32aa
@@ -19,7 +19,7 @@
public static final int MAX_BASE_X = 3;
public static final int MAX_BASE_Y = 3;
private static final float BONUS_SPAWN_INTERVAL = 2.0f; // spawn bonus every 2 seconds
private final float BONUS_SPAWN_INTERVAL; // spawn bonus every 2 seconds
private static final int MAX_BONUSES_ON_FIELD = 3;
public interface GameEventListener
@@ -39,6 +39,7 @@
GameEventListener eventListener;
public GameLogic(DodgingHero _game, GameEventListener _listener) {
BONUS_SPAWN_INTERVAL = 2.0f * (1 - GameProgress.getPlayerBonusReduction());
eventListener = _listener;
game = _game;
player = new Player(
@@ -140,11 +141,11 @@ public void AssignPlayerPosition(int fx, int fy)
if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_HEALTH)
{
player.addLives(1);
player.addLives(GameProgress.getPlayerHealthRestored());
}
else if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_ATTACK)
{
enemy.takeDamage(GameProgress.playerDamage);
enemy.takeDamage(GameProgress.getPlayerDamage());
if (enemy.getLives() <= 0)
{
GameProgress.currentLevel ++;
@@ -11,8 +11,6 @@
public class GameProgress {
public static int playerLives = 3;
public static int maxPlayerLives = 3;
public static int playerDamage = 1;
public static int currentLevel = 0;
public static int currentCharacter = 0;
public static int currentGold = 0;
@@ -23,9 +21,7 @@
private static final String PROGRESS_SAVE_NAME = "progress";
private static final String SAVE_KEY_LIVES = "lives";
private static final String SAVE_KEY_LIVES_MAX = "livesmax";
private static final String SAVE_KEY_CURRENT_LEVEL = "currentlevel";
private static final String SAVE_KEY_PLAYER_DAMAGE = "playerdamage";
private static final String SAVE_KEY_PLAYER_GOLD = "playergold";
private static final String SAVE_KEY_PLAYER_LEVEL = "playerlevel";
@@ -38,9 +34,7 @@ public static void Save()
{
Preferences prefs = Gdx.app.getPreferences(PROGRESS_SAVE_NAME);
prefs.putInteger(SAVE_KEY_LIVES, playerLives);
prefs.putInteger(SAVE_KEY_LIVES_MAX, maxPlayerLives);
prefs.putInteger(SAVE_KEY_CURRENT_LEVEL, currentLevel);
prefs.putInteger(SAVE_KEY_PLAYER_DAMAGE, playerDamage);
prefs.putInteger(SAVE_KEY_PLAYER_GOLD, currentGold);
@@ -58,9 +52,7 @@ public static void Load()
Preferences prefs = Gdx.app.getPreferences(PROGRESS_SAVE_NAME);
playerLives = prefs.getInteger(SAVE_KEY_LIVES, 3);
maxPlayerLives = prefs.getInteger(SAVE_KEY_LIVES_MAX, 3);
currentLevel = prefs.getInteger(SAVE_KEY_CURRENT_LEVEL, 0);
playerDamage = prefs.getInteger(SAVE_KEY_PLAYER_DAMAGE, 1);
currentGold = prefs.getInteger(SAVE_KEY_PLAYER_GOLD, 0);
for (int i = 0; i < CharacterRecord.CHARACTERS.length; i++)
@@ -71,12 +63,35 @@ public static void Load()
public static void Reset() {
playerLives = 3;
maxPlayerLives = 3;
currentLevel = 0;
playerDamage = 1;
}
public static int getNextUpgradeCost(int currentCharacter) {
return levels[currentCharacter] * 2;
}
public static int getPlayerMaxHp() {
CharacterRecord currentChar = CharacterRecord.CHARACTERS[currentCharacter];
return currentChar.getMaxHp(levels[currentCharacter]);
}
public static int getPlayerDamage() {
CharacterRecord currentChar = CharacterRecord.CHARACTERS[currentCharacter];
return currentChar.getDmg(levels[currentCharacter]);
}
public static int getPlayerHealthRestored() {
CharacterRecord currentChar = CharacterRecord.CHARACTERS[currentCharacter];
return currentChar.getHpRestored(levels[currentCharacter]);
}
public static float getPlayerBonusReduction() {
CharacterRecord currentChar = CharacterRecord.CHARACTERS[currentCharacter];
return currentChar.getBonusSpawnReduction(levels[currentCharacter]);
}
public static int getBonusReductionValue() {
CharacterRecord currentChar = CharacterRecord.CHARACTERS[currentCharacter];
return levels[currentCharacter] / currentChar.levelsForBonusSpawnUpgrade;
}
}
@@ -35,4 +35,26 @@ public CharacterRecord(int lvlHp, int lvlRegen, int lvlAttack, int lvlBonus, Str
new CharacterRecord(4, 4, 2, 4, CHAR_NAME_GHOST),
new CharacterRecord(3, 3, 4, 1, CHAR_NAME_SLIME)
};
public int getMaxHp(int level)
{
return 3 + level / levelsForHpUpgrade;
}
public int getDmg(int level)
{
return 1 + level / levelsForAttackUpgrade;
}
public int getHpRestored(int level)
{
return 1 + level / levelsForHpRegenUpgrade;
}
public float getBonusSpawnReduction(int level)
{
int bonusSpawnLvl = level / levelsForBonusSpawnUpgrade;
return bonusSpawnLvl / (30 + bonusSpawnLvl); // 30 enables diminishing returns, x / ( x + 30 ) < 1
}
}
@@ -27,7 +27,7 @@ public Player(int fx, int fy, Resources res, int _lives)
fieldY = fy;
//set(res.player);
set(res.playerSprites.get(CharacterRecord.CHARACTERS[GameProgress.currentCharacter].name));
max_lives = GameProgress.maxPlayerLives;
max_lives = GameProgress.getPlayerMaxHp();
}
public int getFieldX()
@@ -10,6 +10,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.coldwild.dodginghero.DodgingHero;
import com.coldwild.dodginghero.logic.GameProgress;
@@ -23,6 +24,15 @@
Stage uiStage;
private Label prepareStatLabel(String text, float x, float y, Label.LabelStyle textStyle)
{
Label lbl = new Label(text, textStyle);
lbl.setAlignment(Align.left);
lbl.setPosition(x, y);
uiStage.addActor(lbl);
return lbl;
}
void prepareUi()
{
uiStage.clear();
@@ -91,10 +101,30 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
game.res.playerSprites.get(CharacterRecord.CHARACTERS[GameProgress.currentCharacter].name)
);
heroSprite.setPosition((uiStage.getWidth() - heroSprite.getWidth()) / 2,
heroSprite.setPosition((uiStage.getWidth() - heroSprite.getWidth()) / 4,
(uiStage.getHeight() - heroSprite.getHeight()) / 2);
uiStage.addActor(heroSprite);
Label stat = prepareStatLabel("DMG:" + GameProgress.getPlayerDamage(),
uiStage.getWidth() / 2,
heroSprite.getY() + heroSprite.getHeight(),
textStyle);
stat = prepareStatLabel("HP:" + GameProgress.getPlayerMaxHp(),
uiStage.getWidth() / 2,
stat.getY() - 10,
textStyle);
stat = prepareStatLabel("HEAL:" + GameProgress.getPlayerHealthRestored(),
uiStage.getWidth() / 2,
stat.getY() - 10,
textStyle);
prepareStatLabel("BNS:" + GameProgress.getBonusReductionValue(),
uiStage.getWidth() / 2,
stat.getY() - 10,
textStyle);
int lvl = GameProgress.levels[GameProgress.currentCharacter];
Label statusText = new Label(lvl > 0 ? "LVL: " + lvl : "LOCKED", textStyle);
statusText.setPosition(heroSprite.getX() + (heroSprite.getWidth() - statusText.getWidth()) / 2,
@@ -116,7 +146,7 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
}
});
nextButton.setPosition(uiStage.getWidth() * 5 / 6 - nextButton.getWidth() /2,
uiStage.getHeight() / 2);
uiStage.getHeight() * 5 / 6);
uiStage.addActor(nextButton);
TextButton prevButton = new TextButton("<<<", buttonStyle);
@@ -133,7 +163,7 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
prepareUi();
}
});
prevButton.setPosition(uiStage.getWidth() / 6, uiStage.getHeight() / 2);
prevButton.setPosition(uiStage.getWidth() / 6, uiStage.getHeight() * 5 / 6);
uiStage.addActor(prevButton);
// draw the image

0 comments on commit c867d7c

Please sign in to comment.