Commit 022e77bb authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#407 Added health indicators. Code refactoring.

parent 4bcbe2d6
......@@ -9,3 +9,5 @@ game_runes_minus=-5
game_runes_stats=Tvoje skóre\: [BLACK]{0}[]
game_runes_score_text=Score\:{0}/{1}
......@@ -5,4 +5,5 @@ game_runes_result_2=Runes result 2 \#todo
game_runes_result_3=Runes result 3 \#todo
game_runes_plus=+5
game_runes_minus=5
game_runes_stats=Tvoje skóre\: [BLACK]{0}[] \#todo
\ No newline at end of file
game_runes_stats=Tvoje skóre\: [BLACK]{0}[] \#todo
game_runes_score_text=Score\:{0}/{1}
......@@ -5,4 +5,5 @@ game_runes_result_2=Runes result 2 \#todo
game_runes_result_3=Runes result 3 \#todo
game_runes_plus=+5
game_runes_minus=5
game_runes_stats=Tvoje skóre\: [BLACK]{0}[] \#todo
\ No newline at end of file
game_runes_stats=Tvoje skóre\: [BLACK]{0}[] \#todo
game_runes_score_text=Score\:{0}/{1}
package cz.nic.tablexia.game.games.runes.actors;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.utils.Align;
import java.util.List;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.common.TablexiaRandom;
import cz.nic.tablexia.game.common.media.GfxLibrary;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.runes.assets.RuneDefinition;
import cz.nic.tablexia.game.games.runes.assets.RunesGameAssets;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.screen.loader.LoadingBar;
import cz.nic.tablexia.util.ui.TablexiaLabel;
/**
* Created by Vitaliy Vashchenko on 18.7.16.
*/
public class Sidebar extends Group {
private TargetPlate targetPlate;
private TimeBar timeBar;
private Label score;
private Image background;
private static final String SCORE_TEXT = "Score: "; // TODO: 18.7.16 move to texts & add translation
private static final String SCORE_TEXT_TOTAL = "/44";
public Sidebar(GfxLibrary gfxLibrary, GfxLibrary runesLibrary, TablexiaRandom tablexiaRandom, Texture timeBarFg, Texture timeBarBg, TimeBar.TimeBarCallback timeBarCallback) {
background = new Image(gfxLibrary.getTextureRegion(RunesGameAssets.SIDEBAR_BACKGROUND));
targetPlate = new TargetPlate(runesLibrary, tablexiaRandom);
targetPlate.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes());
score = new TablexiaLabel(SCORE_TEXT + 0 + SCORE_TEXT_TOTAL, new TablexiaLabel.TablexiaLabelStyle(ApplicationFontManager.FontType_NEW.BOLD_18, Color.BLACK));
score.setAlignment(Align.center);
timeBar = new TimeBar(new LoadingBar.LoadingBarSkin(timeBarFg, timeBarBg, Color.WHITE), timeBarCallback);
addActor(background);
background.setFillParent(true);
addActor(targetPlate);
addActor(timeBar);
addActor(score);
}
public void performTimeStep() {
timeBar.performStep();
}
public void changeTimeBarCurrentValue(float newValue) {
timeBar.setCurrentPercentage(newValue);
}
public void setSizes() {
targetPlate.init(0.9f * getWidth(), 0.5f * getHeight());
}
public void setPositions() {
targetPlate.setPosition(getWidth() / 2 - targetPlate.getWidth() / 2, getHeight() - targetPlate.getHeight());
score.setPosition(getWidth() / 2 - score.getWidth() / 2, 0);
timeBar.setPosition(getWidth() / 2 - timeBar.getWidth() / 2, score.getHeight() + 10);
}
public void changeActiveTargets(GameDifficulty gameDifficulty, int round) {
targetPlate.changeTargets(gameDifficulty, round);
}
public List<RuneDefinition> getActiveTargets() {
return targetPlate.getActiveTargets();
}
public boolean foundAllRunes() {
return targetPlate.getActiveTargets().size() == 0;
}
public void nextRound(GameDifficulty gameDifficulty, int round) {
timeBar.startGameState();
changeActiveTargets(gameDifficulty, round);
showTargets();
}
public boolean isTarget(RuneDefinition runeDefinition) {
return targetPlate.isTarget(runeDefinition);
}
public void restoreTimeBar(){
timeBar.restoreClock();
}
public void hideTargets() {
targetPlate.setVisible(false);
}
public void showTargets() {
targetPlate.setVisible(true);
}
public void hideTime() {
timeBar.setVisible(false);
}
public void showTime() {
timeBar.setVisible(true);
}
public void hideScore() {
score.setVisible(false);
}
public void showScore() {
score.setVisible(true);
}
public void hideAll() {
hideTargets();
hideTime();
hideScore();
}
public void showAll() {
showScore();
showTargets();
showTime();
}
public void changeScore(int score) {
this.score.setText(SCORE_TEXT + score + SCORE_TEXT_TOTAL);
}
public void removeTargetRune(RuneDefinition runeDefinition) {
targetPlate.hideTarget(runeDefinition);
targetPlate.removeTarget(runeDefinition);
}
}
......@@ -27,11 +27,10 @@ public class TargetPlate extends Group{
private TablexiaRandom tablexiaRandom;
private List<RuneDefinition> activeTargets = new ArrayList<RuneDefinition>();
public TargetPlate(GfxLibrary runesLibrary, TablexiaRandom tablexiaRandom) { // TODO: 18.7.16 rename class
public TargetPlate(GfxLibrary runesLibrary, TablexiaRandom tablexiaRandom) {
this.runesLibrary = runesLibrary;
this.tablexiaRandom = tablexiaRandom;
plate = new Group();
setVisible(false);
addActor(plate);
root = new Table();
root.defaults().pad(INNER_PAD);
......@@ -76,11 +75,9 @@ public class TargetPlate extends Group{
}
}
}
public void hideTarget(RuneDefinition rd) {
for (Actor actor : root.getChildren()){
if (((Rune)actor).getType().equals(rd)) actor.setVisible(false);
}
public boolean foundAllTargets() {
return activeTargets.size() == 0;
}
public boolean isTarget(RuneDefinition rd){
......@@ -88,9 +85,16 @@ public class TargetPlate extends Group{
}
public void removeTarget(RuneDefinition rd){
hideTarget(rd);
activeTargets.remove(rd);
}
public void hideTarget(RuneDefinition rd) {
for (Actor actor : root.getChildren()) {
if (((Rune) actor).getType().equals(rd)) actor.setVisible(false);
}
}
public List<RuneDefinition> getActiveTargets() {
return activeTargets;
}
......
......@@ -6,20 +6,20 @@ import cz.nic.tablexia.game.common.media.AssetDescription;
* Created by Vitaliy Vashchenko on 7.4.16.
*/
public enum RunesGameAssets implements AssetDescription {
// TODO: 1.6.16 change bg images
// TODO: 28.6.16 Fix bad runes images
SIDEBAR_BACKGROUND("sidebar-background"),
BACKGROUND("background"),
GLASS("hand-glass"),
BAR_FG("time-bar-fg"),
BAR_BG("time-bar-bg"),
BAR_BG_WHITE("time-bar-bg-white"),
RESULT_0("result0"),
RESULT_1("result1"),
RESULT_2("result2"),
RESULT_3("result3");
public static final RunesGameAssets[] TEXTURES = {BACKGROUND,SIDEBAR_BACKGROUND,BAR_BG,BAR_FG};
public static final RunesGameAssets[] SOUNDS = {RESULT_0,RESULT_1,RESULT_2,RESULT_3};
RESULT_3("result3"),
SCORE_TEXT("game_runes_score_text");
public static final RunesGameAssets[] TEXTURES = {BACKGROUND, SIDEBAR_BACKGROUND, GLASS, BAR_BG, BAR_FG};
public static final RunesGameAssets[] SOUNDS = {RESULT_0,RESULT_1,RESULT_2,RESULT_3};
private String path;
RunesGameAssets(String path) {
......
......@@ -14,16 +14,8 @@ import cz.nic.tablexia.game.games.runes.model.RunesGameProperties;
*/
public enum PositionDefinition {
//x,y, height, maxRunes
//x,y, max height, max runes
// POS1(0.1f, 0.42f),
// POS2(0.1f, 0.28f),
// POS3(0.1f, 0.14f),
// POS4(0.46f, 0.2f),
// POS5(0.46f, 0.36f),
// POS6(0.46f, 0.52f),
// POS7(0.66f, 0.39f),
// POS8(0.66f, 0.25f),
POS9(0.26f, 0.25f),
POS10(0.26f, 0.43f, 0.3f),
POS11(0.49f, 0.28f),
......@@ -44,10 +36,7 @@ public enum PositionDefinition {
private static final float FOLDED_SCALE = 0.6f;
private static final int MAX_RUNES = 6;
// TODO: 1.6.16 positions on new backgrounds
// public static final PositionDefinition[] MAP_EASY = {POS14, POS15, POS16};
// public static final PositionDefinition[] MAP_MEDIUM = {POS9, POS10, POS11, POS12, POS13};
public static final PositionDefinition[] MAP_EASY = {POS1, POS2, POS3, POS4, POS5, POS6, POS7}; // temporary, `till have some assets to work with.
public static final PositionDefinition[] MAP_EASY = {POS1, POS2, POS3, POS4, POS5, POS6, POS7};
public static final PositionDefinition[] MAP_MEDIUM = {POS1, POS2, POS3, POS4, POS5, POS6, POS7};
public static final PositionDefinition[] MAP_HARD = {POS1, POS2, POS3, POS4, POS5, POS6, POS7};
......
......@@ -7,12 +7,13 @@ import cz.nic.tablexia.game.difficulty.GameDifficulty;
*/
public class RunesGameProperties {
public static final String SCORE_TOTAL = "score_total";
public static final int GAME_TIME = 15;
public static final int GAME_ROUNDS = 12;
public static final int[] CUPS_EASY = {15, 26, 38};
public static final int[] CUPS_MEDIUM = {15, 26, 38};
public static final int[] CUPS_HARD = {15, 26, 38};
public static final int GAME_TIME = 15;
public static final int GAME_ROUNDS = 12;
public static final int RUNES_TO_FIND_TOTAL = 44;
public static final int[] CUPS_EASY = {15, 26, 38};
public static final int[] CUPS_MEDIUM = {15, 26, 38};
public static final int[] CUPS_HARD = {15, 26, 38};
public static final int[] GROUPS_EASY = {2,2,3,3,3,3,3,3,3,3,3,3};
public static final int[] GROUPS_MEDIUM = {2,2,3,3,3,3,4,4,4,5,5,5};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment