diff --git a/core/assets/levels/level4.tmx b/core/assets/levels/level4.tmx index fdfe0a3..d7707dc 100644 --- a/core/assets/levels/level4.tmx +++ b/core/assets/levels/level4.tmx @@ -1,14 +1,17 @@ - + + + + - eJxjYBgFIwkwDbQDqARo4Q9qm8mEhEGAEQsGyTFjwYTMw+dWbHLo9mIDxLqDWDtJsRuXmcToJSZMSLGTEoAtDIdzngMA3GQAZw== + eJxjYBgFo2AU0AIwIWEQYMSCQYAZCyZkHhMONbgANnvRAbHuIBUQYzcleskNE1oAWoXhYAUAsHwAUw== @@ -29,4 +32,9 @@ + + + + + diff --git a/core/assets/levels/level8.tmx b/core/assets/levels/level8.tmx index 630da21..e88c945 100644 --- a/core/assets/levels/level8.tmx +++ b/core/assets/levels/level8.tmx @@ -8,11 +8,11 @@ - eJxjYBgFo2AUDARgIoAHC2AmgKkB0P2Oyy5GApge4YnL7pEIALMwAF8= + eJxjYBgFgwEwAzHjQDuCQsCExGZEwuiAGYoHIyAUB0wMqP4kxjxkM4n1NyVhRIr78JlBql9BAFeckwIGMn1QGnbU8P9AAHLiGgQAlYAAOA== - + @@ -29,4 +29,5 @@ + diff --git a/core/assets/textures/spikes.png b/core/assets/textures/spikes.png new file mode 100644 index 0000000..2c5fcd6 Binary files /dev/null and b/core/assets/textures/spikes.png differ diff --git a/core/src/com/game/Actor/Spike.java b/core/src/com/game/Actor/Spike.java new file mode 100644 index 0000000..a79fd41 --- /dev/null +++ b/core/src/com/game/Actor/Spike.java @@ -0,0 +1,35 @@ +package com.game.actor; + +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.physics.box2d.BodyDef; +import com.badlogic.gdx.physics.box2d.World; +import com.game.misc.Box2dUtils; +import com.game.misc.Vars; + +import static com.game.misc.Vars.PPM; + +/** + * Created by Elliot on 22/02/2016. + */ +public class Spike extends Base { + + public Spike(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, 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) + }, + "SPIKE", + true, + Vars.BIT_MISC, + Vars.BIT_PLAYER + ); + } +} diff --git a/core/src/com/game/Screens/Loading.java b/core/src/com/game/Screens/Loading.java index c9ad50d..cc107a8 100644 --- a/core/src/com/game/Screens/Loading.java +++ b/core/src/com/game/Screens/Loading.java @@ -108,6 +108,7 @@ public class Loading extends AbstractScreen { 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/Spikes.png", Texture.class); for(int i = 1; i <= 10; i++) { app.assets.load("textures/level" + i + "Intro.png", Texture.class); diff --git a/core/src/com/game/Screens/Play.java b/core/src/com/game/Screens/Play.java index 22be5f2..ff50f22 100644 --- a/core/src/com/game/Screens/Play.java +++ b/core/src/com/game/Screens/Play.java @@ -29,6 +29,7 @@ import com.game.actor.Base; import com.game.actor.Platform; import com.game.actor.Player; import com.game.App; +import com.game.actor.Spike; import com.game.managers.ScreenManager; import com.game.misc.Box2dUtils; import com.game.misc.CameraUtils; @@ -55,8 +56,6 @@ public class Play extends AbstractScreen { private OrthographicCamera b2dCam; // TODO, remove // TileMap and Map Renderer - private TiledMap tile1; - private TiledMap tile2; private TiledMap tileMap; private OrthogonalTiledMapRenderer tmr; private float mapWidth, mapHeight; @@ -65,6 +64,7 @@ public class Play extends AbstractScreen { // All Actors in level private Player player; private ArrayList platforms = new ArrayList(); + private ArrayList spikes = new ArrayList(); // Intro window private boolean isIntro; @@ -214,13 +214,7 @@ public class Play extends AbstractScreen { @Override public void handleInput() { - if(Gdx.input.isKeyPressed(Input.Keys.SPACE)) - { - jumpSound.play(); - player.jump(); - } - - if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) + if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) { isPaused = !isPaused; System.out.println("isPaused: " + isPaused); @@ -254,6 +248,12 @@ public class Play extends AbstractScreen { progressTexture = app.assets.get("textures/player_yellow.png", Texture.class); } + if(Gdx.input.isKeyPressed(Input.Keys.SPACE)) + { + jumpSound.play(); + player.jump(); + } + } if(Gdx.input.isKeyJustPressed(Input.Keys.V)) { isDebug = !isDebug; } @@ -280,6 +280,7 @@ public class Play extends AbstractScreen { TiledMapTileLayer platformLayer = (TiledMapTileLayer)tileMap.getLayers().get("PLATFORM"); + TiledMapTileLayer spikeLayer = (TiledMapTileLayer)tileMap.getLayers().get("SPIKES"); MapLayer boundaryLayer = tileMap.getLayers().get("BOUNDARY"); PolylineMapObject polylineObj = (PolylineMapObject)boundaryLayer.getObjects().get(0); @@ -311,6 +312,19 @@ public class Play extends AbstractScreen { 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)); } } } + + for(int row = 0; row < spikeLayer.getHeight(); row++) + { + for(int col = 0; col < spikeLayer.getWidth(); col++) + { + TiledMapTileLayer.Cell cell = spikeLayer.getCell(col, row); + + if(cell == null) { continue; } + if(cell.getTile() == null) { continue; } + + if(cell.getTile().getId() == 0) { spikes.add(new Spike(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)); } + } + } } private void initBoundary(PolylineMapObject polylineObj, String userData, boolean isSensor)