diff --git a/core/assets/levels/level1.tmx b/core/assets/levels/level1.tmx index 4790374..2fb567c 100644 --- a/core/assets/levels/level1.tmx +++ b/core/assets/levels/level1.tmx @@ -1,15 +1,18 @@ - + + + + eJztk8EKACAIQzX//5/rOEKWktGhHgxPy5kl8qmggSLokE31FprsH53xFYyIeRAVvofV+dmdNEcMdYS5mA/rLl6GarJ/OeLP3PVJsH/03bLsHTB3AJM= - + diff --git a/core/assets/levels/level2.tmx b/core/assets/levels/level2.tmx index 3b3605f..f61c147 100644 --- a/core/assets/levels/level2.tmx +++ b/core/assets/levels/level2.tmx @@ -1,19 +1,22 @@ - + + + + eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - + - - + + diff --git a/core/assets/spritesheets/uiskin.atlas b/core/assets/spritesheets/uiskin.atlas deleted file mode 100644 index a51f7bf..0000000 --- a/core/assets/spritesheets/uiskin.atlas +++ /dev/null @@ -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 \ No newline at end of file diff --git a/core/assets/spritesheets/uiskin.json b/core/assets/spritesheets/uiskin.json index 96fb3a6..b0ec92c 100644 --- a/core/assets/spritesheets/uiskin.json +++ b/core/assets/spritesheets/uiskin.json @@ -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 } diff --git a/core/assets/spritesheets/uiskin.png b/core/assets/spritesheets/uiskin.png deleted file mode 100644 index c1e5f1a..0000000 Binary files a/core/assets/spritesheets/uiskin.png and /dev/null differ diff --git a/core/src/com/game/Actor/Base.java b/core/src/com/game/Actor/Base.java index 3fd3267..743d3f8 100644 --- a/core/src/com/game/Actor/Base.java +++ b/core/src/com/game/Actor/Base.java @@ -1,4 +1,4 @@ -package com.game.Actor; +package com.game.actor; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.*; diff --git a/core/src/com/game/Actor/Box2DSprite.java b/core/src/com/game/Actor/Box2DSprite.java index abd249e..f699d74 100644 --- a/core/src/com/game/Actor/Box2DSprite.java +++ b/core/src/com/game/Actor/Box2DSprite.java @@ -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. diff --git a/core/src/com/game/Actor/Object/Background.java b/core/src/com/game/Actor/Object/Background.java index cb09652..21116e4 100644 --- a/core/src/com/game/Actor/Object/Background.java +++ b/core/src/com/game/Actor/Object/Background.java @@ -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. diff --git a/core/src/com/game/Actor/Platform.java b/core/src/com/game/Actor/Platform.java index b4669de..6bc8fdf 100644 --- a/core/src/com/game/Actor/Platform.java +++ b/core/src/com/game/Actor/Platform.java @@ -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. diff --git a/core/src/com/game/Actor/Player.java b/core/src/com/game/Actor/Player.java index c6240fd..92c5c0a 100644 --- a/core/src/com/game/Actor/Player.java +++ b/core/src/com/game/Actor/Player.java @@ -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. diff --git a/core/src/com/game/App.java b/core/src/com/game/App.java index 0ab87e3..f639270 100644 --- a/core/src/com/game/App.java +++ b/core/src/com/game/App.java @@ -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; } } diff --git a/core/src/com/game/Misc/Box2dUtils.java b/core/src/com/game/Misc/Box2dUtils.java index c31c11b..458209a 100644 --- a/core/src/com/game/Misc/Box2dUtils.java +++ b/core/src/com/game/Misc/Box2dUtils.java @@ -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. diff --git a/core/src/com/game/Misc/CameraUtils.java b/core/src/com/game/Misc/CameraUtils.java index 6e58ec6..c6a97e9 100644 --- a/core/src/com/game/Misc/CameraUtils.java +++ b/core/src/com/game/Misc/CameraUtils.java @@ -1,4 +1,4 @@ -package com.game.Misc; +package com.game.misc; import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.math.Vector2; diff --git a/core/src/com/game/Misc/ParralaxBackground.java b/core/src/com/game/Misc/ParralaxBackground.java index 4336cf4..835f443 100644 --- a/core/src/com/game/Misc/ParralaxBackground.java +++ b/core/src/com/game/Misc/ParralaxBackground.java @@ -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. diff --git a/core/src/com/game/Misc/Vars.java b/core/src/com/game/Misc/Vars.java index 8f041cd..965e0ef 100644 --- a/core/src/com/game/Misc/Vars.java +++ b/core/src/com/game/Misc/Vars.java @@ -1,4 +1,4 @@ -package com.game.Misc; +package com.game.misc; import com.badlogic.gdx.math.Vector2; diff --git a/core/src/com/game/Screens/AbstractScreen.java b/core/src/com/game/Screens/AbstractScreen.java index cbb5dda..f83e415 100644 --- a/core/src/com/game/Screens/AbstractScreen.java +++ b/core/src/com/game/Screens/AbstractScreen.java @@ -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()); } } diff --git a/core/src/com/game/Screens/Leaderboard.java b/core/src/com/game/Screens/Leaderboard.java index 84a5a97..cfcd018 100644 --- a/core/src/com/game/Screens/Leaderboard.java +++ b/core/src/com/game/Screens/Leaderboard.java @@ -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 diff --git a/core/src/com/game/Screens/LevelSelect.java b/core/src/com/game/Screens/LevelSelect.java index 80a5d82..af6d9ff 100644 --- a/core/src/com/game/Screens/LevelSelect.java +++ b/core/src/com/game/Screens/LevelSelect.java @@ -1,4 +1,4 @@ -package com.game.Screens; +package com.game.screens; /** * Created by Ash on 11/02/2016. diff --git a/core/src/com/game/Screens/Loading.java b/core/src/com/game/Screens/Loading.java index de4ac98..6aff0e2 100644 --- a/core/src/com/game/Screens/Loading.java +++ b/core/src/com/game/Screens/Loading.java @@ -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); } } diff --git a/core/src/com/game/Screens/Menu.java b/core/src/com/game/Screens/Menu.java index 4a8714a..5d15c3b 100644 --- a/core/src/com/game/Screens/Menu.java +++ b/core/src/com/game/Screens/Menu.java @@ -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))); diff --git a/core/src/com/game/Screens/Play.java b/core/src/com/game/Screens/Play.java index b8c36d9..bd0f408 100644 --- a/core/src/com/game/Screens/Play.java +++ b/core/src/com/game/Screens/Play.java @@ -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 platforms = new ArrayList(); + 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(); diff --git a/core/src/com/game/managers/ScreenManager.java b/core/src/com/game/managers/ScreenManager.java new file mode 100644 index 0000000..6e8d004 --- /dev/null +++ b/core/src/com/game/managers/ScreenManager.java @@ -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 screens = new HashMap(); + 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(); + } + } + } +} diff --git a/desktop/src/com/game/desktop/DesktopLauncher.java b/desktop/src/com/game/desktop/DesktopLauncher.java index 816feca..8dec18d 100644 --- a/desktop/src/com/game/desktop/DesktopLauncher.java +++ b/desktop/src/com/game/desktop/DesktopLauncher.java @@ -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) {