Skip to content
Snippets Groups Projects
Commit 7f9605e2 authored by Matyáš Latner's avatar Matyáš Latner
Browse files

#5 Color backgrounds for creatures

parent 1ba886a1
No related branches found
No related tags found
No related merge requests found
......@@ -35,38 +35,50 @@ public class GameScreen extends ScreenAdapter {
private class GameBackground extends Actor {
private Texture backgroundTexture;
private Texture sceneHelperTexture;
private Texture texture;
public GameBackground() {
backgroundTexture = BankRoberryAssetManager.getInstance().get(BankRoberryAssetManager.SCREEN_BACKGROUND_S5, Texture.class);
backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
sceneHelperTexture = BankRoberryAssetManager.getInstance().get(BankRoberryAssetManager.SCREEN_NEWSSTAND_BOTTOM_S5, Texture.class);
sceneHelperTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
texture = BankRoberryAssetManager.getInstance().get(BankRoberryAssetManager.SCREEN_BACKGROUND_S5, Texture.class);
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.disableBlending();
batch.draw(backgroundTexture, getX(), getY(), Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.draw(texture, getX(), getY(), Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.enableBlending();
batch.draw(sceneHelperTexture, getX(), getY(), Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}
private class FloorBackground extends Actor {
private Texture texture;
public FloorBackground() {
texture = BankRoberryAssetManager.getInstance().get(BankRoberryAssetManager.SCREEN_NEWSSTAND_BOTTOM_S5, Texture.class);
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(texture, getX(), getY(), Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}
private class GameForeground extends Actor {
private Texture sceneTexture;
private Texture texture;
public GameForeground() {
sceneTexture = BankRoberryAssetManager.getInstance().get(BankRoberryAssetManager.SCREEN_NEWSSTAND_S5, Texture.class);
sceneTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
texture = BankRoberryAssetManager.getInstance().get(BankRoberryAssetManager.SCREEN_NEWSSTAND_S5, Texture.class);
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(sceneTexture, getX(), getY(), Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.draw(texture, getX(), getY(), Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}
......@@ -91,21 +103,51 @@ public class GameScreen extends ScreenAdapter {
}
private static class ColorInfoBanner extends Actor {
private Texture texture;
public ColorInfoBanner(Color color) {
setColor(color);
texture = BankRoberryAssetManager.getInstance().get(BankRoberryAssetManager.CREATURE_BACKGROUND_TEXTURE, Texture.class);
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
setSize(texture.getWidth(), texture.getHeight());
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.setColor(getColor());
batch.draw(texture, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false);
batch.setColor(1f, 1f, 1f, 1f);
}
}
private enum InfoItem {
ARRESTED (new GenericInfoItem(BankRoberryAssetManager.INFOITEM_ARRESTED)),
INNOCENCE (new GenericInfoItem(BankRoberryAssetManager.INFOITEM_INNOCENCE)),
ALARM (new GenericInfoItem(BankRoberryAssetManager.INFOITEM_ALARM));
ARRESTED (new GenericInfoItem(BankRoberryAssetManager.INFOITEM_ARRESTED), COLOR_OK),
INNOCENCE (new GenericInfoItem(BankRoberryAssetManager.INFOITEM_INNOCENCE), COLOR_KO),
ALARM (new GenericInfoItem(BankRoberryAssetManager.INFOITEM_ALARM), null);
private final GenericInfoItem infoItem;
private final GenericInfoItem infoItem;
private ColorInfoBanner infoBanner;
private InfoItem(GenericInfoItem infoItem) {
private InfoItem(GenericInfoItem infoItem, Color color) {
this.infoItem = infoItem;
if (color != null) {
this.infoBanner = new ColorInfoBanner(color);
}
}
public void show() {
for (InfoItem container : InfoItem.values()) {
container.infoItem.setVisible(false);
if (container.infoBanner != null) {
container.infoBanner.setVisible(false);
}
}
if (infoBanner != null) {
infoBanner.setVisible(true);
}
infoItem.addAction(alpha(0));
infoItem.addAction(scaleTo(INFOITEM_INITIAL_SCALE, INFOITEM_INITIAL_SCALE));
......@@ -115,6 +157,9 @@ public class GameScreen extends ScreenAdapter {
}
public void hide() {
if (infoBanner != null && infoBanner.isVisible()) {
infoBanner.setVisible(false);
}
if (infoItem.isVisible()) {
infoItem.addAction(sequence(parallel(fadeOut(INFOITEM_HIDE_DURATION, INFOITEM_HIDE_INTERPOLATION),
scaleTo(INFOITEM_INITIAL_SCALE, INFOITEM_INITIAL_SCALE, INFOITEM_HIDE_DURATION, INFOITEM_HIDE_INTERPOLATION)),
......@@ -128,11 +173,17 @@ public class GameScreen extends ScreenAdapter {
}
}
public static void init(Stage stage) {
calculateDimensions(stage.getWidth(), stage.getHeight());
public static void init(Group infoItemLayer, Group colorInfoLayer) {
calculateDimensions(infoItemLayer.getStage().getWidth(), infoItemLayer.getStage().getHeight());
for (InfoItem container : InfoItem.values()) {
container.infoItem.setVisible(false);
stage.addActor(container.infoItem);
infoItemLayer.addActor(container.infoItem);
if (container.infoBanner != null) {
container.infoBanner.setSize(colorInfoLayer.getStage().getWidth() * COLORBANNER_WIDTH_RATIO, colorInfoLayer.getStage().getHeight());
container.infoBanner.setPosition(colorInfoLayer.getStage().getWidth() * COLORBANNER_X_POSITION_RATIO, 0);
container.infoBanner.setVisible(false);
colorInfoLayer.addActor(container.infoBanner);
}
}
}
......@@ -151,6 +202,11 @@ public class GameScreen extends ScreenAdapter {
}
private static final Color COLOR_OK = Color.valueOf("39b54aff");
private static final Color COLOR_KO = Color.valueOf("c1272dff");
private static final float COLORBANNER_X_POSITION_RATIO = 1f/2;
private static final float COLORBANNER_WIDTH_RATIO = 1f/3;
private static final float INFOITEM_POSITION_Y_RATIO = 3f/7;
private static final float INFOITEM_POSITION_X_RATIO = 11f/36;
private static final Interpolation INFOITEM_HIDE_INTERPOLATION = Interpolation.pow4In;
......@@ -176,6 +232,7 @@ public class GameScreen extends ScreenAdapter {
private final static Interpolation CREATURE_MIDDLE_INTERPOLATION = Interpolation.pow4In;
private final static Interpolation CREATURE_FINISH_INTERPOLATION = Interpolation.linear;
private final Group colorInfoLayer = new Group();
private final Group creatureLayer = new Group();
private final Group infoItemLayer = new Group();
......@@ -198,13 +255,15 @@ public class GameScreen extends ScreenAdapter {
Gdx.input.setInputProcessor(stage);
stage.addActor(new GameBackground());
stage.addActor(colorInfoLayer);
stage.addActor(new FloorBackground());
stage.addActor(creatureLayer);
stage.addActor(new GameForeground());
stage.addActor(infoItemLayer);
stage.setDebugAll(true);
InfoItem.init(stage);
InfoItem.init(infoItemLayer, colorInfoLayer);
prepareCreaturePositions(stage.getViewport().getWorldWidth(), stage.getViewport().getWorldHeight());
showNextCreature(BankRoberryGameDataManager.getInstance().getResult());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment