Skip to content

Commit

Permalink
#12 instanced screens
Browse files Browse the repository at this point in the history
  • Loading branch information
KOTerra committed Jan 19, 2023
1 parent 80b6037 commit 3f8b480
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
9 changes: 9 additions & 0 deletions StrafeOverdead/core/src/com/strafergame/GameState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.strafergame;

public enum GameState {
LOADING,
MENU,
PAUSE,
CUTSCENE,
PLAY;
}
26 changes: 24 additions & 2 deletions StrafeOverdead/core/src/com/strafergame/Strafer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.strafergame.game.world.GameWorld;
import com.strafergame.graphics.WorldCamera;
import com.strafergame.input.InputManager;
import com.strafergame.screens.GameScreen;
import com.strafergame.screens.LoadingScreen;
import com.strafergame.screens.TitleScreen;
import com.strafergame.ui.UiManager;

/**
Expand All @@ -38,6 +40,11 @@ public class Strafer extends Game {
*/
public static InputManager inputManager;

/**
* the current state of the game
*/
public static GameState gameState;

/**
* the time elapsed. used to retrieve time dependent data such as animation
* frames
Expand Down Expand Up @@ -89,6 +96,21 @@ public class Strafer extends Game {
*/
public static UiManager uiManager;

/**
* the loading screen
*/
public static LoadingScreen loadingScreen;

/**
* the title screen
*/
public static TitleScreen titleScreen;

/**
* the game screen
*/
public static GameScreen gameScreen;

/**
* stage that contains world entities
*/
Expand Down Expand Up @@ -130,8 +152,8 @@ public void create() {
uiManager = new UiManager(uiScreenViewport, spriteBatch);
uiManager.init();

setScreen(new LoadingScreen(this));

loadingScreen = new LoadingScreen(this);
setScreen(loadingScreen);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ public class GameWorld extends Stage implements Disposable {
private Player playerTest2;
private final TiledMap tiledMapTest = Strafer.assetManager.get("maps/test/map.tmx", TiledMap.class);

Strafer game;

Box2DWorld box2DWorld = new Box2DWorld();

public GameWorld() {
public GameWorld(Strafer game) {
super(Strafer.extendViewport, Strafer.spriteBatch);
this.game = game;

addTestAssets();
}
Expand Down Expand Up @@ -107,6 +110,9 @@ void debugControls() {
if (Gdx.input.isKeyPressed(Keys.NUMPAD_5)) {
playerTest1.getBody().setTransform(playerTest1.getX() + .5f, playerTest1.getY() + .5f, 0);
}
if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
game.setScreen(Strafer.titleScreen);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.math.MathUtils;
import com.strafergame.GameState;
import com.strafergame.Strafer;
import com.strafergame.graphics.AnimationProvider;

Expand All @@ -36,6 +37,7 @@ public class LoadingScreen implements Screen {

public LoadingScreen(final Strafer game) {
this.game = game;
Strafer.gameState = GameState.LOADING;
shapeRenderer = new ShapeRenderer();

queueAssetsToLoad();
Expand All @@ -56,8 +58,11 @@ private void update(float delta) {
if (progress >= Strafer.assetManager.getProgress() - .001f) {
if (Strafer.assetManager.isFinished()) {
AnimationProvider.prepareAnimations();
//game.setScreen(new GameScreen(game));
game.setScreen(new TitleScreen(game));
// game.setScreen(new GameScreen(game));
if (Strafer.titleScreen == null) {
Strafer.titleScreen = new TitleScreen(game);
}
game.setScreen(Strafer.titleScreen);
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions StrafeOverdead/core/src/com/strafergame/ui/UiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

public class UiManager extends Stage implements Disposable {

private HUD hud;

public UiManager(Viewport viewport, SpriteBatch spriteBatch) {
super(viewport, spriteBatch);

Expand All @@ -23,7 +21,6 @@ public void init() {
((InputMultiplexer) Gdx.input.getInputProcessor()).addProcessor(Strafer.uiManager);
VisUI.load(SkinScale.X2);

hud = new HUD();
}

@Override
Expand Down

0 comments on commit 3f8b480

Please sign in to comment.