Permalink
Browse files

Lesson 24: progression changes / rewards on level completion

  • Loading branch information...
vladimirslav committed Dec 27, 2016
1 parent c867d7c commit 49e8b0fe0fa156e17acd6d4ab01d798296f70f03
@@ -148,7 +148,7 @@ else if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_ATTACK)
enemy.takeDamage(GameProgress.getPlayerDamage());
if (enemy.getLives() <= 0)
{
- GameProgress.currentLevel ++;
+ GameProgress.increaseStage();
GameProgress.playerLives = player.getLives();
player.markVictorious();
eventListener.OnGameEnd(true);
@@ -190,10 +190,10 @@ public void OnEffectOver(WarningEffect effect) {
if (effect.getFieldX() == player.getFieldX() &&
effect.getFieldY() == player.getFieldY())
{
- player.takeDamage(1);
+ player.takeDamage(GameProgress.getEnemyDamage());
if (player.getLives() <= 0)
{
- GameProgress.Reset();
+ GameProgress.Reset(true);
}
}
}
@@ -11,36 +11,41 @@
public class GameProgress {
public static int playerLives = 3;
- public static int currentLevel = 0;
public static int currentCharacter = 0;
public static int currentGold = 0;
public static final int CHARACTER_PRICE = 1000;
public static int levels[]; // level of each character, 0 = locked
+ public static int stages[]; // how far the character has progressed
private static final String PROGRESS_SAVE_NAME = "progress";
private static final String SAVE_KEY_LIVES = "lives";
- private static final String SAVE_KEY_CURRENT_LEVEL = "currentlevel";
- private static final String SAVE_KEY_PLAYER_GOLD = "playergold";
private static final String SAVE_KEY_PLAYER_LEVEL = "playerlevel";
+ private static final String SAVE_KEY_PLAYER_STAGE = "playerstage";
+ private static final String SAVE_KEY_PLAYER_GOLD = "playergold";
public static int getEnemyLives()
{
- return 3 + currentLevel * 2; // 3 lives on lvl0, 5 lives on lvl1, etc
+ return 3 + stages[currentCharacter] * 2; // 3 lives on lvl0, 5 lives on lvl1, etc
+ }
+
+ public static int getEnemyDamage()
+ {
+ return 1 + stages[currentCharacter] / 10;
}
public static void Save()
{
Preferences prefs = Gdx.app.getPreferences(PROGRESS_SAVE_NAME);
prefs.putInteger(SAVE_KEY_LIVES, playerLives);
- prefs.putInteger(SAVE_KEY_CURRENT_LEVEL, currentLevel);
prefs.putInteger(SAVE_KEY_PLAYER_GOLD, currentGold);
for (int i = 0; i < CharacterRecord.CHARACTERS.length; i++)
{
prefs.putInteger(SAVE_KEY_PLAYER_LEVEL + i, levels[i]);
+ prefs.putInteger(SAVE_KEY_PLAYER_STAGE + i, stages[i]);
}
prefs.flush();
@@ -49,21 +54,30 @@ public static void Save()
public static void Load()
{
levels = new int[CharacterRecord.CHARACTERS.length];
+ stages = new int[CharacterRecord.CHARACTERS.length];
Preferences prefs = Gdx.app.getPreferences(PROGRESS_SAVE_NAME);
playerLives = prefs.getInteger(SAVE_KEY_LIVES, 3);
- currentLevel = prefs.getInteger(SAVE_KEY_CURRENT_LEVEL, 0);
currentGold = prefs.getInteger(SAVE_KEY_PLAYER_GOLD, 0);
for (int i = 0; i < CharacterRecord.CHARACTERS.length; i++)
{
levels[i] = prefs.getInteger(SAVE_KEY_PLAYER_LEVEL + i, i == 0 ? 1 : 0);
+ stages[i] = prefs.getInteger(SAVE_KEY_PLAYER_STAGE + i, 0);
}
}
- public static void Reset() {
- playerLives = 3;
- currentLevel = 0;
+ public static void Reset(boolean resetProgress) {
+ if (resetProgress)
+ {
+ stages[currentCharacter] -= 5;
+ if (stages[currentCharacter] < 0)
+ {
+ stages[currentCharacter] = 0;
+ }
+ }
+
+ playerLives = getPlayerMaxHp();
}
public static int getNextUpgradeCost(int currentCharacter) {
@@ -94,4 +108,9 @@ public static int getBonusReductionValue() {
CharacterRecord currentChar = CharacterRecord.CHARACTERS[currentCharacter];
return levels[currentCharacter] / currentChar.levelsForBonusSpawnUpgrade;
}
+
+ public static void increaseStage() {
+ currentGold += 1 + stages[currentCharacter] / 4;
+ stages[currentCharacter]++;
+ }
}
@@ -142,6 +142,7 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
GameProgress.currentCharacter = 0;
}
+ GameProgress.Reset(false);
prepareUi();
}
});
@@ -160,6 +161,7 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
GameProgress.currentCharacter = CharacterRecord.CHARACTERS.length - 1;
}
+ GameProgress.Reset(false);
prepareUi();
}
});

0 comments on commit 49e8b0f

Please sign in to comment.