Colour changing implementation

This commit is contained in:
Ash Reynolds 2016-02-13 15:47:03 +00:00
parent 4593a6c686
commit b5fc10546d
26 changed files with 248 additions and 219 deletions

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?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="25"> <map version="1.0" orientation="orthogonal" renderorder="right-down" width="50" height="8" tilewidth="64" tileheight="64" nextobjectid="31">
<tileset firstgid="1" name="platformSet" tilewidth="64" tileheight="64" tilecount="3" columns="3"> <tileset firstgid="1" name="platformSet" tilewidth="64" tileheight="64" tilecount="3" columns="3">
<image source="../spritesheets/platformSet.png" width="192" height="64"/> <image source="../spritesheets/platformSet.png" width="192" height="64"/>
</tileset> </tileset>
<tileset firstgid="4" name="player" tilewidth="64" tileheight="64" tilecount="1" columns="1"> <tileset firstgid="4" name="player" tilewidth="64" tileheight="64" tilecount="1" columns="1">
<image source="../textures/player.png" width="64" height="64"/> <image source="../textures/player_red.png" width="64" height="64"/>
</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">
@ -19,4 +19,14 @@
<polyline points="0,0 0,1024 3328,1024 3328,0 0,0"/> <polyline points="0,0 0,1024 3328,1024 3328,0 0,0"/>
</object> </object>
</objectgroup> </objectgroup>
<objectgroup name="FAILBOUNDARY">
<object id="29" x="0" y="704">
<polyline points="0,0 3328,0 3328,128 0,128 0,0"/>
</object>
</objectgroup>
<objectgroup name="PASSBOUNDARY">
<object id="30" x="3200" y="-192">
<polyline points="0,0 0,640 128,640 128,0 0,0"/>
</object>
</objectgroup>
</map> </map>

View file

@ -1,22 +0,0 @@
<?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="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="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<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,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?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="25"> <map version="1.0" orientation="orthogonal" renderorder="right-down" width="50" height="8" tilewidth="64" tileheight="64" nextobjectid="30">
<tileset firstgid="1" name="platformSet" tilewidth="64" tileheight="64" tilecount="3" columns="3"> <tileset firstgid="1" name="platformSet" tilewidth="64" tileheight="64" tilecount="3" columns="3">
<image source="../spritesheets/platformSet.png" width="192" height="64"/> <image source="../spritesheets/platformSet.png" width="192" height="64"/>
</tileset> </tileset>
<tileset firstgid="4" name="player" tilewidth="64" tileheight="64" tilecount="1" columns="1"> <tileset firstgid="4" name="player" tilewidth="64" tileheight="64" tilecount="1" columns="1">
<image source="../textures/player.png" width="64" height="64"/> <image source="../textures/player_red.png" width="64" height="64"/>
</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">
@ -19,4 +19,14 @@
<polyline points="0,85.3333 0,1109.33 3328,1109.33 3328,85.3333 0,85.3333"/> <polyline points="0,85.3333 0,1109.33 3328,1109.33 3328,85.3333 0,85.3333"/>
</object> </object>
</objectgroup> </objectgroup>
<objectgroup name="FAILBOUNDARY">
<object id="29" x="0" y="704">
<polyline points="0,0 3328,0 3328,128 0,128 0,0"/>
</object>
</objectgroup>
<objectgroup name="PASSBOUNDARY">
<object id="28" x="3200" y="-192">
<polyline points="0,0 128,0 128,512 0,512 0,0"/>
</object>
</objectgroup>
</map> </map>

View file

@ -1,22 +0,0 @@
<?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="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="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<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,22 +0,0 @@
<?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="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="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<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,22 +0,0 @@
<?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="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="24" gid="4" x="0" y="320" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<object id="23" x="0" y="-192">
<polyline points="0,0 0,1024 3328,1024 3328,0 0,0"/>
</object>
</objectgroup>
</map>

View file

@ -1,22 +0,0 @@
<?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="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="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<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,22 +0,0 @@
<?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="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="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<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,22 +0,0 @@
<?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="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="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<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,22 +0,0 @@
<?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="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="22" gid="4" x="0" y="256" width="64" height="64"/>
</objectgroup>
<objectgroup name="BOUNDARY">
<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

@ -6,9 +6,12 @@ com.badlogic.gdx.graphics.Color: {
black: { a: 1, b: 0, g: 0, r: 0 }, black: { a: 1, b: 0, g: 0, r: 0 },
}, },
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { 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: { com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: { font: default-font, fontColor: white } default: { font: default-font, fontColor: white }
}, },
com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: {
default: { titleFont: default-font, background: null }
},
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 942 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View file

@ -11,7 +11,6 @@ public abstract class Base {
protected World world; protected World world;
// Physics definitions // Physics definitions
protected BodyDef bd;
protected Body body; protected Body body;
protected String bodyType; protected String bodyType;

View file

@ -3,6 +3,7 @@ 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;
@ -11,21 +12,23 @@ import static com.game.misc.Vars.PPM;
*/ */
public class Platform extends Base { 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); super(world, pos, size, "STATIC", curColour);
body = Box2dUtils.makeBody(world, body = Box2dUtils.makeBody(world,
BodyDef.BodyType.StaticBody, BodyDef.BodyType.StaticBody,
pos pos
); );
Box2dUtils.makePolygon(body, size, "", false); Box2dUtils.makePolygon(body, size, "", false, categoryBits, maskBits);
Box2dUtils.makeChain(body, Box2dUtils.makeChain(body,
new Vector2[]{ 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),
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", "PLATFORM",
true true,
Vars.BIT_MISC,
Vars.BIT_PLAYER
); );
} }
} }

View file

@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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.App;
import com.game.misc.Box2dUtils; import com.game.misc.Box2dUtils;
import com.game.misc.Vars; import com.game.misc.Vars;
@ -16,8 +17,7 @@ public class Player extends Base {
Vector2 curVel; Vector2 curVel;
// TODO, remove private Texture texture;
private Texture texture = new Texture("textures/player.png");
private Action curAction; private Action curAction;
public enum Action public enum Action
@ -36,7 +36,9 @@ public class Player extends Base {
BodyDef.BodyType.DynamicBody, BodyDef.BodyType.DynamicBody,
pos 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) public void update(float dt)
@ -75,4 +77,37 @@ public class Player extends Base {
// Mutators // Mutators
public void setAction(Action curAction) { this.curAction = curAction; } 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);
}
} }

View file

@ -7,15 +7,16 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.game.managers.ScreenManager; import com.game.managers.ScreenManager;
import com.game.screens.AbstractScreen;
import com.game.screens.Menu; import com.game.screens.Menu;
import com.game.screens.Play;
public class App extends Game { public class App extends Game {
// Managers // Managers
public AssetManager assets; public static AssetManager assets;
public ScreenManager sm; public ScreenManager sm;
// Batches // Batches
public SpriteBatch sb; public SpriteBatch sb;
public ShapeRenderer sr; public ShapeRenderer sr;

View file

@ -23,7 +23,7 @@ public class Box2dUtils {
return world.createBody(bd); 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(); FixtureDef fd = new FixtureDef();
@ -34,13 +34,15 @@ public class Box2dUtils {
fd.shape = shape; fd.shape = shape;
fd.density = density; fd.density = density;
fd.friction = friction; fd.friction = friction;
fd.filter.categoryBits = categoryBits;
fd.filter.maskBits = maskBits;
fd.isSensor = isSensor; fd.isSensor = isSensor;
if(userData.equals("")) { body.createFixture(fd); } if(userData.equals("")) { body.createFixture(fd); }
else { body.createFixture(fd).setUserData(userData); } 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(); FixtureDef fd = new FixtureDef();
@ -49,13 +51,15 @@ public class Box2dUtils {
fd.shape = shape; fd.shape = shape;
fd.density = density; fd.density = density;
fd.friction = friction; fd.friction = friction;
fd.filter.categoryBits = categoryBits;
fd.filter.maskBits = maskBits;
fd.isSensor = isSensor; fd.isSensor = isSensor;
if(userData.equals("")) { body.createFixture(fd); } if(userData.equals("")) { body.createFixture(fd); }
else { body.createFixture(fd).setUserData(userData); } 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(); FixtureDef fd = new FixtureDef();
@ -64,6 +68,8 @@ public class Box2dUtils {
fd.shape = shape; fd.shape = shape;
fd.density = density; fd.density = density;
fd.friction = friction; fd.friction = friction;
fd.filter.categoryBits = categoryBits;
fd.filter.maskBits = maskBits;
fd.isSensor = isSensor; fd.isSensor = isSensor;
if(userData.equals("")) { body.createFixture(fd); } if(userData.equals("")) { body.createFixture(fd); }

View file

@ -25,4 +25,6 @@ public class Vars {
public static final short BIT_RED = 2; public static final short BIT_RED = 2;
public static final short BIT_GREEN = 4; public static final short BIT_GREEN = 4;
public static final short BIT_BLUE = 8; public static final short BIT_BLUE = 8;
public static final short BIT_PLAYER = 16;
public static final short BIT_MISC = 32;
} }

View file

@ -40,10 +40,10 @@ public class Loading extends AbstractScreen {
loadFont("fonts/badaboom.TTF", 60, Color.BLACK); 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 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); loadingRect = new Rectangle(stage.getWidth() / 6f, (stage.getHeight() / 2f - 25), 0, 25);
assetsToLoad(); assetsToLoad();
@ -100,10 +100,15 @@ public class Loading extends AbstractScreen {
app.assets.load("textures/menuBackground.jpg", Texture.class); app.assets.load("textures/menuBackground.jpg", Texture.class);
app.assets.load("textures/leaderboardBackground.jpg", Texture.class); app.assets.load("textures/leaderboardBackground.jpg", Texture.class);
app.assets.load("textures/levelSelectBackground.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/position0.png", Texture.class);
app.assets.load("textures/position1.png", Texture.class); app.assets.load("textures/position1.png", Texture.class);
app.assets.load("textures/position2.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("sounds/jumping.mp3", Sound.class);
app.assets.load("music/TheComplex.mp3", Music.class); app.assets.load("music/TheComplex.mp3", Music.class);

View file

@ -5,8 +5,6 @@ import com.badlogic.gdx.Input;
import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; 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.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
@ -29,6 +27,7 @@ public class Menu extends AbstractScreen {
private Music music; private Music music;
public Menu(App app) { public Menu(App app) {
super(app); super(app);
skin = new Skin(); skin = new Skin();

View file

@ -3,7 +3,6 @@ package com.game.screens;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; 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.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; 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.Polyline;
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.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.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.App;
import com.game.managers.ScreenManager; import com.game.managers.ScreenManager;
import com.game.misc.Box2dUtils;
import com.game.misc.CameraUtils; import com.game.misc.CameraUtils;
import com.game.misc.Vars; import com.game.misc.Vars;
import javax.xml.soap.Text;
import java.util.ArrayList; import java.util.ArrayList;
import static com.game.misc.Vars.PPM; import static com.game.misc.Vars.PPM;
@ -35,6 +41,8 @@ import static com.game.misc.Vars.PPM;
*/ */
public class Play extends AbstractScreen { public class Play extends AbstractScreen {
private Skin skin;
// TODO, remove // TODO, remove
public boolean isDebug = false; public boolean isDebug = false;
@ -53,6 +61,15 @@ public class Play extends AbstractScreen {
private Player player; private Player player;
private ArrayList<Platform> platforms = new ArrayList<Platform>(); private ArrayList<Platform> platforms = new ArrayList<Platform>();
// 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 int levelNumber;
private Sound jumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/jumping.mp3")); 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) { public Play(App app, int levelNumber) {
super(app); super(app);
skin = new Skin();
this.levelNumber = levelNumber; this.levelNumber = levelNumber;
world = new World(new Vector2(0, Vars.GRAVITY.y), true); world = new World(new Vector2(0, Vars.GRAVITY.y), true);
@ -69,6 +88,9 @@ public class Play extends AbstractScreen {
b2dCam = new OrthographicCamera(); b2dCam = new OrthographicCamera();
b2dCam.setToOrtho(false, Vars.SCREEN_WIDTH / PPM, Vars.SCREEN_HEIGHT / PPM); b2dCam.setToOrtho(false, Vars.SCREEN_WIDTH / PPM, Vars.SCREEN_HEIGHT / PPM);
isPaused = false;
buttonSize = new Vector2(50, 50);
} }
@Override @Override
@ -76,16 +98,22 @@ public class Play extends AbstractScreen {
{ {
super.show(); 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 @Override
public void update(float dt) { public void update(float dt) {
if(!isPaused)
{
world.step(dt, 6, 2); world.step(dt, 6, 2);
CameraUtils.lerpToTarget(cam, player.getPos().scl(PPM).x, 0); CameraUtils.lerpToTarget(cam, player.getPos().scl(PPM).x, 0);
CameraUtils.lerpToTarget(b2dCam, player.getPos().x, player.getPos().y); CameraUtils.lerpToTarget(b2dCam, player.getPos().x, player.getPos().y);
b2dCam.zoom = 5f;
Vector2 start = new Vector2(cam.viewportWidth / 2, cam.viewportHeight / 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)); CameraUtils.setBoundary(cam, start, new Vector2(mapWidth * tileSize.x - start.x * 2, mapHeight * tileSize.y - start.y * 2));
@ -93,6 +121,15 @@ public class Play extends AbstractScreen {
player.update(dt); player.update(dt);
} }
if(pauseWindow.isVisible() != isPaused)
{
pauseWindow.setVisible(isPaused);
pauseGlow.setVisible(isPaused);
}
stage.act(dt);
}
@Override @Override
public void render(float dt) { public void render(float dt) {
super.render(dt); super.render(dt);
@ -115,6 +152,8 @@ public class Play extends AbstractScreen {
{ {
b2dr.render(world, b2dCam.combined); b2dr.render(world, b2dCam.combined);
} }
stage.draw();
} }
@Override @Override
@ -125,7 +164,27 @@ public class Play extends AbstractScreen {
player.jump(); 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; } if(Gdx.input.isKeyJustPressed(Input.Keys.V)) { isDebug = !isDebug; }
} }
@ -133,9 +192,12 @@ public class Play extends AbstractScreen {
public void dispose() { public void dispose() {
super.dispose(); super.dispose();
world.dispose(); world.dispose();
b2dr.dispose();
tileMap.dispose();
tmr.dispose();
} }
private void setupLevel() private void initLevel()
{ {
tileMap = new TmxMapLoader().load("levels/level" + levelNumber + ".tmx"); tileMap = new TmxMapLoader().load("levels/level" + levelNumber + ".tmx");
tmr = new OrthogonalTiledMapRenderer(tileMap); tmr = new OrthogonalTiledMapRenderer(tileMap);
@ -150,7 +212,15 @@ public class Play extends AbstractScreen {
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);
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"); MapLayer playerLayer = tileMap.getLayers().get("PLAYER");
TextureMapObject playerObj = (TextureMapObject)playerLayer.getObjects().get(0); TextureMapObject playerObj = (TextureMapObject)playerLayer.getObjects().get(0);
@ -165,14 +235,14 @@ public class Play extends AbstractScreen {
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.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), 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, 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)); } 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)); } 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(); Polyline r = polylineObj.getPolyline();
BodyDef bd = new BodyDef(); BodyDef bd = new BodyDef();
@ -180,10 +250,6 @@ public class Play extends AbstractScreen {
Body body = world.createBody(bd); Body body = world.createBody(bd);
FixtureDef fd = new FixtureDef();
ChainShape chain = new ChainShape();
float[] v = r.getTransformedVertices(); float[] v = r.getTransformedVertices();
Vector2[] finalV = new Vector2[v.length / 2]; Vector2[] finalV = new Vector2[v.length / 2];
@ -194,10 +260,58 @@ public class Play extends AbstractScreen {
finalV[i].y = v[i * 2 + 1] / PPM; finalV[i].y = v[i * 2 + 1] / PPM;
} }
chain.createChain(finalV); Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_MISC, Vars.BIT_PLAYER);
fd.shape = chain; }
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 // Accessors
@ -219,8 +333,25 @@ public class Play extends AbstractScreen {
{ {
if(player.getCurAction() != Player.Action.IDLE) { if(player.getCurAction() != Player.Action.IDLE) {
player.setAction(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 @Override

View file

@ -38,6 +38,7 @@ public class ScreenManager {
public void setPlayScreen(int levelNumber) public void setPlayScreen(int levelNumber)
{ {
// remove loaded level // remove loaded level
if(screens.get(Screen.PLAY) != null) if(screens.get(Screen.PLAY) != null)
{ {