From 7ea8ee3cae1e5ec559a2e884f14811deb468f1c3 Mon Sep 17 00:00:00 2001 From: Jeasonfire Date: Sun, 17 May 2015 20:43:36 +0300 Subject: [PATCH] Added splash screens. --- core/assets/splashscreens/libgdx.png | Bin 0 -> 2523 bytes core/assets/splashscreens/saltosion.png | Bin 0 -> 3522 bytes .../saltosion/gladiator/GladiatorBrawler.java | 4 +- .../gui/creators/IntroGUICreator.java | 55 ++++++++++++++++++ .../gladiator/gui/nodes/ImageNode.java | 11 +++- .../gladiator/level/LevelFactory.java | 4 +- .../saltosion/gladiator/state/IntroState.java | 51 ++++++++++++++++ .../gladiator/systems/RenderingSystem.java | 17 ++++-- .../com/saltosion/gladiator/util/Name.java | 3 + .../gladiator/util/SpriteLoader.java | 13 ++++- 10 files changed, 144 insertions(+), 14 deletions(-) create mode 100644 core/assets/splashscreens/libgdx.png create mode 100644 core/assets/splashscreens/saltosion.png create mode 100644 core/src/com/saltosion/gladiator/gui/creators/IntroGUICreator.java create mode 100644 core/src/com/saltosion/gladiator/state/IntroState.java diff --git a/core/assets/splashscreens/libgdx.png b/core/assets/splashscreens/libgdx.png new file mode 100644 index 0000000000000000000000000000000000000000..e272593d4a3b8ee02a5611d20de1d6ad76eb1461 GIT binary patch literal 2523 zcmeHJYgbce7LH00C>Rv9AonSO;gSTE(ts%ti^~APg)k`~7eNNefSD6Mbf#U>>-r3pN$HxbQ!CkkJ0pBb>+@y#-X&y*2)CKCqR({H$T45ojZ2nB7JVR6ip>B-D12^mQ+Mgl#J ziAqaiI{Tu0P#+}~9!`S6jDzu^xL6i-VPYY}F3hqp!OCPuNTAOi7gvT}Xqu;st#4bf zEq1Ml6|8UE%gL5@sz0e8D!nkVO-b52+e-72A6R9;=Ws`JM;B zjeEG2=UbA+UFx#3ewt;LEc|dSFH)1TbS=e9eSfgF4dLGJilP-=F@7kmt3_yRtyKap z$Vwqa0iNV35$+K3?)JlTM1Wb9uj;lUljxr=h2PmfHt6LxPafwSZ<|pa=VprhK5jd6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9@LowiS16D+MBQ!bOP z(Vt>CECsL!kiH@bg-M;VJ~=xKiQnTjbqZAzj$3Bd+oJP-W8r82yz-y-Z}I{~E#kGL ztov@RpUnM(UnzU*%%+wDkn>N>9qh8s}=@ALxguADSS)+W7+>#a9;&; Z%_y-WSDvE|Isf>{wYPDyuCeq@{x<}g{b&FH literal 0 HcmV?d00001 diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index 82e016b..ac79032 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -10,7 +10,7 @@ import com.saltosion.gladiator.input.InputHandler; import com.saltosion.gladiator.level.EntityFactory; import com.saltosion.gladiator.level.LevelFactory; import com.saltosion.gladiator.state.BaseState; -import com.saltosion.gladiator.state.MainMenuState; +import com.saltosion.gladiator.state.IntroState; import com.saltosion.gladiator.systems.AISystem; import com.saltosion.gladiator.systems.CombatSystem; import com.saltosion.gladiator.systems.MiscManagerSystem; @@ -57,7 +57,7 @@ public class GladiatorBrawler extends ApplicationAdapter { // Initialize states BaseState.setMainClass(this); - setState(new MainMenuState()); + setState(new IntroState()); Log.info("Successfully started the game."); } diff --git a/core/src/com/saltosion/gladiator/gui/creators/IntroGUICreator.java b/core/src/com/saltosion/gladiator/gui/creators/IntroGUICreator.java new file mode 100644 index 0000000..b31b9e9 --- /dev/null +++ b/core/src/com/saltosion/gladiator/gui/creators/IntroGUICreator.java @@ -0,0 +1,55 @@ +package com.saltosion.gladiator.gui.creators; + +import com.badlogic.gdx.graphics.g2d.Sprite; +import com.saltosion.gladiator.gui.nodes.ImageNode; +import com.saltosion.gladiator.gui.nodes.TextNode; +import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.Name; +import com.saltosion.gladiator.util.SpriteLoader; + +public class IntroGUICreator implements GUICreator { + + // These sprites should be loaded before the initialization of this class + private final Sprite[] splashScreens = {SpriteLoader.loadSprite(Name.SPLASH_SALTOSION), + SpriteLoader.loadSprite(Name.SPLASH_LIBGDX)}; + private int currentSplash = 0; + private ImageNode splash; + private TextNode loadingText; + + @Override + public void create() { + splash = new ImageNode("splash_image", splashScreens[currentSplash]); + splash.setPosition(0.5f, 0.5f); + AppUtil.guiManager.getRootNode().addChild(splash); + + loadingText = new TextNode("loading_text", "Loading"); + loadingText.setPosition(0.43f, 0.5f); + loadingText.setVisible(false); + AppUtil.guiManager.getRootNode().addChild(loadingText); + } + + /** + * @return Returns true if there is no next splash screen + */ + public boolean nextSplashScreen() { + currentSplash++; + if (currentSplash >= splashScreens.length) { + return true; + } + splash.setImage(splashScreens[currentSplash]); + return false; + } + + public int getCurrentSplashIndex() { + return currentSplash; + } + + public ImageNode getSplash() { + return splash; + } + + public TextNode getLoadingText() { + return loadingText; + } + +} diff --git a/core/src/com/saltosion/gladiator/gui/nodes/ImageNode.java b/core/src/com/saltosion/gladiator/gui/nodes/ImageNode.java index 51dbda1..1d1f19f 100644 --- a/core/src/com/saltosion/gladiator/gui/nodes/ImageNode.java +++ b/core/src/com/saltosion/gladiator/gui/nodes/ImageNode.java @@ -13,9 +13,9 @@ import com.saltosion.gladiator.gui.properties.ImageProperty; * @author somersby */ public class ImageNode extends GUINode implements ImageProperty { - + private Sprite image; - + public ImageNode(String ID, Sprite image) { super(ID); this.image = image; @@ -25,5 +25,10 @@ public class ImageNode extends GUINode implements ImageProperty { public Sprite getImage() { return this.image; } - + + public ImageNode setImage(Sprite image) { + this.image = image; + return this; + } + } diff --git a/core/src/com/saltosion/gladiator/level/LevelFactory.java b/core/src/com/saltosion/gladiator/level/LevelFactory.java index 4202470..4e4fc50 100644 --- a/core/src/com/saltosion/gladiator/level/LevelFactory.java +++ b/core/src/com/saltosion/gladiator/level/LevelFactory.java @@ -34,7 +34,7 @@ public class LevelFactory { audienceRO.playAnimation("Default-Animation"); audience.add(audienceRO); CPhysics audiencePO = new CPhysics().setMovable(false).setGravityApplied(false) - .setProcessCollisions(false).setGhost(true).setPosition(0, 10).setZParallax(9) + .setProcessCollisions(false).setGhost(true).setPosition(0, 10).setZParallax(10) .setSize(audienceSprite0.getRegionWidth() * Global.SPRITE_SCALE, audienceSprite0.getRegionHeight() * Global.SPRITE_SCALE); audience.add(audiencePO); @@ -49,7 +49,7 @@ public class LevelFactory { CRenderedObject wallRO = new CRenderedObject(wallSprite); wall.add(wallRO); CPhysics wallPO = new CPhysics().setMovable(false).setGravityApplied(false) - .setProcessCollisions(false).setGhost(true).setPosition(0, 2).setZParallax(1.5f) + .setProcessCollisions(false).setGhost(true).setPosition(0, 2).setZParallax(2) .setSize(wallSprite.getRegionWidth() * Global.SPRITE_SCALE, wallSprite.getRegionHeight() * Global.SPRITE_SCALE); wall.add(wallPO); diff --git a/core/src/com/saltosion/gladiator/state/IntroState.java b/core/src/com/saltosion/gladiator/state/IntroState.java new file mode 100644 index 0000000..18f44ea --- /dev/null +++ b/core/src/com/saltosion/gladiator/state/IntroState.java @@ -0,0 +1,51 @@ +package com.saltosion.gladiator.state; + +import com.saltosion.gladiator.gui.creators.IntroGUICreator; +import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.SpriteLoader; + +public class IntroState extends BaseState { + + private static final float SPLASH_DELAY = 5; + private IntroGUICreator guiCreator; + private float currentTime; + + @Override + public void create() { + // Start from a clean slate + AppUtil.guiManager.clearGUI(); + + SpriteLoader.preload(); + guiCreator = new IntroGUICreator(); + guiCreator.create(); + } + + @Override + public void update(float deltaTime) { + currentTime += deltaTime; + if (currentTime > SPLASH_DELAY) { + boolean finished = guiCreator.nextSplashScreen(); + if (finished && SpriteLoader.loadedAllSprites) { + setState(new MainMenuState()); + } else if (finished && !guiCreator.getLoadingText().isVisible()) { + guiCreator.getLoadingText().setVisible(true); + SpriteLoader.loadAll(); + } else if (!finished) { + currentTime = 0; + } + } + guiCreator.getSplash().getImage().setAlpha(getCurrentAlpha()); + } + + public float getCurrentAlpha() { + float f = Math.max(0, Math.min(1, currentTime / SPLASH_DELAY)); + return f < 0.5 ? f * 2 : 1 - ((f - 0.5f) * 2f); + } + + @Override + public void destroy() { + // Clear GUI so there's nothing leftover for the next state + AppUtil.guiManager.clearGUI(); + } + +} diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index 8c9a310..3e78ae2 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -63,6 +63,7 @@ public class RenderingSystem extends EntitySystem { private List drawableText; private Sprite[] healthbar; + private boolean healthbarLoaded = false; private float xMin = -15, xMax = 15; @Override @@ -84,11 +85,6 @@ public class RenderingSystem extends EntitySystem { fontCamera.setToOrtho(false, Global.FONT_SCALE, Global.FONT_SCALE); drawableText = new ArrayList(); - - healthbar = new Sprite[3]; - healthbar[0] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 0, 32, 8); - healthbar[1] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 1, 32, 8); - healthbar[2] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 2, 32, 8); } public void setViewport(int width, int height) { @@ -236,6 +232,9 @@ public class RenderingSystem extends EntitySystem { // Draw healthbars CCombat combat = cm.get(entities.get(i)); if (combat != null) { + if (!healthbarLoaded) { + loadHealthbarSprites(); + } float spriteWidth = healthbar[0].getWidth(); float spriteHeight = healthbar[0].getHeight(); float hp = (float) combat.getHealth() / (float) combat.getMaxHealth(); @@ -358,6 +357,14 @@ public class RenderingSystem extends EntitySystem { ComponentType.getBitsFor(CPhysics.class, CParticle.class), ComponentType.getBitsFor())); } + public void loadHealthbarSprites() { + healthbarLoaded = true; + healthbar = new Sprite[3]; + healthbar[0] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 0, 32, 8); + healthbar[1] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 1, 32, 8); + healthbar[2] = SpriteLoader.loadSprite(Name.HEALTHBARIMG, 0, 2, 32, 8); + } + public boolean getDebug() { return this.debug; } diff --git a/core/src/com/saltosion/gladiator/util/Name.java b/core/src/com/saltosion/gladiator/util/Name.java index 8d73b40..8cb9cfc 100644 --- a/core/src/com/saltosion/gladiator/util/Name.java +++ b/core/src/com/saltosion/gladiator/util/Name.java @@ -5,6 +5,9 @@ public class Name { public static final String GAME_NAME = "Gladiator Brawl"; public static final String DEBUG = "DEBUG"; + public static final String SPLASH_SALTOSION = "SPLASH_SALTOSION"; + public static final String SPLASH_LIBGDX = "SPLASH_LIBGDX"; + public static final String STATICPLAYER = "STATICPLAYER"; public static final String PLAYERIMG = "PLAYERIMG"; public static final String GROUNDIMG = "GROUNDIMG"; diff --git a/core/src/com/saltosion/gladiator/util/SpriteLoader.java b/core/src/com/saltosion/gladiator/util/SpriteLoader.java index 815b2f2..5449ccc 100644 --- a/core/src/com/saltosion/gladiator/util/SpriteLoader.java +++ b/core/src/com/saltosion/gladiator/util/SpriteLoader.java @@ -9,9 +9,15 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; public class SpriteLoader { - public static HashMap textures = new HashMap(); + private static final HashMap textures = new HashMap(); + public static boolean loadedAllSprites = false; - static { + public static void preload() { + loadTexture(Name.SPLASH_SALTOSION, "splashscreens/saltosion.png"); + loadTexture(Name.SPLASH_LIBGDX, "splashscreens/libgdx.png"); + } + + public static void loadAll() { loadTexture(Name.STATICPLAYER, "sprites/staticplayer.png"); loadTexture(Name.PLAYERIMG, "sprites/player/player.png"); loadTexture(Name.GROUNDIMG, "sprites/ground.png"); @@ -30,6 +36,7 @@ public class SpriteLoader { loadTexture(Name.MENU_BACKGROUND, "sprites/menu_background.png"); loadTexture(Name.GPLV3_LOGO, "sprites/gplv3_logo.png"); loadTexture(Name.OSI_LOGO, "sprites/osi_logo.png"); + loadedAllSprites = true; } /** @@ -62,7 +69,9 @@ public class SpriteLoader { /** * Load texture from path. * + * @param key * @param filePath + * @return */ public static Texture loadTexture(String key, String filePath) { Texture t = new Texture(Gdx.files.internal(filePath));