Permalink
Browse files

Lesson 20: chaging the player's sprite after hero selection

  • Loading branch information...
vladimirslav committed Dec 15, 2016
1 parent e46d43e commit 62d13eecf8b7d3a016d973276b7bf6af0c2515b0
@@ -5,6 +5,8 @@
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.coldwild.dodginghero.logic.objects.Character;
+import com.coldwild.dodginghero.logic.objects.CharacterRecord;
import java.util.HashMap;
@@ -28,6 +30,7 @@
public Sprite player;
public HashMap<Integer, Sprite> enemySprites;
+ public HashMap<String, Sprite> playerSprites;
public TextureRegion base;
public TextureRegion warning;
@@ -54,6 +57,13 @@ public Resources()
enemySprites.put(ENEMY_RANDOM, gameSprites.createSprite("slime"));
enemySprites.put(ENEMY_UNIVERSAL, gameSprites.createSprite("skeleton"));
+ playerSprites = new HashMap<String, Sprite>();
+ playerSprites.put(CharacterRecord.CHAR_NAME_HUMAN, gameSprites.createSprite("player"));
+ playerSprites.put(CharacterRecord.CHAR_NAME_SPIDER, gameSprites.createSprite("spider"));
+ playerSprites.put(CharacterRecord.CHAR_NAME_SKELETON, gameSprites.createSprite("skeleton"));
+ playerSprites.put(CharacterRecord.CHAR_NAME_GHOST, gameSprites.createSprite("ghost"));
+ playerSprites.put(CharacterRecord.CHAR_NAME_SLIME, gameSprites.createSprite("slime"));
+
base = gameSprites.findRegion("base");
warning = gameSprites.findRegion("warning");
@@ -13,6 +13,7 @@
public static int maxPlayerLives = 3;
public static int playerDamage = 1;
public static int currentLevel = 0;
+ public static int currentCharacter = 0;
private static final String PROGRESS_SAVE_NAME = "progress";
@@ -0,0 +1,38 @@
+package com.coldwild.dodginghero.logic.objects;
+
+/**
+ * Created by comrad_gremlin on 12/15/2016.
+ */
+
+public class CharacterRecord {
+
+ public final int levelsForHpUpgrade;
+ public final int levelsForHpRegenUpgrade;
+ public final int levelsForAttackUpgrade;
+ public final int levelsForBonusSpawnUpgrade;
+
+ public final String name;
+
+ public CharacterRecord(int lvlHp, int lvlRegen, int lvlAttack, int lvlBonus, String _name)
+ {
+ levelsForHpUpgrade = lvlHp;
+ levelsForHpRegenUpgrade = lvlRegen;
+ levelsForAttackUpgrade = lvlAttack;
+ levelsForBonusSpawnUpgrade = lvlBonus;
+ name = _name;
+ }
+
+ public static String CHAR_NAME_HUMAN = "Human";
+ public static String CHAR_NAME_SPIDER = "Spider";
+ public static String CHAR_NAME_SKELETON = "Mr.Skeletal";
+ public static String CHAR_NAME_GHOST = "Ghost";
+ public static String CHAR_NAME_SLIME = "Slimey";
+
+ public static CharacterRecord CHARACTERS[] = {
+ new CharacterRecord(2, 2, 4, 4, CHAR_NAME_HUMAN),
+ new CharacterRecord(3, 6, 3, 3, CHAR_NAME_SPIDER),
+ new CharacterRecord(6, 12, 1, 3, CHAR_NAME_SKELETON),
+ new CharacterRecord(4, 4, 2, 4, CHAR_NAME_GHOST),
+ new CharacterRecord(3, 3, 4, 1, CHAR_NAME_SLIME)
+ };
+}
@@ -25,7 +25,8 @@ public Player(int fx, int fy, Resources res, int _lives)
super(_lives);
fieldX = fx;
fieldY = fy;
- set(res.player);
+ //set(res.player);
+ set(res.playerSprites.get(CharacterRecord.CHARACTERS[GameProgress.currentCharacter].name));
max_lives = GameProgress.maxPlayerLives;
}
@@ -10,6 +10,8 @@
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.coldwild.dodginghero.DodgingHero;
+import com.coldwild.dodginghero.logic.GameProgress;
+import com.coldwild.dodginghero.logic.objects.CharacterRecord;
/**
* Created by comrad_gremlin on 12/12/2016.
@@ -18,7 +20,6 @@
public class CharacterSelectionScreen extends DefaultScreen {
Stage uiStage;
- int currentCharacter;
void prepareUi()
{
@@ -40,24 +41,54 @@ public void touchUp (InputEvent event, float x, float y, int pointer, int button
uiStage.addActor(startButton);
- Image heroSprite = new Image(game.res.player);
+ Image heroSprite = new Image(
+ game.res.playerSprites.get(CharacterRecord.CHARACTERS[GameProgress.currentCharacter].name)
+ );
+
heroSprite.setPosition((uiStage.getWidth() - heroSprite.getWidth()) / 2,
(uiStage.getHeight() - heroSprite.getHeight()) / 2);
uiStage.addActor(heroSprite);
TextButton nextButton = new TextButton(">>>", buttonStyle);
+ nextButton.addListener(new ClickListener()
+ {
+ @Override
+ public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
+ GameProgress.currentCharacter += 1;
+ if (GameProgress.currentCharacter == CharacterRecord.CHARACTERS.length)
+ {
+ GameProgress.currentCharacter = 0;
+ }
+
+ uiStage.clear();
+ prepareUi();
+ }
+ });
nextButton.setPosition(uiStage.getWidth() * 5 / 6 - nextButton.getWidth() /2,
uiStage.getHeight() / 2);
uiStage.addActor(nextButton);
TextButton prevButton = new TextButton("<<<", buttonStyle);
+ prevButton.addListener(new ClickListener()
+ {
+ @Override
+ public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
+ GameProgress.currentCharacter -= 1;
+ if (GameProgress.currentCharacter < 0)
+ {
+ GameProgress.currentCharacter = CharacterRecord.CHARACTERS.length - 1;
+ }
+
+ uiStage.clear();
+ prepareUi();
+ }
+ });
prevButton.setPosition(uiStage.getWidth() / 6, uiStage.getHeight() / 2);
uiStage.addActor(prevButton);
}
public CharacterSelectionScreen(DodgingHero _game) {
super(_game);
- currentCharacter = 0;
FitViewport viewport = new FitViewport(160, 120);
uiStage = new Stage(viewport);

0 comments on commit 62d13ee

Please sign in to comment.