diff --git a/core/assets/levels/level1.tmx b/core/assets/levels/level1.tmx index 2fb567c..c226eb1 100644 --- a/core/assets/levels/level1.tmx +++ b/core/assets/levels/level1.tmx @@ -1,10 +1,10 @@ - + - + @@ -19,4 +19,14 @@ + + + + + + + + + + diff --git a/core/assets/levels/level10.tmx b/core/assets/levels/level10.tmx deleted file mode 100644 index f61c147..0000000 --- a/core/assets/levels/level10.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - - - - - - - - - - - diff --git a/core/assets/levels/level2.tmx b/core/assets/levels/level2.tmx index f61c147..099e802 100644 --- a/core/assets/levels/level2.tmx +++ b/core/assets/levels/level2.tmx @@ -1,10 +1,10 @@ - + - + @@ -19,4 +19,14 @@ + + + + + + + + + + diff --git a/core/assets/levels/level3.tmx b/core/assets/levels/level3.tmx deleted file mode 100644 index f61c147..0000000 --- a/core/assets/levels/level3.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - - - - - - - - - - - diff --git a/core/assets/levels/level4.tmx b/core/assets/levels/level4.tmx deleted file mode 100644 index f61c147..0000000 --- a/core/assets/levels/level4.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - - - - - - - - - - - diff --git a/core/assets/levels/level5.tmx b/core/assets/levels/level5.tmx deleted file mode 100644 index 2fb567c..0000000 --- a/core/assets/levels/level5.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJztk8EKACAIQzX//5/rOEKWktGhHgxPy5kl8qmggSLokE31FprsH53xFYyIeRAVvofV+dmdNEcMdYS5mA/rLl6GarJ/OeLP3PVJsH/03bLsHTB3AJM= - - - - - - - - - - - diff --git a/core/assets/levels/level6.tmx b/core/assets/levels/level6.tmx deleted file mode 100644 index f61c147..0000000 --- a/core/assets/levels/level6.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - - - - - - - - - - - diff --git a/core/assets/levels/level7.tmx b/core/assets/levels/level7.tmx deleted file mode 100644 index f61c147..0000000 --- a/core/assets/levels/level7.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - - - - - - - - - - - diff --git a/core/assets/levels/level8.tmx b/core/assets/levels/level8.tmx deleted file mode 100644 index f61c147..0000000 --- a/core/assets/levels/level8.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - - - - - - - - - - - diff --git a/core/assets/levels/level9.tmx b/core/assets/levels/level9.tmx deleted file mode 100644 index f61c147..0000000 --- a/core/assets/levels/level9.tmx +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - eJxjYBgFo2B4ACYK9TMSqQaGKTWLFECJeUxYMDJghmJk9aS4B5t55AJK9A60HZSmv6EIAF6cACk= - - - - - - - - - - - diff --git a/core/assets/spritesheets/uiskin.json b/core/assets/spritesheets/uiskin.json index b0ec92c..520abbb 100644 --- a/core/assets/spritesheets/uiskin.json +++ b/core/assets/spritesheets/uiskin.json @@ -6,9 +6,12 @@ com.badlogic.gdx.graphics.Color: { black: { a: 1, b: 0, g: 0, r: 0 }, }, com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { - default: { down: null, up: null, font: default-font, fontColor: white, overFontColor: 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 } }, +com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: { + default: { titleFont: default-font, background: null } +}, } \ No newline at end of file diff --git a/core/assets/textures/pauseBackground.png b/core/assets/textures/pauseBackground.png new file mode 100644 index 0000000..9b6655f Binary files /dev/null and b/core/assets/textures/pauseBackground.png differ diff --git a/core/assets/textures/pauseGlow.png b/core/assets/textures/pauseGlow.png new file mode 100644 index 0000000..915ac19 Binary files /dev/null and b/core/assets/textures/pauseGlow.png differ diff --git a/core/assets/textures/player_blue.png b/core/assets/textures/player_blue.png new file mode 100644 index 0000000..28eebf4 Binary files /dev/null and b/core/assets/textures/player_blue.png differ diff --git a/core/assets/textures/player_green.png b/core/assets/textures/player_green.png new file mode 100644 index 0000000..b6dd8c7 Binary files /dev/null and b/core/assets/textures/player_green.png differ diff --git a/core/assets/textures/player.png b/core/assets/textures/player_red.png similarity index 100% rename from core/assets/textures/player.png rename to core/assets/textures/player_red.png diff --git a/core/src/com/game/Actor/Base.java b/core/src/com/game/Actor/Base.java index 743d3f8..6bee386 100644 --- a/core/src/com/game/Actor/Base.java +++ b/core/src/com/game/Actor/Base.java @@ -11,7 +11,6 @@ public abstract class Base { protected World world; // Physics definitions - protected BodyDef bd; protected Body body; protected String bodyType; diff --git a/core/src/com/game/Actor/Platform.java b/core/src/com/game/Actor/Platform.java index 6bc8fdf..aa70903 100644 --- a/core/src/com/game/Actor/Platform.java +++ b/core/src/com/game/Actor/Platform.java @@ -3,6 +3,7 @@ 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.Vars; import static com.game.misc.Vars.PPM; @@ -11,21 +12,23 @@ import static com.game.misc.Vars.PPM; */ public class Platform extends Base { - public Platform(World world, Vector2 pos, Vector2 size, Colours curColour) { + public Platform(World world, Vector2 pos, Vector2 size, Colours curColour, short categoryBits, short maskBits) { super(world, pos, size, "STATIC", curColour); body = Box2dUtils.makeBody(world, BodyDef.BodyType.StaticBody, pos ); - Box2dUtils.makePolygon(body, size, "", false); + Box2dUtils.makePolygon(body, size, "", false, categoryBits, maskBits); Box2dUtils.makeChain(body, new Vector2[]{ new Vector2((-size.x / 2 + 5) / PPM, (size.y / 2 + 5) / PPM), new Vector2((size.x / 2 - 5) / PPM, (size.y / 2 + 5) / PPM) }, "PLATFORM", - true + true, + Vars.BIT_MISC, + Vars.BIT_PLAYER ); } } diff --git a/core/src/com/game/Actor/Player.java b/core/src/com/game/Actor/Player.java index 92c5c0a..a3635ac 100644 --- a/core/src/com/game/Actor/Player.java +++ b/core/src/com/game/Actor/Player.java @@ -4,6 +4,7 @@ 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.App; import com.game.misc.Box2dUtils; import com.game.misc.Vars; @@ -16,8 +17,7 @@ public class Player extends Base { Vector2 curVel; - // TODO, remove - private Texture texture = new Texture("textures/player.png"); + private Texture texture; private Action curAction; public enum Action @@ -36,7 +36,9 @@ public class Player extends Base { BodyDef.BodyType.DynamicBody, pos ); - Box2dUtils.makeCircle(body, size.x, "PLAYER", false); + Box2dUtils.makeCircle(body, size.x, "PLAYER", false, Vars.BIT_PLAYER, (short)(Vars.BIT_RED | Vars.BIT_MISC)); + + texture = App.assets.get("textures/player_red.png"); } public void update(float dt) @@ -75,4 +77,37 @@ public class Player extends Base { // Mutators public void setAction(Action curAction) { this.curAction = curAction; } + + @Override + public void setCurColour(Colours curColour) + { + super.setCurColour(curColour); + Filter filter = body.getFixtureList().first().getFilterData(); + short bits = filter.maskBits; + + switch (curColour) + { + case RED: + bits &= ~Vars.BIT_GREEN; + bits &= ~Vars.BIT_BLUE; + bits |= Vars.BIT_RED; + texture = App.assets.get("textures/player_red.png", Texture.class); + break; + case GREEN: + bits &= ~Vars.BIT_RED; + bits &= ~Vars.BIT_BLUE; + bits |= Vars.BIT_GREEN; + texture = App.assets.get("textures/player_green.png", Texture.class); + break; + case BLUE: + bits &= ~Vars.BIT_RED; + bits &= ~Vars.BIT_GREEN; + bits |= Vars.BIT_BLUE; + texture = App.assets.get("textures/player_blue.png", Texture.class); + break; + } + + filter.maskBits = bits; + body.getFixtureList().first().setFilterData(filter); + } } diff --git a/core/src/com/game/App.java b/core/src/com/game/App.java index f639270..87242b0 100644 --- a/core/src/com/game/App.java +++ b/core/src/com/game/App.java @@ -7,15 +7,16 @@ import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.game.managers.ScreenManager; +import com.game.screens.AbstractScreen; import com.game.screens.Menu; +import com.game.screens.Play; public class App extends Game { // Managers - public AssetManager assets; + public static AssetManager assets; public ScreenManager sm; - // Batches public SpriteBatch sb; public ShapeRenderer sr; diff --git a/core/src/com/game/Misc/Box2dUtils.java b/core/src/com/game/Misc/Box2dUtils.java index 458209a..4686d1d 100644 --- a/core/src/com/game/Misc/Box2dUtils.java +++ b/core/src/com/game/Misc/Box2dUtils.java @@ -23,7 +23,7 @@ public class Box2dUtils { return world.createBody(bd); } - public static void makePolygon(Body body, Vector2 size, String userData, boolean isSensor) + public static void makePolygon(Body body, Vector2 size, String userData, boolean isSensor, short categoryBits, short maskBits) { FixtureDef fd = new FixtureDef(); @@ -34,13 +34,15 @@ public class Box2dUtils { fd.shape = shape; fd.density = density; fd.friction = friction; + fd.filter.categoryBits = categoryBits; + fd.filter.maskBits = maskBits; fd.isSensor = isSensor; if(userData.equals("")) { body.createFixture(fd); } else { body.createFixture(fd).setUserData(userData); } } - public static void makeCircle(Body body, float diameter, String userData, boolean isSensor) + public static void makeCircle(Body body, float diameter, String userData, boolean isSensor, short categoryBits, short maskBits) { FixtureDef fd = new FixtureDef(); @@ -49,13 +51,15 @@ public class Box2dUtils { fd.shape = shape; fd.density = density; fd.friction = friction; + fd.filter.categoryBits = categoryBits; + fd.filter.maskBits = maskBits; fd.isSensor = isSensor; if(userData.equals("")) { body.createFixture(fd); } else { body.createFixture(fd).setUserData(userData); } } - public static void makeChain(Body body, Vector2[] v, String userData, boolean isSensor) + public static void makeChain(Body body, Vector2[] v, String userData, boolean isSensor, short categoryBits, short maskBits) { FixtureDef fd = new FixtureDef(); @@ -64,6 +68,8 @@ public class Box2dUtils { fd.shape = shape; fd.density = density; fd.friction = friction; + fd.filter.categoryBits = categoryBits; + fd.filter.maskBits = maskBits; fd.isSensor = isSensor; if(userData.equals("")) { body.createFixture(fd); } diff --git a/core/src/com/game/Misc/Vars.java b/core/src/com/game/Misc/Vars.java index 965e0ef..1d79cf1 100644 --- a/core/src/com/game/Misc/Vars.java +++ b/core/src/com/game/Misc/Vars.java @@ -25,4 +25,6 @@ public class Vars { public static final short BIT_RED = 2; public static final short BIT_GREEN = 4; public static final short BIT_BLUE = 8; + public static final short BIT_PLAYER = 16; + public static final short BIT_MISC = 32; } diff --git a/core/src/com/game/Screens/Loading.java b/core/src/com/game/Screens/Loading.java index 1395ec2..f068a0a 100644 --- a/core/src/com/game/Screens/Loading.java +++ b/core/src/com/game/Screens/Loading.java @@ -40,10 +40,10 @@ public class Loading extends AbstractScreen { loadFont("fonts/badaboom.TTF", 60, Color.BLACK); - app.assets.load("textures/player.png", Texture.class); + app.assets.load("textures/player_red.png", Texture.class); app.assets.finishLoading(); // make sure player texture and font is loaded - logo = app.assets.get("textures/player.png", Texture.class); + logo = app.assets.get("textures/player_red.png", Texture.class); loadingRect = new Rectangle(stage.getWidth() / 6f, (stage.getHeight() / 2f - 25), 0, 25); assetsToLoad(); @@ -100,10 +100,15 @@ public class Loading extends AbstractScreen { app.assets.load("textures/menuBackground.jpg", Texture.class); app.assets.load("textures/leaderboardBackground.jpg", Texture.class); app.assets.load("textures/levelSelectBackground.jpg", Texture.class); + app.assets.load("textures/pauseBackground.png", Texture.class); + app.assets.load("textures/pauseGlow.png", 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); + app.assets.load("textures/player_green.png", Texture.class); + app.assets.load("textures/player_blue.png", Texture.class); + app.assets.load("sounds/jumping.mp3", Sound.class); app.assets.load("music/TheComplex.mp3", Music.class); diff --git a/core/src/com/game/Screens/Menu.java b/core/src/com/game/Screens/Menu.java index de21a0c..dbc368c 100644 --- a/core/src/com/game/Screens/Menu.java +++ b/core/src/com/game/Screens/Menu.java @@ -5,8 +5,6 @@ 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.Skin; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; @@ -29,6 +27,7 @@ public class Menu extends AbstractScreen { private Music music; + public Menu(App app) { super(app); skin = new Skin(); diff --git a/core/src/com/game/Screens/Play.java b/core/src/com/game/Screens/Play.java index b7e70a0..82257f8 100644 --- a/core/src/com/game/Screens/Play.java +++ b/core/src/com/game/Screens/Play.java @@ -3,7 +3,6 @@ package com.game.screens; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.audio.Sound; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -18,14 +17,21 @@ 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.badlogic.gdx.scenes.scene2d.ui.Image; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.ui.Window; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.game.actor.Base; import com.game.actor.Platform; import com.game.actor.Player; import com.game.App; import com.game.managers.ScreenManager; +import com.game.misc.Box2dUtils; import com.game.misc.CameraUtils; import com.game.misc.Vars; +import javax.xml.soap.Text; import java.util.ArrayList; import static com.game.misc.Vars.PPM; @@ -35,6 +41,8 @@ import static com.game.misc.Vars.PPM; */ public class Play extends AbstractScreen { + private Skin skin; + // TODO, remove public boolean isDebug = false; @@ -53,6 +61,15 @@ public class Play extends AbstractScreen { private Player player; private ArrayList platforms = new ArrayList(); + // Pause window + private boolean isPaused; + private Window pauseWindow; + private Image pauseBackground; + private Image pauseGlow; + private TextButton butContinue, butReset, butExit; + private Vector2 buttonSize; + + private int levelNumber; private Sound jumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/jumping.mp3")); @@ -60,6 +77,8 @@ public class Play extends AbstractScreen { public Play(App app, int levelNumber) { super(app); + skin = new Skin(); + this.levelNumber = levelNumber; world = new World(new Vector2(0, Vars.GRAVITY.y), true); @@ -69,6 +88,9 @@ public class Play extends AbstractScreen { b2dCam = new OrthographicCamera(); b2dCam.setToOrtho(false, Vars.SCREEN_WIDTH / PPM, Vars.SCREEN_HEIGHT / PPM); + + isPaused = false; + buttonSize = new Vector2(50, 50); } @Override @@ -76,21 +98,36 @@ public class Play extends AbstractScreen { { super.show(); + skin.add("default-font", app.assets.get("badaboom60.ttf", BitmapFont.class)); + skin.load(Gdx.files.internal("spritesheets/uiskin.json")); - setupLevel(); + initLevel(); + initPauseWindow(); } @Override public void update(float dt) { - world.step(dt, 6, 2); + if(!isPaused) + { + world.step(dt, 6, 2); - CameraUtils.lerpToTarget(cam, player.getPos().scl(PPM).x, 0); - CameraUtils.lerpToTarget(b2dCam, player.getPos().x, player.getPos().y); + CameraUtils.lerpToTarget(cam, player.getPos().scl(PPM).x, 0); + CameraUtils.lerpToTarget(b2dCam, player.getPos().x, player.getPos().y); + b2dCam.zoom = 5f; - Vector2 start = new Vector2(cam.viewportWidth / 2, cam.viewportHeight / 2); - CameraUtils.setBoundary(cam, start, new Vector2(mapWidth * tileSize.x - start.x * 2, mapHeight * tileSize.y - start.y * 2)); + Vector2 start = new Vector2(cam.viewportWidth / 2, cam.viewportHeight / 2); + CameraUtils.setBoundary(cam, start, new Vector2(mapWidth * tileSize.x - start.x * 2, mapHeight * tileSize.y - start.y * 2)); - player.update(dt); + player.update(dt); + } + + if(pauseWindow.isVisible() != isPaused) + { + pauseWindow.setVisible(isPaused); + pauseGlow.setVisible(isPaused); + } + + stage.act(dt); } @Override @@ -115,6 +152,8 @@ public class Play extends AbstractScreen { { b2dr.render(world, b2dCam.combined); } + + stage.draw(); } @Override @@ -125,7 +164,27 @@ 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.ESCAPE)) + { + isPaused = !isPaused; + System.out.println("isPaused: " + isPaused); + } + + if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) + { + player.setCurColour(Base.Colours.RED); + } + + if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) + { + player.setCurColour(Base.Colours.GREEN); + } + + if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) + { + player.setCurColour(Base.Colours.BLUE); + } + if(Gdx.input.isKeyJustPressed(Input.Keys.V)) { isDebug = !isDebug; } } @@ -133,9 +192,12 @@ public class Play extends AbstractScreen { public void dispose() { super.dispose(); world.dispose(); + b2dr.dispose(); + tileMap.dispose(); + tmr.dispose(); } - private void setupLevel() + private void initLevel() { tileMap = new TmxMapLoader().load("levels/level" + levelNumber + ".tmx"); tmr = new OrthogonalTiledMapRenderer(tileMap); @@ -150,7 +212,15 @@ public class Play extends AbstractScreen { MapLayer boundaryLayer = tileMap.getLayers().get("BOUNDARY"); PolylineMapObject polylineObj = (PolylineMapObject)boundaryLayer.getObjects().get(0); - buildBoundary(polylineObj); + initBoundary(polylineObj, "BOUNDARY", false); + + boundaryLayer = tileMap.getLayers().get("FAILBOUNDARY"); + polylineObj = (PolylineMapObject)boundaryLayer.getObjects().get(0); + initBoundary(polylineObj, "FAILBOUNDARY", true); + + boundaryLayer = tileMap.getLayers().get("PASSBOUNDARY"); + polylineObj = (PolylineMapObject)boundaryLayer.getObjects().get(0); + initBoundary(polylineObj, "PASSBOUNDARY", true); MapLayer playerLayer = tileMap.getLayers().get("PLAYER"); TextureMapObject playerObj = (TextureMapObject)playerLayer.getObjects().get(0); @@ -165,14 +235,14 @@ public class Play extends AbstractScreen { if(cell == null) { continue; } if(cell.getTile() == null) { continue; } - if(cell.getTile().getId() == 1) { platforms.add(new Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), Base.Colours.RED)); } - else if(cell.getTile().getId() == 2) { platforms.add(new Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), Base.Colours.GREEN)); } - else if(cell.getTile().getId() == 3) { platforms.add(new Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), Base.Colours.BLUE)); } + if(cell.getTile().getId() == 1) { platforms.add(new Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), Base.Colours.RED, Vars.BIT_RED, Vars.BIT_PLAYER)); } + else if(cell.getTile().getId() == 2) { platforms.add(new Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), Base.Colours.GREEN, Vars.BIT_GREEN, Vars.BIT_PLAYER)); } + else if(cell.getTile().getId() == 3) { platforms.add(new Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), Base.Colours.BLUE, Vars.BIT_BLUE, Vars.BIT_PLAYER)); } } } } - private void buildBoundary(PolylineMapObject polylineObj) + private void initBoundary(PolylineMapObject polylineObj, String userData, boolean isSensor) { Polyline r = polylineObj.getPolyline(); BodyDef bd = new BodyDef(); @@ -180,10 +250,6 @@ public class Play extends AbstractScreen { Body body = world.createBody(bd); - FixtureDef fd = new FixtureDef(); - - ChainShape chain = new ChainShape(); - float[] v = r.getTransformedVertices(); Vector2[] finalV = new Vector2[v.length / 2]; @@ -194,10 +260,58 @@ public class Play extends AbstractScreen { finalV[i].y = v[i * 2 + 1] / PPM; } - chain.createChain(finalV); - fd.shape = chain; + Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_MISC, Vars.BIT_PLAYER); + } - body.createFixture(fd).setUserData("boundary"); + private void initPauseWindow() + { + pauseWindow = new Window("Paused", skin); + pauseWindow.getTitleLabel().setPosition(350, 500); + pauseBackground = new Image(app.assets.get("textures/pauseBackground.png", Texture.class)); + pauseWindow.setBackground(pauseBackground.getDrawable()); + pauseWindow.setSize(700, 500); + pauseWindow.setPosition(280, 50); + pauseWindow.setVisible(false); + + butContinue = new TextButton("Continue", skin, "default"); + butContinue.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 240); + butContinue.setSize(buttonSize.x, buttonSize.y); + butContinue.addListener(new ClickListener() { + @Override + public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { + isPaused = false; + } + }); + + butReset = new TextButton("Reset", skin, "default"); + butReset.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 140); + butReset.setSize(buttonSize.x, buttonSize.y); + butReset.addListener(new ClickListener() { + @Override + public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { + app.sm.setPlayScreen(levelNumber); + } + }); + + butExit = new TextButton("Exit", skin, "default"); + butExit.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 40); + butExit.setSize(buttonSize.x, buttonSize.y); + butExit.addListener(new ClickListener() { + @Override + public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { + app.sm.setScreen(ScreenManager.Screen.MENU); + } + }); + + pauseGlow = new Image(app.assets.get("textures/pauseGlow.png", Texture.class)); + pauseGlow.setVisible(false); + + pauseWindow.addActor(butContinue); + pauseWindow.addActor(butReset); + pauseWindow.addActor(butExit); + + stage.addActor(pauseGlow); + stage.addActor(pauseWindow); } // Accessors @@ -219,8 +333,25 @@ public class Play extends AbstractScreen { { if(player.getCurAction() != Player.Action.IDLE) { player.setAction(Player.Action.IDLE); + return; } } + + if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("PASSBOUNDARY") || + fb.getUserData().equals("PLAYER") && fa.getUserData().equals("PASSBOUNDARY")) + { + isPaused = true; + + return; + } + + if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("FAILBOUNDARY") || + fb.getUserData().equals("PLAYER") && fa.getUserData().equals("FAILBOUNDARY")) + { + isPaused = true; + return; + } + } @Override diff --git a/core/src/com/game/managers/ScreenManager.java b/core/src/com/game/managers/ScreenManager.java index 967a7e4..703e1bc 100644 --- a/core/src/com/game/managers/ScreenManager.java +++ b/core/src/com/game/managers/ScreenManager.java @@ -38,6 +38,7 @@ public class ScreenManager { public void setPlayScreen(int levelNumber) { + // remove loaded level if(screens.get(Screen.PLAY) != null) {