Camera utilities and menu implementation
This commit is contained in:
parent
71ffec00ab
commit
61a10aa7e7
12 changed files with 203 additions and 104 deletions
|
@ -5,15 +5,15 @@
|
||||||
</tileset>
|
</tileset>
|
||||||
<layer name="PLATFORM" width="50" height="8">
|
<layer name="PLATFORM" width="50" height="8">
|
||||||
<data encoding="base64" compression="zlib">
|
<data encoding="base64" compression="zlib">
|
||||||
eJxjYBgF1ABMSJgYwAjEzGj0QAHGAbZ/qANmPBifHmTAyIA/Hkg1nxBgwoLxAUYsGNld+PQh06S4DZvZ2NxAbYArTCi1j5TygR6AnHSLDgAqVwCE
|
eJztk8EKACAIQzX//5/rOEKWktGhHgxPy5kl8qmggSLokE31FprsH53xFYyIeRAVvofV+dmdNEcMdYS5mA/rLl6GarJ/OeLP3PVJsH/03bLsHTB3AJM=
|
||||||
</data>
|
</data>
|
||||||
</layer>
|
</layer>
|
||||||
<objectgroup name="PLAYER">
|
<objectgroup name="PLAYER">
|
||||||
<object id="19" gid="3" x="64" y="320" width="64" height="64"/>
|
<object id="19" gid="3" x="64" y="320" width="64" height="64"/>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
<objectgroup name="BOUNDARY">
|
<objectgroup name="BOUNDARY">
|
||||||
<object id="23" x="-64" y="-128">
|
<object id="23" x="0" y="-192">
|
||||||
<polyline points="0,0 0,768 3392,768 3392,0 0,0"/>
|
<polyline points="0,0 0,1024 3328,1024 3328,0 0,0"/>
|
||||||
</object>
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package com.game.Actor;
|
package com.game.Actor;
|
||||||
|
|
||||||
import static com.game.Misc.Vars.PPM;
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.physics.box2d.*;
|
import com.badlogic.gdx.physics.box2d.*;
|
||||||
import com.game.Misc.Vars;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ash on 08/02/2016.
|
* Created by Ash on 08/02/2016.
|
||||||
|
|
|
@ -3,18 +3,16 @@ package com.game.Actor;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.physics.box2d.*;
|
import com.badlogic.gdx.physics.box2d.*;
|
||||||
import com.game.Misc.Box2dUtils;
|
import com.game.Misc.Box2dUtils;
|
||||||
import com.game.Misc.Vars;
|
|
||||||
|
|
||||||
import static com.game.Misc.Vars.PPM;
|
import static com.game.Misc.Vars.PPM;
|
||||||
import static com.game.Misc.Vars.TILESIZE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ash on 08/02/2016.
|
* Created by Ash on 08/02/2016.
|
||||||
*/
|
*/
|
||||||
public class Platform extends Base {
|
public class Platform extends Base {
|
||||||
|
|
||||||
public Platform(World world, Vector2 pos, Colours curColour) {
|
public Platform(World world, Vector2 pos, Vector2 size, Colours curColour) {
|
||||||
super(world, pos, new Vector2(TILESIZE, TILESIZE), "STATIC", curColour);
|
super(world, pos, size, "STATIC", curColour);
|
||||||
|
|
||||||
body = Box2dUtils.makeBody(world,
|
body = Box2dUtils.makeBody(world,
|
||||||
BodyDef.BodyType.StaticBody,
|
BodyDef.BodyType.StaticBody,
|
||||||
|
@ -23,8 +21,8 @@ public class Platform extends Base {
|
||||||
Box2dUtils.makePolygon(body, size, "", false);
|
Box2dUtils.makePolygon(body, size, "", false);
|
||||||
Box2dUtils.makeChain(body,
|
Box2dUtils.makeChain(body,
|
||||||
new Vector2[]{
|
new Vector2[]{
|
||||||
new Vector2((-TILESIZE / 2 + 5) / PPM, (TILESIZE / 2 + 5) / PPM),
|
new Vector2((-size.x / 2 + 5) / PPM, (size.y / 2 + 5) / PPM),
|
||||||
new Vector2((TILESIZE / 2 - 5) / PPM, (TILESIZE / 2 + 5) / PPM)
|
new Vector2((size.x / 2 - 5) / PPM, (size.y / 2 + 5) / PPM)
|
||||||
},
|
},
|
||||||
"PLATFORM",
|
"PLATFORM",
|
||||||
true
|
true
|
||||||
|
|
|
@ -2,38 +2,53 @@ package com.game;
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
import com.game.Misc.Vars;
|
import com.game.Misc.Vars;
|
||||||
import com.game.States.StateManager;
|
import com.game.Managers.StateManager;
|
||||||
|
|
||||||
public class Game extends ApplicationAdapter {
|
public class App extends ApplicationAdapter {
|
||||||
|
|
||||||
private float accum;
|
private float accum;
|
||||||
|
|
||||||
|
// Batches
|
||||||
private SpriteBatch sb;
|
private SpriteBatch sb;
|
||||||
|
private ShapeRenderer sr;
|
||||||
|
|
||||||
|
// Cameras
|
||||||
private OrthographicCamera cam;
|
private OrthographicCamera cam;
|
||||||
private OrthographicCamera hudCam;
|
private OrthographicCamera hudCam;
|
||||||
|
|
||||||
|
// Managers
|
||||||
private StateManager sm;
|
private StateManager sm;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
sb = new SpriteBatch();
|
|
||||||
|
|
||||||
|
// Create batches
|
||||||
|
sb = new SpriteBatch();
|
||||||
|
sr = new ShapeRenderer();
|
||||||
|
|
||||||
|
// Create Main + HUD cameras
|
||||||
cam = new OrthographicCamera();
|
cam = new OrthographicCamera();
|
||||||
cam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
cam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
||||||
hudCam = new OrthographicCamera();
|
hudCam = new OrthographicCamera();
|
||||||
hudCam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
hudCam.setToOrtho(false, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
||||||
|
|
||||||
|
// Create statemanager (Should always happen last)
|
||||||
sm = new StateManager(this);
|
sm = new StateManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize (int width, int height) {
|
public void resize (int width, int height) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render () {
|
public void render () {
|
||||||
|
super.render();
|
||||||
accum += Gdx.graphics.getDeltaTime();
|
accum += Gdx.graphics.getDeltaTime();
|
||||||
while (accum >= Vars.STEP) {
|
while (accum >= Vars.STEP) {
|
||||||
accum -= Vars.STEP;
|
accum -= Vars.STEP;
|
||||||
|
@ -41,22 +56,20 @@ public class Game extends ApplicationAdapter {
|
||||||
sm.update(Vars.STEP);
|
sm.update(Vars.STEP);
|
||||||
sm.render();
|
sm.render();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if(Gdx.input.isKeyPressed(Input.Keys.ESCAPE)) { Gdx.app.exit(); }
|
||||||
public void pause () {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resume () {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose () {
|
public void dispose () {
|
||||||
sm.dispose();
|
sm.dispose();
|
||||||
|
sb.dispose();
|
||||||
|
sr.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpriteBatch getSpriteBatch() { return sb; }
|
public SpriteBatch getSpriteBatch() { return sb; }
|
||||||
|
public ShapeRenderer getSr() { return sr; }
|
||||||
|
public StateManager getSm() { return sm; }
|
||||||
public OrthographicCamera getCam() { return cam; }
|
public OrthographicCamera getCam() { return cam; }
|
||||||
public OrthographicCamera getHudCam() { return hudCam; }
|
public OrthographicCamera getHudCam() { return hudCam; }
|
||||||
}
|
}
|
7
core/src/com/game/Managers/Assets.java
Normal file
7
core/src/com/game/Managers/Assets.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package com.game.Managers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ash on 10/02/2016.
|
||||||
|
*/
|
||||||
|
public class Assets {
|
||||||
|
}
|
|
@ -1,6 +1,9 @@
|
||||||
package com.game.States;
|
package com.game.Managers;
|
||||||
|
|
||||||
import com.game.Game;
|
import com.game.App;
|
||||||
|
import com.game.States.Menu;
|
||||||
|
import com.game.States.Play;
|
||||||
|
import com.game.States.State;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -8,7 +11,8 @@ import java.util.HashMap;
|
||||||
* Created by Ash on 08/02/2016.
|
* Created by Ash on 08/02/2016.
|
||||||
*/
|
*/
|
||||||
public class StateManager {
|
public class StateManager {
|
||||||
private Game game;
|
|
||||||
|
protected final App app;
|
||||||
|
|
||||||
private HashMap<States, State> states = new HashMap<States, State>();
|
private HashMap<States, State> states = new HashMap<States, State>();
|
||||||
|
|
||||||
|
@ -20,13 +24,13 @@ public class StateManager {
|
||||||
PLAY,
|
PLAY,
|
||||||
}
|
}
|
||||||
|
|
||||||
public StateManager(Game game)
|
public StateManager(App app)
|
||||||
{
|
{
|
||||||
this.game = game;
|
this.app = app;
|
||||||
states.put(States.MENU, new Menu(this));
|
states.put(States.MENU, new Menu(this));
|
||||||
states.put(States.PLAY, new Play(this));
|
states.put(States.PLAY, new Play(this));
|
||||||
|
|
||||||
setState(States.PLAY); // TODO, set to MENU
|
setState(States.MENU); // TODO, set to MENU
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(float dt)
|
public void update(float dt)
|
||||||
|
@ -50,7 +54,7 @@ public class StateManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
public Game game() { return game; }
|
public App app() { return app; }
|
||||||
|
|
||||||
// Mutators
|
// Mutators
|
||||||
public void setState(States state)
|
public void setState(States state)
|
54
core/src/com/game/Misc/CameraUtils.java
Normal file
54
core/src/com/game/Misc/CameraUtils.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package com.game.Misc;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Camera;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Ash on 10/02/2016.
|
||||||
|
*/
|
||||||
|
public class CameraUtils {
|
||||||
|
|
||||||
|
public static void lockOnTarget(Camera cam, float tarX, float tarY)
|
||||||
|
{
|
||||||
|
Vector3 pos = cam.position;
|
||||||
|
pos.x = tarX;
|
||||||
|
pos.y = tarY;
|
||||||
|
cam.position.set(pos);
|
||||||
|
cam.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void lerpToTarget(Camera cam, float tarX, float tarY)
|
||||||
|
{
|
||||||
|
Vector3 pos = cam.position;
|
||||||
|
pos.x = cam.position.x + (tarX - cam.position.x) * .2f;
|
||||||
|
pos.y = cam.position.y + (tarY - cam.position.y) * .2f;;
|
||||||
|
cam.position.set(pos);
|
||||||
|
cam.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setBoundary(Camera cam, Vector2 start, Vector2 size)
|
||||||
|
{
|
||||||
|
Vector3 pos = cam.position;
|
||||||
|
if(pos.x < start.x)
|
||||||
|
{
|
||||||
|
pos.x = start.x;
|
||||||
|
}
|
||||||
|
if(pos.y < start.y)
|
||||||
|
{
|
||||||
|
pos.y = start.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pos.x > start.x + size.x)
|
||||||
|
{
|
||||||
|
pos.x = start.x + size.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pos.y > start.y + size.y)
|
||||||
|
{
|
||||||
|
pos.y = start.y + size.y;
|
||||||
|
}
|
||||||
|
cam.position.set(pos);
|
||||||
|
cam.update();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,8 +2,6 @@ package com.game.Misc;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ash on 08/02/2016.
|
* Created by Ash on 08/02/2016.
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +17,7 @@ public class Vars {
|
||||||
public static final float STEP = 1 / FRAMERATE;
|
public static final float STEP = 1 / FRAMERATE;
|
||||||
public static final Vector2 GRAVITY = new Vector2(0, -9.81f);
|
public static final Vector2 GRAVITY = new Vector2(0, -9.81f);
|
||||||
public static final float PPM = 100f; // Pixels per meter
|
public static final float PPM = 100f; // Pixels per meter
|
||||||
public static final float TILESIZE = 64f;
|
//public static final Vector2 TILESIZE = new Vector2(64, 64);
|
||||||
public static final Vector2 SCROLLSPEED = new Vector2(150f, 0);
|
public static final Vector2 SCROLLSPEED = new Vector2(150f, 0);
|
||||||
|
|
||||||
// Filter bits
|
// Filter bits
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
package com.game.States;
|
package com.game.States;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
import com.game.Managers.StateManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ash on 08/02/2016.
|
* Created by Ash on 08/02/2016.
|
||||||
*/
|
*/
|
||||||
public class Menu extends State {
|
public class Menu extends State {
|
||||||
|
|
||||||
|
|
||||||
public Menu(StateManager sm) {
|
public Menu(StateManager sm) {
|
||||||
super(sm);
|
super(sm);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +31,10 @@ public class Menu extends State {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleInput() {
|
public void handleInput() {
|
||||||
|
if(Gdx.input.isKeyPressed(Input.Keys.ENTER))
|
||||||
|
{
|
||||||
|
sm.setState(StateManager.States.PLAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,8 +6,8 @@ import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.audio.Sound;
|
import com.badlogic.gdx.audio.Sound;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
|
||||||
import com.badlogic.gdx.maps.MapLayer;
|
import com.badlogic.gdx.maps.MapLayer;
|
||||||
|
import com.badlogic.gdx.maps.MapProperties;
|
||||||
import com.badlogic.gdx.maps.objects.PolylineMapObject;
|
import com.badlogic.gdx.maps.objects.PolylineMapObject;
|
||||||
import com.badlogic.gdx.maps.objects.TextureMapObject;
|
import com.badlogic.gdx.maps.objects.TextureMapObject;
|
||||||
import com.badlogic.gdx.maps.tiled.TiledMap;
|
import com.badlogic.gdx.maps.tiled.TiledMap;
|
||||||
|
@ -21,7 +21,11 @@ import com.badlogic.gdx.physics.box2d.*;
|
||||||
import com.game.Actor.Base;
|
import com.game.Actor.Base;
|
||||||
import com.game.Actor.Platform;
|
import com.game.Actor.Platform;
|
||||||
import com.game.Actor.Player;
|
import com.game.Actor.Player;
|
||||||
|
import com.game.App;
|
||||||
|
import com.game.Managers.StateManager;
|
||||||
|
import com.game.Misc.CameraUtils;
|
||||||
import com.game.Misc.Vars;
|
import com.game.Misc.Vars;
|
||||||
|
import javafx.beans.property.MapProperty;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -31,61 +35,29 @@ import java.util.ArrayList;
|
||||||
public class Play extends State {
|
public class Play extends State {
|
||||||
|
|
||||||
// TODO, remove
|
// TODO, remove
|
||||||
public boolean isDebug = true;
|
public boolean isDebug = false;
|
||||||
|
|
||||||
// Physics related
|
// Physics related
|
||||||
private World world;
|
private World world;
|
||||||
private Box2DDebugRenderer b2dr; // TODO, remove
|
private Box2DDebugRenderer b2dr; // TODO, remove
|
||||||
|
private OrthographicCamera b2dCam; // TODO, remove
|
||||||
|
|
||||||
private OrthographicCamera b2dCam;
|
// TileMap and Map Renderer
|
||||||
|
|
||||||
private float tileSize;
|
|
||||||
|
|
||||||
Player player;
|
|
||||||
|
|
||||||
private TiledMap tileMap;
|
private TiledMap tileMap;
|
||||||
private OrthogonalTiledMapRenderer tmr;
|
private OrthogonalTiledMapRenderer tmr;
|
||||||
|
private float mapWidth, mapHeight;
|
||||||
|
private Vector2 tileSize;
|
||||||
|
|
||||||
|
// All Actors in level
|
||||||
|
private Player player;
|
||||||
|
private ArrayList<Platform> platforms = new ArrayList<Platform>();
|
||||||
|
|
||||||
ArrayList<Platform> platforms = new ArrayList<Platform>();
|
|
||||||
|
|
||||||
private Sound jumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/jumping.mp3"));
|
private Sound jumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/jumping.mp3"));
|
||||||
|
|
||||||
public Play(StateManager sm) {
|
public Play(StateManager sm) {
|
||||||
super(sm);
|
super(sm);
|
||||||
world = new World(new Vector2(0, Vars.GRAVITY.y), true);
|
world = new World(new Vector2(0, Vars.GRAVITY.y), true);
|
||||||
ContactListener cl = new ContactListener() {
|
|
||||||
@Override
|
|
||||||
public void beginContact(Contact contact) {
|
|
||||||
Fixture fa = contact.getFixtureA();
|
|
||||||
Fixture fb = contact.getFixtureB();
|
|
||||||
|
|
||||||
if(fa == null || fb == null) { return; }
|
|
||||||
if(fa.getUserData() == null || fb.getUserData() == null) { return; }
|
|
||||||
|
|
||||||
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("PLATFORM") ||
|
|
||||||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("PLATFORM"))
|
|
||||||
{
|
|
||||||
if(player.getCurAction() != Player.Action.IDLE) {
|
|
||||||
player.setAction(Player.Action.IDLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void endContact(Contact contact) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preSolve(Contact contact, Manifold oldManifold) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postSolve(Contact contact, ContactImpulse impulse) {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
world.setContactListener(cl);
|
world.setContactListener(cl);
|
||||||
|
|
||||||
b2dr = new Box2DDebugRenderer(); // TODO, remove
|
b2dr = new Box2DDebugRenderer(); // TODO, remove
|
||||||
|
@ -103,10 +75,11 @@ public class Play extends State {
|
||||||
public void update(float dt) {
|
public void update(float dt) {
|
||||||
world.step(dt, 6, 2);
|
world.step(dt, 6, 2);
|
||||||
|
|
||||||
cameraUpdate(dt);
|
CameraUtils.lerpToTarget(cam, player.getPos().scl(PPM).x, 0);
|
||||||
|
CameraUtils.lockOnTarget(b2dCam, player.getPos().x, player.getPos().y);
|
||||||
|
|
||||||
b2dCam.position.x = player.getPos().x;
|
Vector2 start = new Vector2(cam.viewportWidth / 2, cam.viewportHeight / 2);
|
||||||
b2dCam.update();
|
CameraUtils.setBoundary(cam, start, new Vector2(mapWidth * tileSize.x - start.x * 2, mapHeight * tileSize.y - start.y * 2));
|
||||||
|
|
||||||
player.update(dt);
|
player.update(dt);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +109,7 @@ public class Play extends State {
|
||||||
public void handleInput() {
|
public void handleInput() {
|
||||||
if(Gdx.input.isKeyPressed(Input.Keys.SPACE))
|
if(Gdx.input.isKeyPressed(Input.Keys.SPACE))
|
||||||
{
|
{
|
||||||
//jumpSound.play(); TODO, fix sound?
|
//jumpSound.play(); //TODO, fix sound?
|
||||||
player.jump();
|
player.jump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,17 +118,7 @@ public class Play extends State {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
world.dispose();
|
||||||
}
|
|
||||||
|
|
||||||
private void cameraUpdate(float dt)
|
|
||||||
{
|
|
||||||
Vector3 camPos = cam.position;
|
|
||||||
|
|
||||||
camPos.x = cam.position.x + ((player.getPos().x * PPM) - cam.position.x) * .2f;
|
|
||||||
//camPos.y = cam.position.y + ((player.getPos().y * PPM) - cam.position.y) * .2f;
|
|
||||||
cam.position.set(camPos);
|
|
||||||
cam.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLevel()
|
private void setupLevel()
|
||||||
|
@ -163,8 +126,13 @@ public class Play extends State {
|
||||||
tileMap = new TmxMapLoader().load("levels/level1.tmx");
|
tileMap = new TmxMapLoader().load("levels/level1.tmx");
|
||||||
tmr = new OrthogonalTiledMapRenderer(tileMap);
|
tmr = new OrthogonalTiledMapRenderer(tileMap);
|
||||||
|
|
||||||
|
MapProperties mapProp = tileMap.getProperties();
|
||||||
|
mapWidth = mapProp.get("width", Integer.class);
|
||||||
|
mapHeight = mapProp.get("height", Integer.class);
|
||||||
|
tileSize = new Vector2(mapProp.get("tilewidth", Integer.class), mapProp.get("tileheight", Integer.class));
|
||||||
|
|
||||||
|
|
||||||
TiledMapTileLayer platformLayer = (TiledMapTileLayer)tileMap.getLayers().get("PLATFORM");
|
TiledMapTileLayer platformLayer = (TiledMapTileLayer)tileMap.getLayers().get("PLATFORM");
|
||||||
tileSize = platformLayer.getTileWidth();
|
|
||||||
|
|
||||||
MapLayer boundaryLayer = tileMap.getLayers().get("BOUNDARY");
|
MapLayer boundaryLayer = tileMap.getLayers().get("BOUNDARY");
|
||||||
PolylineMapObject polylineObj = (PolylineMapObject)boundaryLayer.getObjects().get(0);
|
PolylineMapObject polylineObj = (PolylineMapObject)boundaryLayer.getObjects().get(0);
|
||||||
|
@ -183,14 +151,14 @@ public class Play extends State {
|
||||||
if(cell == null) { continue; }
|
if(cell == null) { continue; }
|
||||||
if(cell.getTile() == null) { continue; }
|
if(cell.getTile() == null) { continue; }
|
||||||
|
|
||||||
if(cell.getTile().getId() == 1) { platforms.add(new Platform(world, new Vector2((col + 0.5f) * tileSize, (row + 0.5f) * tileSize), Base.Colours.RED)); }
|
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, (row + 0.5f) * tileSize), Base.Colours.GREEN)); }
|
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, (row + 0.5f) * tileSize), Base.Colours.BLUE)); }
|
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)); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildBoundary(PolylineMapObject polylineObj)
|
private void buildBoundary(PolylineMapObject polylineObj)
|
||||||
{
|
{
|
||||||
Polyline r = polylineObj.getPolyline();
|
Polyline r = polylineObj.getPolyline();
|
||||||
BodyDef bd = new BodyDef();
|
BodyDef bd = new BodyDef();
|
||||||
|
@ -221,4 +189,39 @@ public class Play extends State {
|
||||||
// Accessors
|
// Accessors
|
||||||
|
|
||||||
// Mutators
|
// Mutators
|
||||||
|
|
||||||
|
// Contact Listener
|
||||||
|
ContactListener cl = new ContactListener() {
|
||||||
|
@Override
|
||||||
|
public void beginContact(Contact contact) {
|
||||||
|
Fixture fa = contact.getFixtureA();
|
||||||
|
Fixture fb = contact.getFixtureB();
|
||||||
|
|
||||||
|
if(fa == null || fb == null) { return; }
|
||||||
|
if(fa.getUserData() == null || fb.getUserData() == null) { return; }
|
||||||
|
|
||||||
|
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("PLATFORM") ||
|
||||||
|
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("PLATFORM"))
|
||||||
|
{
|
||||||
|
if(player.getCurAction() != Player.Action.IDLE) {
|
||||||
|
player.setAction(Player.Action.IDLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endContact(Contact contact) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preSolve(Contact contact, Manifold oldManifold) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postSolve(Contact contact, ContactImpulse impulse) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,26 +2,42 @@ package com.game.States;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.game.Game;
|
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||||
|
import com.game.App;
|
||||||
|
import com.game.Managers.StateManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ash on 08/02/2016.
|
* Created by Ash on 08/02/2016.
|
||||||
*/
|
*/
|
||||||
public abstract class State {
|
public abstract class State {
|
||||||
protected StateManager sm;
|
|
||||||
protected Game game;
|
|
||||||
|
|
||||||
|
// App reference
|
||||||
|
protected final App app;
|
||||||
|
|
||||||
|
// Batches
|
||||||
protected SpriteBatch sb;
|
protected SpriteBatch sb;
|
||||||
|
protected ShapeRenderer sr;
|
||||||
|
|
||||||
|
// Cameras
|
||||||
protected OrthographicCamera cam;
|
protected OrthographicCamera cam;
|
||||||
protected OrthographicCamera hudCam;
|
protected OrthographicCamera hudCam;
|
||||||
|
|
||||||
|
// Stage
|
||||||
|
protected Stage stage;
|
||||||
|
|
||||||
|
// Managers
|
||||||
|
protected final StateManager sm;
|
||||||
|
|
||||||
public State (StateManager sm)
|
public State (StateManager sm)
|
||||||
{
|
{
|
||||||
this.sm = sm;
|
this.sm = sm;
|
||||||
game = sm.game();
|
this.app = sm.app();
|
||||||
sb = game.getSpriteBatch();
|
sb = app.getSpriteBatch();
|
||||||
cam = game.getCam();
|
sr = app.getSr();
|
||||||
hudCam = game.getHudCam();
|
cam = app.getCam();
|
||||||
|
hudCam = app.getHudCam();
|
||||||
|
stage = new Stage();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void init();
|
public abstract void init();
|
||||||
|
|
|
@ -3,19 +3,19 @@ package com.game.desktop;
|
||||||
import com.badlogic.gdx.Files;
|
import com.badlogic.gdx.Files;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
|
||||||
import com.badlogic.gdx.graphics.PixmapIO;
|
import com.game.App;
|
||||||
import com.game.Game;
|
|
||||||
import com.game.Misc.Vars;
|
import com.game.Misc.Vars;
|
||||||
|
|
||||||
public class DesktopLauncher {
|
public class DesktopLauncher {
|
||||||
public static void main (String[] arg) {
|
public static void main (String[] arg) {
|
||||||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
|
||||||
new LwjglApplication(new Game(), config);
|
new LwjglApplication(new App(), config);
|
||||||
config.title = Vars.TITLE;
|
config.title = Vars.TITLE;
|
||||||
config.width = Vars.SCREEN_WIDTH;
|
config.width = Vars.SCREEN_WIDTH;
|
||||||
config.height = Vars.SCREEN_HEIGHT;
|
config.height = Vars.SCREEN_HEIGHT;
|
||||||
config.resizable = Vars.RESIZABLE;
|
config.resizable = Vars.RESIZABLE;
|
||||||
config.addIcon("spritesheets/icon.jpg", Files.FileType.Internal);
|
config.addIcon("spritesheets/icon.jpg", Files.FileType.Internal);
|
||||||
config.foregroundFPS = (int)Vars.FRAMERATE;
|
config.foregroundFPS = (int)Vars.FRAMERATE;
|
||||||
|
config.backgroundFPS = (int)Vars.FRAMERATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue