Added splash screens.

This commit is contained in:
Jeasonfire 2015-05-17 20:43:36 +03:00
parent b882b363ec
commit 7ea8ee3cae
10 changed files with 144 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -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.");
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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();
}
}

View File

@ -63,6 +63,7 @@ public class RenderingSystem extends EntitySystem {
private List<TextObject> 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<TextObject>();
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;
}

View File

@ -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";

View File

@ -9,9 +9,15 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class SpriteLoader {
public static HashMap<String, Texture> textures = new HashMap<String, Texture>();
private static final HashMap<String, Texture> textures = new HashMap<String, Texture>();
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));