Added level change text.

This commit is contained in:
Jeasonfire 2015-05-17 00:12:24 +03:00
parent 78d9890437
commit c5ad241dd3
7 changed files with 73 additions and 15 deletions

View File

@ -8,7 +8,9 @@ import com.saltosion.gladiator.util.Log;
import com.saltosion.gladiator.util.Name; import com.saltosion.gladiator.util.Name;
import com.saltosion.gladiator.util.SpriteLoader; import com.saltosion.gladiator.util.SpriteLoader;
public class TestGUICreator implements GUICreator { public class InGameGUICreator implements GUICreator {
private TextNode levelChangeText;
@Override @Override
public void create() { public void create() {
@ -33,6 +35,14 @@ public class TestGUICreator implements GUICreator {
TextNode text = new TextNode("test-text", "Test!"); TextNode text = new TextNode("test-text", "Test!");
text.setPosition(0.8f, 0.5f); text.setPosition(0.8f, 0.5f);
AppUtil.guiManager.getRootNode().addChild(text); AppUtil.guiManager.getRootNode().addChild(text);
levelChangeText = new TextNode("Level-Change-Text", "Level change");
levelChangeText.setPosition(0.4f, 0.5f);
AppUtil.guiManager.getRootNode().addChild(levelChangeText);
}
public TextNode getLevelChangeText() {
return this.levelChangeText;
} }
} }

View File

@ -4,9 +4,11 @@ import com.badlogic.gdx.math.Vector2;
import java.util.ArrayList; import java.util.ArrayList;
public class GUINode { public class GUINode {
private final Vector2 position; private final Vector2 position;
private final ArrayList<GUINode> children; private final ArrayList<GUINode> children;
private String ID = ""; private String ID = "";
private boolean visible = true;
public GUINode(String ID) { public GUINode(String ID) {
this.ID = ID; this.ID = ID;
@ -65,4 +67,14 @@ public class GUINode {
public String getID() { public String getID() {
return this.ID; return this.ID;
} }
public GUINode setVisible(boolean visible) {
this.visible = visible;
return this;
}
public boolean isVisible() {
return this.visible;
}
} }

View File

@ -16,4 +16,9 @@ public class TextNode extends GUINode implements TextProperty {
return text; return text;
} }
public TextNode setText(String text) {
this.text = text;
return this;
}
} }

View File

@ -2,6 +2,8 @@ package com.saltosion.gladiator.level;
public interface Level { public interface Level {
public String getLevelName();
public void generate(); public void generate();
} }

View File

@ -14,6 +14,11 @@ import com.saltosion.gladiator.util.SpriteSequence;
public class TestLevel implements Level { public class TestLevel implements Level {
@Override
public String getLevelName() {
return "Test level";
}
@Override @Override
public void generate() { public void generate() {
// Audience // Audience

View File

@ -1,8 +1,7 @@
package com.saltosion.gladiator.state; package com.saltosion.gladiator.state;
import com.saltosion.gladiator.gui.creators.GUICreator; import com.saltosion.gladiator.gui.creators.GUICreator;
import com.saltosion.gladiator.gui.creators.TestGUICreator; import com.saltosion.gladiator.gui.creators.InGameGUICreator;
import com.saltosion.gladiator.gui.nodes.ButtonNode;
import com.saltosion.gladiator.level.Level; import com.saltosion.gladiator.level.Level;
import com.saltosion.gladiator.level.TestLevel; import com.saltosion.gladiator.level.TestLevel;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
@ -10,7 +9,11 @@ import com.saltosion.gladiator.util.AppUtil;
public class InGameState extends BaseState { public class InGameState extends BaseState {
private Level level; private Level level;
private GUICreator guiCreator; private InGameGUICreator guiCreator;
private float timeSinceLevelChange;
private final float levelChangeTextDelay = 2;
private boolean levelChangeTextChanged = false;
@Override @Override
public void create() { public void create() {
@ -20,13 +23,31 @@ public class InGameState extends BaseState {
level = new TestLevel(); level = new TestLevel();
level.generate(); level.generate();
timeSinceLevelChange = 0;
guiCreator = new TestGUICreator(); guiCreator = new InGameGUICreator();
guiCreator.create(); guiCreator.create();
} }
@Override @Override
public void update(float deltaTime) { public void update(float deltaTime) {
if (timeSinceLevelChange < levelChangeTextDelay) {
timeSinceLevelChange += deltaTime;
if (!levelChangeTextChanged) {
guiCreator.getLevelChangeText().setVisible(true);
guiCreator.getLevelChangeText().setText(level.getLevelName());
levelChangeTextChanged = true;
}
} else {
guiCreator.getLevelChangeText().setVisible(false);
levelChangeTextChanged = false;
}
}
public void changeLevel(Level level) {
AppUtil.engine.removeAllEntities();
this.level = level;
this.timeSinceLevelChange = 0;
} }
@Override @Override

View File

@ -232,6 +232,9 @@ public class RenderingSystem extends EntitySystem {
} }
private void renderGUINode(GUINode node, Vector2 position) { private void renderGUINode(GUINode node, Vector2 position) {
if (!node.isVisible()) {
return;
}
position.add(node.getPosition()); position.add(node.getPosition());
if (node instanceof ImageProperty) { if (node instanceof ImageProperty) {
Sprite s = ((ImageProperty) node).getImage(); Sprite s = ((ImageProperty) node).getImage();