Increased performance (Huge Refactor)

This commit is contained in:
Ash Reynolds 2016-02-12 23:23:59 +00:00
parent 3553152649
commit cfb59a3c4a
23 changed files with 210 additions and 368 deletions

View file

@ -1,15 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="50" height="8" tilewidth="64" tileheight="64" nextobjectid="24">
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="50" height="8" tilewidth="64" tileheight="64" nextobjectid="25">
<tileset firstgid="1" name="platformSet" tilewidth="64" tileheight="64" tilecount="3" columns="3">
<image source="../spritesheets/platformSet.png" width="192" height="64"/>
</tileset>
<tileset firstgid="4" name="player" tilewidth="64" tileheight="64" tilecount="1" columns="1">
<image source="../textures/player.png" width="64" height="64"/>
</tileset>
<layer name="PLATFORM" width="50" height="8">
<data encoding="base64" compression="zlib">
eJztk8EKACAIQzX//5/rOEKWktGhHgxPy5kl8qmggSLokE31FprsH53xFYyIeRAVvofV+dmdNEcMdYS5mA/rLl6GarJ/OeLP3PVJsH/03bLsHTB3AJM=
</data>
</layer>
<objectgroup name="PLAYER">
<object id="19" gid="3" x="64" y="320" width="64" height="64"/>
<object id="24" gid="4" x="0" y="320" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<object id="23" x="0" y="-192">

View file

@ -1,19 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="50" height="8" tilewidth="64" tileheight="64" nextobjectid="22">
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="50" height="8" tilewidth="64" tileheight="64" nextobjectid="25">
<tileset firstgid="1" name="platformSet" tilewidth="64" tileheight="64" tilecount="3" columns="3">
<image source="../spritesheets/platformSet.png" width="192" height="64"/>
</tileset>
<tileset firstgid="4" name="player" tilewidth="64" tileheight="64" tilecount="1" columns="1">
<image source="../textures/player.png" width="64" height="64"/>
</tileset>
<layer name="PLATFORM" width="50" height="8">
<data encoding="base64" compression="zlib">
eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk=
</data>
</layer>
<objectgroup name="PLAYER">
<object id="19" gid="3" x="64" y="320" width="64" height="64"/>
<object id="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<object id="21" x="-64" y="-192">
<polyline points="0,64 0,832 3392,832 3392,64 0,64"/>
<object id="21" x="0" y="-277.333">
<polyline points="0,85.3333 0,1109.33 3328,1109.33 3328,85.3333 0,85.3333"/>
</object>
</objectgroup>
</map>

View file

@ -1,199 +0,0 @@
uiskin.png
size: 256,128
format: RGBA8888
filter: Linear,Linear
repeat: none
check-off
rotate: false
xy: 11, 5
size: 14, 14
orig: 14, 14
offset: 0, 0
index: -1
textfield
rotate: false
xy: 11, 5
size: 14, 14
split: 3, 3, 3, 3
orig: 14, 14
offset: 0, 0
index: -1
check-on
rotate: false
xy: 125, 35
size: 14, 14
orig: 14, 14
offset: 0, 0
index: -1
cursor
rotate: false
xy: 23, 1
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
offset: 0, 0
index: -1
default
rotate: false
xy: 1, 50
size: 254, 77
orig: 254, 77
offset: 0, 0
index: -1
default-pane
rotate: false
xy: 11, 1
size: 5, 3
split: 1, 1, 1, 1
orig: 5, 3
offset: 0, 0
index: -1
default-rect-pad
rotate: false
xy: 11, 1
size: 5, 3
split: 1, 1, 1, 1
orig: 5, 3
offset: 0, 0
index: -1
default-pane-noborder
rotate: false
xy: 170, 44
size: 1, 1
split: 0, 0, 0, 0
orig: 1, 1
offset: 0, 0
index: -1
default-rect
rotate: false
xy: 38, 25
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
offset: 0, 0
index: -1
default-rect-down
rotate: false
xy: 170, 46
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
offset: 0, 0
index: -1
default-round
rotate: false
xy: 112, 29
size: 12, 20
split: 5, 5, 5, 4
pad: 4, 4, 1, 1
orig: 12, 20
offset: 0, 0
index: -1
default-round-down
rotate: false
xy: 99, 29
size: 12, 20
split: 5, 5, 5, 4
pad: 4, 4, 1, 1
orig: 12, 20
offset: 0, 0
index: -1
default-round-large
rotate: false
xy: 57, 29
size: 20, 20
split: 5, 5, 5, 4
orig: 20, 20
offset: 0, 0
index: -1
default-scroll
rotate: false
xy: 78, 29
size: 20, 20
split: 2, 2, 2, 2
orig: 20, 20
offset: 0, 0
index: -1
default-select
rotate: false
xy: 29, 29
size: 27, 20
split: 4, 14, 4, 4
orig: 27, 20
offset: 0, 0
index: -1
default-select-selection
rotate: false
xy: 26, 16
size: 3, 3
split: 1, 1, 1, 1
orig: 3, 3
offset: 0, 0
index: -1
default-slider
rotate: false
xy: 29, 20
size: 8, 8
split: 2, 2, 2, 2
orig: 8, 8
offset: 0, 0
index: -1
default-slider-knob
rotate: false
xy: 1, 1
size: 9, 18
orig: 9, 18
offset: 0, 0
index: -1
default-splitpane
rotate: false
xy: 17, 1
size: 5, 3
split: 0, 5, 0, 0
orig: 5, 3
offset: 0, 0
index: -1
default-splitpane-vertical
rotate: false
xy: 125, 29
size: 3, 5
split: 0, 0, 0, 5
orig: 3, 5
offset: 0, 0
index: -1
default-window
rotate: false
xy: 1, 20
size: 27, 29
split: 4, 3, 20, 3
orig: 27, 29
offset: 0, 0
index: -1
selection
rotate: false
xy: 174, 48
size: 1, 1
orig: 1, 1
offset: 0, 0
index: -1
tree-minus
rotate: false
xy: 140, 35
size: 14, 14
orig: 14, 14
offset: 0, 0
index: -1
tree-plus
rotate: false
xy: 155, 35
size: 14, 14
orig: 14, 14
offset: 0, 0
index: -1
white
rotate: false
xy: 129, 31
size: 3, 3
orig: 3, 3
offset: 0, 0
index: -1

View file

@ -6,8 +6,7 @@ com.badlogic.gdx.graphics.Color: {
black: { a: 1, b: 0, g: 0, r: 0 },
},
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
default: { down: default-round-down, up: default-round, font: default-font, fontColor: white, overFontColor: red },
toggle: { down: default-round-down, up: default-round, checked: default-round-down, font: default-font, fontColor: white, downFontColor: red }
default: { down: null, up: null, font: default-font, fontColor: white, overFontColor: red },
},
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: { font: default-font, fontColor: white }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

View file

@ -1,4 +1,4 @@
package com.game.Actor;
package com.game.actor;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;

View file

@ -1,4 +1,4 @@
package com.game.Actor;
package com.game.actor;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import static com.game.Misc.Vars.PPM;
import static com.game.misc.Vars.PPM;
/**
* Created by Ash on 09/02/2016.

View file

@ -1,9 +1,9 @@
package com.game.Actor.Object;
package com.game.actor.object;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.game.Misc.Vars;
import com.game.misc.Vars;
/**
* Created by Ash on 09/02/2016.

View file

@ -1,10 +1,10 @@
package com.game.Actor;
package com.game.actor;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.game.Misc.Box2dUtils;
import com.game.misc.Box2dUtils;
import static com.game.Misc.Vars.PPM;
import static com.game.misc.Vars.PPM;
/**
* Created by Ash on 08/02/2016.

View file

@ -1,13 +1,13 @@
package com.game.Actor;
package com.game.actor;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.game.Misc.Box2dUtils;
import com.game.Misc.Vars;
import com.game.misc.Box2dUtils;
import com.game.misc.Vars;
import static com.game.Misc.Vars.PPM;
import static com.game.misc.Vars.PPM;
/**
* Created by Ash on 08/02/2016.

View file

@ -4,84 +4,58 @@ 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.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.game.Misc.Vars;
import com.game.Screens.Loading;
import com.game.Screens.Menu;
import com.game.managers.ScreenManager;
import com.game.screens.Menu;
public class App extends Game {
private float accum;
// Managers
public AssetManager assets;
public ScreenManager sm;
// Batches
private SpriteBatch sb;
private ShapeRenderer sr;
public SpriteBatch sb;
public ShapeRenderer sr;
// Cameras
//private OrthographicCamera cam;
//private OrthographicCamera hudCam;
// Managers
private AssetManager assetManager;
//private StateManager sm;
@Override
public void create() {
assetManager = new AssetManager();
// Create managers
assets = new AssetManager();
sm = new ScreenManager(this);
// Create batches
sb = new SpriteBatch();
sr = new ShapeRenderer();
sr.setAutoShapeType(true);
// Create Main + HUD cameras
//cam = new OrthographicCamera();
//cam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
//hudCam = new OrthographicCamera();
//hudCam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
this.setScreen(new Loading(this));
sm.setScreen(ScreenManager.Screen.LOADING);
}
@Override
public void render () {
super.render();
if(Gdx.input.isKeyPressed(Input.Keys.M))
{
this.setScreen(new Menu(this));
}
/*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 () {
super.dispose();
assetManager.dispose();
sb.dispose();
sr.dispose();
assets.dispose();
sm.dispose();
}
public SpriteBatch getSpriteBatch() { return sb; }
public ShapeRenderer getSr() { return sr; }
//public OrthographicCamera getCam() { return cam; }
//public OrthographicCamera getHudCam() { return hudCam; }
public AssetManager getAssetManager() { return assetManager; }
public AssetManager getAssetManager() { return assets; }
}

View file

@ -1,9 +1,9 @@
package com.game.Misc;
package com.game.misc;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import static com.game.Misc.Vars.PPM;
import static com.game.misc.Vars.PPM;
/**
* Created by Ash on 09/02/2016.

View file

@ -1,4 +1,4 @@
package com.game.Misc;
package com.game.misc;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.math.Vector2;

View file

@ -1,7 +1,7 @@
package com.game.Misc;
package com.game.misc;
import com.badlogic.gdx.math.Vector2;
import com.game.Actor.Object.Background;
import com.game.actor.object.Background;
/**
* Created by Ash on 09/02/2016.

View file

@ -1,4 +1,4 @@
package com.game.Misc;
package com.game.misc;
import com.badlogic.gdx.math.Vector2;

View file

@ -1,15 +1,14 @@
package com.game.Screens;
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.math.Matrix4;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.game.App;
import com.game.Misc.Vars;
import com.game.misc.Vars;
/**
* Created by Ash on 11/02/2016.
@ -19,38 +18,38 @@ public abstract class AbstractScreen implements Screen {
// App reference
protected App app;
// Batches
/*// Manager references
protected AssetManager assets;
// Batch references
protected SpriteBatch sb;
protected ShapeRenderer sr;
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 = new OrthographicCamera();
cam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
hudCam = new OrthographicCamera();
hudCam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
assets = app.getAssetManager();
stage = new Stage();
this.stage = new Stage();
}
@Override
public void show() {
System.out.println("Showing screen: " + this.getClass().getSimpleName());
Gdx.input.setInputProcessor(stage);
}
@ -62,13 +61,14 @@ public abstract class AbstractScreen implements Screen {
update(dt);
Gdx.gl.glClearColor(0, 0, 0, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
app.sb.setProjectionMatrix(cam.combined);
}
public abstract void handleInput();
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
@Override
@ -83,11 +83,12 @@ public abstract class AbstractScreen implements Screen {
@Override
public void hide() {
Gdx.input.setInputProcessor(null);
}
@Override
public void dispose() {
stage.dispose();
System.out.println("Disposing screen: " + this.getClass().getSimpleName());
}
}

View file

@ -1,10 +1,13 @@
package com.game.Screens;
package com.game.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.game.App;
import com.game.managers.ScreenManager;
/**
* Created by Ash on 11/02/2016.
@ -33,15 +36,15 @@ public class Leaderboard extends AbstractScreen {
public void render(float dt) {
super.render(dt);
sb.begin();
sb.draw(assets.get("textures/leaderboardBackground.jpg", Texture.class), 0, 0);
assets.get("badaboom25.ttf", BitmapFont.class).draw(sb,"Press M to go back to menu", 100, 100);
sb.end();
app.sb.begin();
app.sb.draw(app.assets.get("textures/leaderboardBackground.jpg", Texture.class), 0, 0);
app.assets.get("badaboom25.ttf", BitmapFont.class).draw(app.sb,"Press M to go back to menu", 100, 100);
app.sb.end();
}
@Override
public void handleInput() {
if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { app.sm.setScreen(ScreenManager.Screen.MENU); }
}
@Override

View file

@ -1,4 +1,4 @@
package com.game.Screens;
package com.game.screens;
/**
* Created by Ash on 11/02/2016.

View file

@ -1,6 +1,5 @@
package com.game.Screens;
package com.game.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.audio.Music;
@ -16,17 +15,16 @@ import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.game.App;
import com.game.managers.ScreenManager;
/**
* Created by Ash on 11/02/2016.
*/
public class Loading extends AbstractScreen {
private Image logo;
private float percent;
private Rectangle loadingRect;
private Texture logo;
public Loading(App app) {
super(app);
@ -35,17 +33,17 @@ public class Loading extends AbstractScreen {
@Override
public void show() {
super.show();
FileHandleResolver resolver = new InternalFileHandleResolver();
assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
assets.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
app.assets.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
app.assets.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
loadFont("fonts/badaboom.TTF", 60, Color.BLACK);
assets.load("textures/player.png", Texture.class);
assets.finishLoading(); // make sure player texture and font is loaded
app.assets.load("textures/player.png", Texture.class);
app.assets.finishLoading(); // make sure player texture and font is loaded
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);
logo = app.assets.get("textures/player.png", Texture.class);
loadingRect = new Rectangle(stage.getWidth() / 6f, (stage.getHeight() / 2f - 25), 0, 25);
assetsToLoad();
@ -53,12 +51,12 @@ public class Loading extends AbstractScreen {
@Override
public void update(float dt) {
percent = Interpolation.linear.apply(percent, assets.getProgress(), 0.3f);
percent = Interpolation.linear.apply(percent, app.assets.getProgress(), 0.3f);
loadingRect.width = 0 + 853.3333f * percent;
if (assets.update() && loadingRect.width >= 852f) { // continue to menu screen when all assets have loaded
app.setScreen(new Menu(app));
if (app.assets.update() && loadingRect.width >= 852f) { // continue to menu screen when all assets have loaded
app.sm.setScreen(ScreenManager.Screen.MENU);
}
}
@ -66,17 +64,18 @@ public class Loading extends AbstractScreen {
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.set(ShapeRenderer.ShapeType.Line);
sr.rect(loadingRect.x, loadingRect.y, 853.3333f, loadingRect.height); // Outline
sr.end();
// Loading bar
app.sr.begin(ShapeRenderer.ShapeType.Filled);
app.sr.setColor(1, 0, 0, 1);
app.sr.rect(loadingRect.x, loadingRect.y, loadingRect.width, loadingRect.height); // Red loading bar
app.sr.set(ShapeRenderer.ShapeType.Line);
app.sr.rect(loadingRect.x, loadingRect.y, 853.3333f, loadingRect.height); // Outline
app.sr.end();
sb.begin();
assets.get("badaboom60.ttf", BitmapFont.class).draw(sb, "Loading", stage.getWidth() / 2 - 80, loadingRect.y + 80);
logo.draw(sb, 1f);
sb.end();
app.sb.begin();
app.assets.get("badaboom60.ttf", BitmapFont.class).draw(app.sb, "Loading", stage.getWidth() / 2 - 80, loadingRect.y + 80);
app.sb.draw(logo, (stage.getWidth() / 2) - logo.getWidth() / 2, (stage.getHeight() / 1.5f) - logo.getHeight() / 2);
app.sb.end();
}
@Override
@ -87,6 +86,7 @@ public class Loading extends AbstractScreen {
@Override
public void dispose() {
super.dispose();
logo.dispose();
}
private void assetsToLoad()
@ -96,16 +96,16 @@ public class Loading extends AbstractScreen {
loadFont("fonts/badaboom.TTF", 45, Color.BLACK);
assets.load("textures/badlogic.jpg", Texture.class);
assets.load("textures/menuBackground.jpg", Texture.class);
assets.load("textures/leaderboardBackground.jpg", Texture.class);
assets.load("textures/position0.png", Texture.class);
assets.load("textures/position1.png", Texture.class);
assets.load("textures/position2.png", Texture.class);
app.assets.load("textures/badlogic.jpg", Texture.class);
app.assets.load("textures/menuBackground.jpg", Texture.class);
app.assets.load("textures/leaderboardBackground.jpg", Texture.class);
app.assets.load("textures/position0.png", Texture.class);
app.assets.load("textures/position1.png", Texture.class);
app.assets.load("textures/position2.png", Texture.class);
assets.load("sounds/jumping.mp3", Sound.class);
app.assets.load("sounds/jumping.mp3", Sound.class);
assets.load("music/TheComplex.mp3", Music.class);
app.assets.load("music/TheComplex.mp3", Music.class);
}
private void loadFont(String fontFileName, int size, Color borderColour)
@ -116,6 +116,6 @@ public class Loading extends AbstractScreen {
params.fontParameters.borderWidth = 2;
params.fontParameters.borderColor = borderColour;
assets.load("badaboom" + size + ".ttf", BitmapFont.class, params);
app.assets.load("badaboom" + size + ".ttf", BitmapFont.class, params);
}
}

View file

@ -1,28 +1,26 @@
package com.game.Screens;
package com.game.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.game.App;
import com.game.managers.ScreenManager;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.alpha;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;
/**
* Created by Ash on 11/02/2016.
*/
public class Menu extends AbstractScreen {
private TextureAtlas atlas;
private Skin skin;
// Buttons
@ -33,15 +31,7 @@ public class Menu extends AbstractScreen {
public Menu(App app) {
super(app);
atlas = new TextureAtlas("spriteSheets/uiskin.atlas");
skin = new Skin(atlas);
skin.add("default-font", assets.get("badaboom60.ttf", BitmapFont.class));
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
music = assets.get("music/TheComplex.mp3", Music.class);
music.setLooping(true);
skin = new Skin();
buttonSize = new Vector2(128, 40);
}
@ -49,6 +39,13 @@ public class Menu extends AbstractScreen {
@Override
public void show() {
super.show();
skin.add("default-font", app.assets.get("badaboom60.ttf", BitmapFont.class));
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
music = app.assets.get("music/TheComplex.mp3", Music.class);
music.setLooping(true);
initButtons();
music.play();
}
@ -56,6 +53,7 @@ public class Menu extends AbstractScreen {
@Override
public void update(float dt) {
stage.act(dt);
}
@Override
@ -63,21 +61,16 @@ public class Menu extends AbstractScreen {
{
super.render(dt);
sb.begin();
sb.draw(assets.get("textures/menuBackground.jpg", Texture.class), 0, 0);
sb.end();
app.sb.begin();
app.sb.draw(app.assets.get("textures/menuBackground.jpg", Texture.class), 0, 0);
app.sb.end();
stage.draw();
}
@Override
public void handleInput() {
}
@Override
public void hide() {
super.hide();
if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { Gdx.app.exit(); }
}
@Override
@ -93,9 +86,8 @@ public class Menu extends AbstractScreen {
butPlay.addListener(new ClickListener() {
@Override
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
Gdx.input.setInputProcessor(null);
music.stop();
app.setScreen(new Play(app));
app.sm.setPlayScreen(1);
}
});
@ -105,8 +97,7 @@ public class Menu extends AbstractScreen {
butLeaderboard.addListener(new ClickListener() {
@Override
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
Gdx.input.setInputProcessor(null);
app.setScreen(new Leaderboard(app));
app.sm.setScreen(ScreenManager.Screen.LEADERBOARD);
}
});
@ -120,7 +111,6 @@ public class Menu extends AbstractScreen {
}
});
//butPlay.addAction(parallel(alpha(0), moveTo(stage.getWidth() / 2, stage.getHeight() / 2, 5f, Interpolation.pow5), sequence(alpha(0f), fadeIn(1.5f, Interpolation.pow2))));
butPlay.addAction(sequence(alpha(0f), fadeIn(1f, Interpolation.pow2)));
butLeaderboard.addAction(sequence(alpha(0f), fadeIn(1.5f, Interpolation.pow2)));
butExit.addAction(sequence(alpha(0f), fadeIn(2f, Interpolation.pow2)));

View file

@ -1,4 +1,4 @@
package com.game.Screens;
package com.game.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
@ -17,16 +17,17 @@ import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Polyline;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.game.Actor.Base;
import com.game.Actor.Platform;
import com.game.Actor.Player;
import com.game.actor.Base;
import com.game.actor.Platform;
import com.game.actor.Player;
import com.game.App;
import com.game.Misc.CameraUtils;
import com.game.Misc.Vars;
import com.game.managers.ScreenManager;
import com.game.misc.CameraUtils;
import com.game.misc.Vars;
import java.util.ArrayList;
import static com.game.Misc.Vars.PPM;
import static com.game.misc.Vars.PPM;
/**
* Created by Ash on 11/02/2016.
@ -51,11 +52,15 @@ public class Play extends AbstractScreen {
private Player player;
private ArrayList<Platform> platforms = new ArrayList<Platform>();
private int levelNumber;
private Sound jumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/jumping.mp3"));
public Play(App app) {
public Play(App app, int levelNumber) {
super(app);
this.levelNumber = levelNumber;
world = new World(new Vector2(0, Vars.GRAVITY.y), true);
world.setContactListener(cl);
@ -91,15 +96,14 @@ public class Play extends AbstractScreen {
public void render(float dt) {
super.render(dt);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
sb.setProjectionMatrix(cam.combined);
app.sb.setProjectionMatrix(cam.combined);
if(!isDebug)
{
sb.begin();
assets.get("badaboom25.ttf", BitmapFont.class).draw(sb,"Press M to go back to menu", 0, 0);
player.render(sb);
sb.end();
app.sb.begin();
app.assets.get("badaboom25.ttf", BitmapFont.class).draw(app.sb,"Press M to go back to menu", 0, 0);
player.render(app.sb);
app.sb.end();
tmr.setView(cam);
tmr.render();
@ -118,8 +122,7 @@ public class Play extends AbstractScreen {
player.jump();
}
if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { app.sm.setScreen(ScreenManager.Screen.MENU); }
if(Gdx.input.isKeyJustPressed(Input.Keys.V)) { isDebug = !isDebug; }
}
@ -131,7 +134,7 @@ public class Play extends AbstractScreen {
private void setupLevel()
{
tileMap = new TmxMapLoader().load("levels/level1.tmx");
tileMap = new TmxMapLoader().load("levels/level" + levelNumber + ".tmx");
tmr = new OrthogonalTiledMapRenderer(tileMap);
MapProperties mapProp = tileMap.getProperties();

View file

@ -0,0 +1,65 @@
package com.game.managers;
import com.game.App;
import com.game.screens.*;
import java.util.HashMap;
/**
* Created by Ash on 12/02/2016.
*/
public class ScreenManager {
private final App app;
private HashMap<Screen, AbstractScreen> screens = new HashMap<Screen, AbstractScreen>();
public enum Screen
{
LOADING,
MENU,
LEADERBOARD,
LEVELSELECT,
PLAY,
}
public ScreenManager(final App app)
{
this.app = app;
initScreens();
}
private void initScreens()
{
screens.put(Screen.LOADING, new Loading(app));
screens.put(Screen.MENU, new Menu(app));
screens.put(Screen.LEADERBOARD, new Leaderboard(app));
}
public void setPlayScreen(int levelNumber)
{
// remove loaded level
if(screens.get(Screen.PLAY) != null)
{
screens.get(Screen.PLAY).dispose();
screens.remove(Screen.PLAY);
}
screens.put(Screen.PLAY, new Play(app, levelNumber));
setScreen(Screen.PLAY);
}
public void setScreen(Screen s)
{
app.setScreen(screens.get(s));
}
public void dispose()
{
for(AbstractScreen s : screens.values())
{
if(s != null)
{
s.dispose();
}
}
}
}

View file

@ -4,7 +4,7 @@ import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.game.App;
import com.game.Misc.Vars;
import com.game.misc.Vars;
public class DesktopLauncher {
public static void main (String[] arg) {