Screen functionality
Basic screen functionality, working loading screen with asset loader and manager
This commit is contained in:
parent
61a10aa7e7
commit
fbd68c2169
17 changed files with 683 additions and 22 deletions
|
@ -1,15 +1,17 @@
|
|||
package com.game;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Game;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.game.Misc.Vars;
|
||||
import com.game.Managers.StateManager;
|
||||
import com.game.Screens.Loading;
|
||||
import com.game.Screens.Splash;
|
||||
|
||||
public class App extends ApplicationAdapter {
|
||||
public class App extends Game {
|
||||
|
||||
private float accum;
|
||||
|
||||
|
@ -22,10 +24,12 @@ public class App extends ApplicationAdapter {
|
|||
private OrthographicCamera hudCam;
|
||||
|
||||
// Managers
|
||||
private StateManager sm;
|
||||
private AssetManager assetManager;
|
||||
//private StateManager sm;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
assetManager = new AssetManager();
|
||||
|
||||
// Create batches
|
||||
sb = new SpriteBatch();
|
||||
|
@ -38,38 +42,40 @@ public class App extends ApplicationAdapter {
|
|||
hudCam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
||||
|
||||
// Create statemanager (Should always happen last)
|
||||
sm = new StateManager(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize (int width, int height) {
|
||||
//sm = new StateManager(this);
|
||||
this.setScreen(new Loading(this));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
super.render();
|
||||
accum += Gdx.graphics.getDeltaTime();
|
||||
|
||||
|
||||
/*accum += Gdx.graphics.getDeltaTime();
|
||||
while (accum >= Vars.STEP) {
|
||||
accum -= Vars.STEP;
|
||||
sm.handleInput();
|
||||
sm.update(Vars.STEP);
|
||||
sm.render();
|
||||
}
|
||||
}*/
|
||||
|
||||
if(Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { Gdx.app.exit(); }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
sm.dispose();
|
||||
sb.dispose();
|
||||
sr.dispose();
|
||||
super.dispose();
|
||||
|
||||
//sm.dispose();
|
||||
//sb.dispose();
|
||||
//sr.dispose();
|
||||
}
|
||||
|
||||
public SpriteBatch getSpriteBatch() { return sb; }
|
||||
public ShapeRenderer getSr() { return sr; }
|
||||
public StateManager getSm() { return sm; }
|
||||
//public StateManager getSm() { return sm; }
|
||||
public OrthographicCamera getCam() { return cam; }
|
||||
public OrthographicCamera getHudCam() { return hudCam; }
|
||||
public AssetManager getAssetManager() { return assetManager; }
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.game.Managers;
|
||||
|
||||
/**
|
||||
* Created by Ash on 10/02/2016.
|
||||
*/
|
||||
public class Assets {
|
||||
}
|
|
@ -11,6 +11,7 @@ public class Vars {
|
|||
public static final int SCREEN_WIDTH = 1280;
|
||||
public static final int SCREEN_HEIGHT = 720;
|
||||
public static final boolean RESIZABLE = false;
|
||||
public static final boolean VSYNC = true;
|
||||
public static final float FRAMERATE = 60;
|
||||
|
||||
// Physics related
|
||||
|
|
85
core/src/com/game/Screens/AbstractScreen.java
Normal file
85
core/src/com/game/Screens/AbstractScreen.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package com.game.Screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Screen;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.game.App;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public abstract class AbstractScreen implements Screen {
|
||||
|
||||
// App reference
|
||||
protected App app;
|
||||
|
||||
// Batches
|
||||
protected SpriteBatch sb;
|
||||
protected ShapeRenderer sr;
|
||||
|
||||
// Cameras
|
||||
protected OrthographicCamera cam;
|
||||
protected OrthographicCamera hudCam;
|
||||
|
||||
// Managers
|
||||
protected AssetManager assets;
|
||||
|
||||
// Stage
|
||||
protected Stage stage;
|
||||
|
||||
public AbstractScreen(final App app)
|
||||
{
|
||||
this.app = app;
|
||||
sb = app.getSpriteBatch();
|
||||
sr = app.getSr();
|
||||
cam = app.getCam();
|
||||
hudCam = app.getHudCam();
|
||||
assets = app.getAssetManager();
|
||||
stage = new Stage();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
|
||||
}
|
||||
|
||||
public abstract void update(float dt);
|
||||
|
||||
@Override
|
||||
public void render(float dt) {
|
||||
update(dt);
|
||||
Gdx.gl.glClearColor(0, 0, 0, 1f);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
stage.dispose();
|
||||
}
|
||||
}
|
7
core/src/com/game/Screens/Leaderboard.java
Normal file
7
core/src/com/game/Screens/Leaderboard.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package com.game.Screens;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public class Leaderboard {
|
||||
}
|
7
core/src/com/game/Screens/LevelSelect.java
Normal file
7
core/src/com/game/Screens/LevelSelect.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package com.game.Screens;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public class LevelSelect {
|
||||
}
|
72
core/src/com/game/Screens/Loading.java
Normal file
72
core/src/com/game/Screens/Loading.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
package com.game.Screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.game.App;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public class Loading extends AbstractScreen {
|
||||
|
||||
private Image logo;
|
||||
private float percent;
|
||||
|
||||
private Rectangle loadingRect;
|
||||
|
||||
public Loading(App app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
assets.load("textures/player.png", Texture.class);
|
||||
assets.finishLoading();
|
||||
|
||||
logo = new Image(assets.get("textures/player.png", Texture.class));
|
||||
logo.setPosition((stage.getWidth() / 2) - logo.getWidth() / 2, (stage.getHeight() / 1.5f) - logo.getHeight() / 2);
|
||||
// 853.3333
|
||||
loadingRect = new Rectangle(stage.getWidth() / 6f, (stage.getHeight() / 2f), 0, 25);
|
||||
|
||||
|
||||
assets.load("textures/badlogic.jpg", Texture.class);
|
||||
assets.load("textures/position0.png", Texture.class);
|
||||
assets.load("textures/position1.png", Texture.class);
|
||||
assets.load("textures/position2.png", Texture.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
percent = Interpolation.linear.apply(percent, assets.getProgress(), 0.1f);
|
||||
|
||||
loadingRect.width = 0 + 853.3333f * percent;
|
||||
|
||||
if (assets.update()) {
|
||||
if (Gdx.input.isTouched()) {
|
||||
app.setScreen(new Menu(app));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float dt) {
|
||||
super.render(dt);
|
||||
sr.begin(ShapeRenderer.ShapeType.Filled);
|
||||
sr.setColor(1, 0, 0, 1);
|
||||
sr.rect(loadingRect.x, loadingRect.y, loadingRect.width, loadingRect.height); // Red loading bar
|
||||
sr.end();
|
||||
|
||||
sb.begin();
|
||||
logo.draw(sb, 1f);
|
||||
sb.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
}
|
38
core/src/com/game/Screens/Menu.java
Normal file
38
core/src/com/game/Screens/Menu.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package com.game.Screens;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.game.App;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public class Menu extends AbstractScreen {
|
||||
|
||||
private TextureAtlas atlas;
|
||||
private Skin skin;
|
||||
|
||||
// Buttons
|
||||
private TextButton butPlay, butExit, butLeaderboard;
|
||||
|
||||
// Font
|
||||
|
||||
|
||||
|
||||
public Menu(App app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float dt)
|
||||
{
|
||||
super.render(dt);
|
||||
}
|
||||
|
||||
}
|
7
core/src/com/game/Screens/Play.java
Normal file
7
core/src/com/game/Screens/Play.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package com.game.Screens;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public class Play {
|
||||
}
|
31
core/src/com/game/Screens/Splash.java
Normal file
31
core/src/com/game/Screens/Splash.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package com.game.Screens;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.game.App;
|
||||
|
||||
/**
|
||||
* Created by Ash on 11/02/2016.
|
||||
*/
|
||||
public class Splash extends AbstractScreen {
|
||||
|
||||
public Splash(App app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
|
||||
stage.act(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float dt)
|
||||
{
|
||||
super.render(dt);
|
||||
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -2,31 +2,96 @@ package com.game.States;
|
|||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.*;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.game.Managers.StateManager;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.util.Random;
|
||||
|
||||
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
|
||||
|
||||
/**
|
||||
* Created by Ash on 08/02/2016.
|
||||
*/
|
||||
public class Menu extends State {
|
||||
|
||||
Random rand = new Random();
|
||||
int threshhold = 200;
|
||||
long lastChanged = 0;
|
||||
|
||||
private Image tempImage;
|
||||
|
||||
private TextureAtlas atlas;
|
||||
|
||||
private Skin skin;
|
||||
private Table table;
|
||||
|
||||
private TextButton butPlay, butExit, butLeaderboard;
|
||||
public BitmapFont font64;
|
||||
public FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/badaboom.TTF"));
|
||||
public FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
|
||||
private Label heading;
|
||||
|
||||
|
||||
public Menu(StateManager sm) {
|
||||
super(sm);
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
atlas = new TextureAtlas("spritesheets/uiskin.atlas");
|
||||
skin = new Skin(atlas);
|
||||
|
||||
parameter.size = 64;
|
||||
parameter.borderWidth = 2f;
|
||||
parameter.borderColor = Color.WHITE;
|
||||
parameter.color = Color.BLACK;
|
||||
font64 = generator.generateFont(parameter);
|
||||
|
||||
skin.add("default-font", font64);
|
||||
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
|
||||
|
||||
initButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
stage.act(dt);
|
||||
//genRandColour();
|
||||
|
||||
}
|
||||
|
||||
private void genRandColour()
|
||||
{
|
||||
if(System.currentTimeMillis() - lastChanged < threshhold) { return; }
|
||||
font64.setColor(new Color(
|
||||
rand.nextFloat() / 2f + 0.5f,
|
||||
rand.nextFloat() / 2f + 0.5f,
|
||||
rand.nextFloat() / 2f + 0.5f,
|
||||
1f
|
||||
));
|
||||
lastChanged = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
Gdx.gl.glClearColor(.25f, .25f, .25f, 1f);
|
||||
|
||||
stage.draw();
|
||||
|
||||
sb.begin();
|
||||
//font12.draw(sb, "Main menu", 200, 200);
|
||||
sb.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,6 +104,35 @@ public class Menu extends State {
|
|||
|
||||
@Override
|
||||
public void dispose() {
|
||||
stage.dispose();
|
||||
}
|
||||
|
||||
private void initButtons()
|
||||
{
|
||||
butPlay = new TextButton("Play", skin, "default");
|
||||
butPlay.setPosition(500, 260);
|
||||
butPlay.setSize(128, 40);
|
||||
butPlay.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
sm.setState(StateManager.States.PLAY);
|
||||
}
|
||||
});
|
||||
|
||||
butExit = new TextButton("Exit", skin, "default");
|
||||
butExit.setPosition(500, 110);
|
||||
butExit.setSize(128, 40);
|
||||
butExit.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
Gdx.app.exit();
|
||||
}
|
||||
});
|
||||
|
||||
butPlay.addAction(parallel(alpha(0), moveTo(stage.getWidth() / 2, stage.getHeight() / 2, 5f, Interpolation.pow5), sequence(alpha(0f), fadeIn(1.5f, Interpolation.pow2))));
|
||||
butExit.addAction(sequence(alpha(0f), fadeIn(2f, Interpolation.pow2)));
|
||||
|
||||
stage.addActor(butPlay);
|
||||
stage.addActor(butExit);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue