Permalink
Browse files

Lesson 21: adding gold pickups / persistence / display

  • Loading branch information...
vladimirslav committed Dec 19, 2016
1 parent 62d13ee commit 6eb79301a6ce8727379edc00b431c6a17b6ff506
@@ -25,65 +25,72 @@ bat
orig: 16, 16
offset: 0, 0
index: -1
ghost
coin
rotate: false
xy: 38, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
ground
ghost
rotate: false
xy: 56, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
ground
rotate: false
xy: 74, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
health
rotate: false
xy: 182, 10
xy: 200, 10
size: 14, 14
orig: 14, 14
offset: 0, 0
index: -1
player
rotate: false
xy: 74, 8
xy: 92, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
skeleton
rotate: false
xy: 92, 8
xy: 110, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
slime
rotate: false
xy: 110, 8
xy: 128, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
spider
rotate: false
xy: 128, 8
xy: 146, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
wall
rotate: false
xy: 146, 8
xy: 164, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
index: -1
warning
rotate: false
xy: 164, 8
xy: 182, 8
size: 16, 16
orig: 16, 16
offset: 0, 0
Binary file not shown.
View
Binary file not shown.
@@ -37,6 +37,7 @@
public Sprite attackBonus;
public Sprite healthBonus;
public Sprite coinBonus;
public static final int TILE_SIZE = 16;
@@ -69,6 +70,7 @@ public Resources()
attackBonus = gameSprites.createSprite("attack");
healthBonus = gameSprites.createSprite("health");
coinBonus = gameSprites.createSprite("coin");
}
public void dispose()
@@ -86,8 +86,20 @@ private void SpawnRandomBonus()
}
} while (targetNonEmpty);
byte activeBonus = Bonus.BONUS_TYPE_ATTACK;
int rnd = MathUtils.random(7); // 0 .. 7
// 1/8 chance to get health, 1/4 to get gold
if (rnd > 6)
{
activeBonus = Bonus.BONUS_TYPE_HEALTH;
}
else if (rnd > 4)
{
activeBonus = Bonus.BONUS_TYPE_COIN;
}
bonuses.add(Bonus.Create(fx, fy,
MathUtils.random(3) == 0 ? Bonus.BONUS_TYPE_HEALTH : Bonus.BONUS_TYPE_ATTACK,
activeBonus,
game.res));
lastBonusSpawnTime = gameTime;
}
@@ -141,6 +153,10 @@ else if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_ATTACK)
eventListener.OnGameEnd(true);
}
}
else if (currentBonus.getBonusType() == Bonus.BONUS_TYPE_COIN)
{
GameProgress.currentGold += 1;
}
currentBonus.release();
bonuses.remove(i);
@@ -14,13 +14,15 @@
public static int playerDamage = 1;
public static int currentLevel = 0;
public static int currentCharacter = 0;
public static int currentGold = 0;
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";
public static int getEnemyLives()
{
@@ -34,6 +36,8 @@ public static void Save()
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);
prefs.flush();
}
@@ -44,6 +48,7 @@ public static void Load()
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);
}
public static void Reset() {
@@ -14,6 +14,7 @@
public static byte BONUS_TYPE_ATTACK = 0;
public static byte BONUS_TYPE_HEALTH = 1;
public static byte BONUS_TYPE_COIN = 2;
private int fieldX;
private int fieldY;
@@ -38,6 +39,10 @@ else if (bType == BONUS_TYPE_HEALTH)
{
set(res.healthBonus);
}
else if (bType == BONUS_TYPE_COIN)
{
set(res.coinBonus);
}
}
@@ -6,6 +6,7 @@
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
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.viewport.FitViewport;
@@ -85,6 +86,19 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
});
prevButton.setPosition(uiStage.getWidth() / 6, uiStage.getHeight() / 2);
uiStage.addActor(prevButton);
// draw the image
Image coinImage = new Image(game.res.coinBonus);
coinImage.setPosition(1, 1);
uiStage.addActor(coinImage);
// amount of coins
Label.LabelStyle textStyle = new Label.LabelStyle(game.res.gamefont, Color.WHITE);
Label coinAmntLbl = new Label("" + GameProgress.currentGold, textStyle);
coinAmntLbl.setPosition(coinImage.getX() + coinImage.getWidth() + 3,
coinImage.getY() + (coinImage.getHeight() - coinAmntLbl.getHeight()) / 2);
uiStage.addActor(coinAmntLbl);
}
public CharacterSelectionScreen(DodgingHero _game) {
@@ -18,6 +18,7 @@
import com.coldwild.dodginghero.graph.SizeEvaluator;
import com.coldwild.dodginghero.graph.effects.WarningEffect;
import com.coldwild.dodginghero.logic.GameLogic;
import com.coldwild.dodginghero.logic.GameProgress;
import com.coldwild.dodginghero.logic.objects.Bonus;
import com.coldwild.dodginghero.logic.objects.Player;
@@ -158,6 +159,17 @@ private void DrawUI()
Align.right,
Color.WHITE);
batch.draw(game.res.coinBonus,
gameStage.getViewport().getScreenX() + 2,
gameStage.getViewport().getScreenY() + 5);
DrawShadowed("" + GameProgress.currentGold,
gameStage.getViewport().getScreenX() + game.res.coinBonus.getWidth() + 4,
gameStage.getViewport().getScreenY() + 8 + game.res.coinBonus.getHeight() / 2,
gameStage.getWidth() - 4,
Align.left,
Color.WHITE);
if (player.getLives() <= 0)
{
ShowGameResult("DEFEAT!");

0 comments on commit 6eb7930

Please sign in to comment.