Did some stuff
This commit is contained in:
parent
9cd355036c
commit
e1e49d3e19
71 changed files with 1004 additions and 1278 deletions
|
@ -12,7 +12,6 @@ public abstract class Base {
|
|||
|
||||
// Physics definitions
|
||||
protected Body body;
|
||||
protected String bodyType;
|
||||
|
||||
// Position and Size
|
||||
protected Vector2 pos;
|
||||
|
@ -24,16 +23,14 @@ public abstract class Base {
|
|||
RED,
|
||||
GREEN,
|
||||
BLUE,
|
||||
YELLOW,
|
||||
NONE,
|
||||
WHITE
|
||||
}
|
||||
|
||||
public Base(World world, Vector2 pos, Vector2 size, String bodyType, Colours curColour)
|
||||
public Base(World world, Vector2 pos, Vector2 size, Colours curColour)
|
||||
{
|
||||
this.world = world;
|
||||
this.pos = pos;
|
||||
this.size = size;
|
||||
this.bodyType = bodyType;
|
||||
this.curColour = curColour;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
package com.game.actor;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Animation;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.Body;
|
||||
|
||||
import static com.game.misc.Vars.PPM;
|
||||
|
||||
/**
|
||||
* Created by Ash on 09/02/2016.
|
||||
*/
|
||||
public class Box2DSprite {
|
||||
|
||||
protected Body body;
|
||||
protected Animation animation;
|
||||
|
||||
protected float width, height;
|
||||
protected Vector2 pos;
|
||||
|
||||
protected TextureRegion currentFrame;
|
||||
|
||||
public Box2DSprite(Body body)
|
||||
{
|
||||
this.body = body;
|
||||
//setAnimation();
|
||||
}
|
||||
|
||||
public void update(float dt)
|
||||
{
|
||||
pos = body.getPosition();
|
||||
currentFrame = animation.getKeyFrame(dt, true);
|
||||
}
|
||||
|
||||
public void render(SpriteBatch sb)
|
||||
{
|
||||
sb.begin();
|
||||
sb.draw(currentFrame,
|
||||
(pos.x * PPM) - width / 2,
|
||||
(pos.y * PPM) - height / 2
|
||||
);
|
||||
sb.end();
|
||||
|
||||
}
|
||||
|
||||
/*public void setAnimation(TextureRegion[] reg, float delay)
|
||||
{
|
||||
setAnimation(reg, delay);
|
||||
}*/
|
||||
|
||||
|
||||
}
|
93
core/src/com/game/Actor/Enemy.java
Normal file
93
core/src/com/game/Actor/Enemy.java
Normal file
|
@ -0,0 +1,93 @@
|
|||
package com.game.actor;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.*;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.game.App;
|
||||
import com.game.misc.utils.Box2dUtils;
|
||||
import com.game.misc.Vars;
|
||||
|
||||
import static com.game.misc.Vars.PPM;
|
||||
|
||||
/**
|
||||
* Created by Ash on 22/02/2016.
|
||||
*/
|
||||
public class Enemy extends Base {
|
||||
|
||||
private Sprite sprite;
|
||||
private boolean isAlive;
|
||||
|
||||
public Enemy(World world, Vector2 pos, Vector2 size, Colours curColour, short categoryBits, short maskBits) {
|
||||
super(world, pos, size, curColour);
|
||||
|
||||
body = Box2dUtils.makeBody(world,
|
||||
BodyDef.BodyType.StaticBody,
|
||||
pos
|
||||
);
|
||||
Box2dUtils.makePolygon(body, size, "ENEMY", true, 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)
|
||||
},
|
||||
"ENEMY",
|
||||
true,
|
||||
Vars.BIT_ALL,
|
||||
Vars.BIT_PLAYER
|
||||
);*/
|
||||
|
||||
isAlive = true;
|
||||
|
||||
sprite = new Sprite(App.assets.get("textures/enemies/redAlive.png", Texture.class));
|
||||
sprite.setPosition(pos.x - size.x / 2, pos.y - size.y / 2);
|
||||
setCurColour(curColour);
|
||||
}
|
||||
|
||||
public void render(SpriteBatch sb)
|
||||
{
|
||||
sprite.draw(sb);
|
||||
}
|
||||
|
||||
@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;
|
||||
if(isAlive) { sprite.setTexture(App.assets.get("textures/enemies/redAlive.png", Texture.class)); }
|
||||
else { sprite.setTexture(App.assets.get("textures/enemies/redDead.png", Texture.class)); }
|
||||
break;
|
||||
case GREEN:
|
||||
bits &= ~Vars.BIT_RED;
|
||||
bits &= ~Vars.BIT_BLUE;
|
||||
bits |= Vars.BIT_GREEN;
|
||||
if(isAlive) { sprite.setTexture(App.assets.get("textures/enemies/greenAlive.png", Texture.class)); }
|
||||
else { sprite.setTexture(App.assets.get("textures/enemies/greenDead.png", Texture.class)); }
|
||||
break;
|
||||
case BLUE:
|
||||
bits &= ~Vars.BIT_RED;
|
||||
bits &= ~Vars.BIT_GREEN;
|
||||
bits |= Vars.BIT_BLUE;
|
||||
if(isAlive) { sprite.setTexture(App.assets.get("textures/enemies/blueAlive.png", Texture.class)); }
|
||||
else { sprite.setTexture(App.assets.get("textures/enemies/blueDead.png", Texture.class)); }
|
||||
break;
|
||||
}
|
||||
|
||||
filter.maskBits = bits;
|
||||
body.getFixtureList().first().setFilterData(filter);
|
||||
}
|
||||
|
||||
public void setAlive(boolean isAlive) { this.isAlive = isAlive; }
|
||||
|
||||
public Array<Fixture> getFixtures() { return body.getFixtureList(); }
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package com.game.actor.object;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.game.misc.Vars;
|
||||
|
||||
/**
|
||||
* Created by Ash on 09/02/2016.
|
||||
*/
|
||||
public class Background {
|
||||
|
||||
private Vector2 pos;
|
||||
|
||||
private Texture texture;
|
||||
|
||||
public Background(String path)
|
||||
{
|
||||
loadTexture(path);
|
||||
}
|
||||
|
||||
public void update(float dt, Vector2 pos)
|
||||
{
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public void render(SpriteBatch sb)
|
||||
{
|
||||
sb.draw(texture, pos.x, pos.y, Vars.SCREEN_WIDTH, Vars.SCREEN_HEIGHT);
|
||||
}
|
||||
|
||||
private void loadTexture(String path)
|
||||
{
|
||||
this.texture = new Texture(path);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package com.game.actor;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
|
@ -9,7 +8,7 @@ import com.badlogic.gdx.math.MathUtils;
|
|||
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.utils.Box2dUtils;
|
||||
import com.game.misc.Vars;
|
||||
|
||||
import static com.game.misc.Vars.PPM;
|
||||
|
@ -36,19 +35,20 @@ public class Player extends Base {
|
|||
private Sound colourchangeSound;
|
||||
|
||||
public Player(World world, Vector2 pos, Vector2 size, Colours curColour) {
|
||||
super(world, pos, size, "", curColour);
|
||||
super(world, pos, size, curColour);
|
||||
curAction = Action.IDLE;
|
||||
|
||||
body = Box2dUtils.makeBody(world,
|
||||
BodyDef.BodyType.DynamicBody,
|
||||
pos
|
||||
);
|
||||
Box2dUtils.makeCircle(body, size.x, "PLAYER", false, Vars.BIT_PLAYER, (short)(Vars.BIT_RED | Vars.BIT_PRISMATIC));
|
||||
Box2dUtils.makeCircle(body, size.x, "PLAYER", false, Vars.BIT_PLAYER, (short)(Vars.BIT_RED | Vars.BIT_ALL));
|
||||
|
||||
jumpSound = App.assets.get("sounds/jumping.mp3", Sound.class);
|
||||
colourchangeSound = App.assets.get("sounds/colourchange.mp3", Sound.class);
|
||||
|
||||
sprite = new Sprite(App.assets.get("textures/player_red.png", Texture.class));
|
||||
sprite = new Sprite(App.assets.get("textures/player/player_red.png", Texture.class));
|
||||
sprite.setPosition((pos.x * PPM) - size.x / 2, (pos.y * PPM) - size.y / 2);
|
||||
}
|
||||
|
||||
public void update(float dt)
|
||||
|
@ -100,30 +100,20 @@ public class Player extends Base {
|
|||
case RED:
|
||||
bits &= ~Vars.BIT_GREEN;
|
||||
bits &= ~Vars.BIT_BLUE;
|
||||
bits &= ~Vars.BIT_YELLOW;
|
||||
bits |= Vars.BIT_RED;
|
||||
sprite.setTexture(App.assets.get("textures/player_red.png", Texture.class));
|
||||
sprite.setTexture(App.assets.get("textures/player/player_red.png", Texture.class));
|
||||
break;
|
||||
case GREEN:
|
||||
bits &= ~Vars.BIT_RED;
|
||||
bits &= ~Vars.BIT_BLUE;
|
||||
bits &= ~Vars.BIT_YELLOW;
|
||||
bits |= Vars.BIT_GREEN;
|
||||
sprite.setTexture(App.assets.get("textures/player_green.png", Texture.class));
|
||||
sprite.setTexture(App.assets.get("textures/player/player_green.png", Texture.class));
|
||||
break;
|
||||
case BLUE:
|
||||
bits &= ~Vars.BIT_RED;
|
||||
bits &= ~Vars.BIT_GREEN;
|
||||
bits &= ~Vars.BIT_YELLOW;
|
||||
bits |= Vars.BIT_BLUE;
|
||||
sprite.setTexture(App.assets.get("textures/player_blue.png", Texture.class));
|
||||
break;
|
||||
case YELLOW:
|
||||
bits &= ~Vars.BIT_RED;
|
||||
bits &= ~Vars.BIT_GREEN;
|
||||
bits &= ~Vars.BIT_BLUE;
|
||||
bits |= Vars.BIT_YELLOW;
|
||||
sprite.setTexture(App.assets.get("textures/player_yellow.png", Texture.class));
|
||||
sprite.setTexture(App.assets.get("textures/player/player_blue.png", Texture.class));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
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) {
|
||||
super(world, pos, size, "STATIC", curColour);
|
||||
|
||||
body = Box2dUtils.makeBody(world,
|
||||
BodyDef.BodyType.StaticBody,
|
||||
pos
|
||||
);
|
||||
|
||||
short maskBits = 0;
|
||||
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)
|
||||
},
|
||||
"SPIKES",
|
||||
true,
|
||||
<<<<<<< HEAD
|
||||
Vars.BIT_PRISMATIC,
|
||||
Vars.BIT_PLAYER
|
||||
=======
|
||||
Vars.BIT_MISC, maskBits
|
||||
>>>>>>> origin/master
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package com.game.actor;
|
||||
package com.game.actor.object;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.*;
|
||||
import com.game.misc.Box2dUtils;
|
||||
import com.game.actor.Base;
|
||||
import com.game.misc.utils.Box2dUtils;
|
||||
import com.game.misc.Vars;
|
||||
|
||||
import static com.game.misc.Vars.PPM;
|
||||
|
@ -13,7 +14,7 @@ import static com.game.misc.Vars.PPM;
|
|||
public class Platform extends Base {
|
||||
|
||||
public Platform(World world, Vector2 pos, Vector2 size, Colours curColour, short categoryBits, short maskBits) {
|
||||
super(world, pos, size, "STATIC", curColour);
|
||||
super(world, pos, size, curColour);
|
||||
|
||||
body = Box2dUtils.makeBody(world,
|
||||
BodyDef.BodyType.StaticBody,
|
||||
|
@ -27,7 +28,7 @@ public class Platform extends Base {
|
|||
},
|
||||
"PLATFORM",
|
||||
true,
|
||||
Vars.BIT_PRISMATIC,
|
||||
Vars.BIT_ALL,
|
||||
Vars.BIT_PLAYER
|
||||
);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package com.game.misc;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.game.actor.object.Background;
|
||||
|
||||
/**
|
||||
* Created by Ash on 09/02/2016.
|
||||
*/
|
||||
public class ParralaxBackground {
|
||||
private Background back;
|
||||
private Background middle;
|
||||
private Background front;
|
||||
|
||||
public ParralaxBackground(String back, String middle, String front)
|
||||
{
|
||||
this.back = new Background(back);
|
||||
createBackground(middle);
|
||||
createBackground(front);
|
||||
}
|
||||
|
||||
public void update(float dt)
|
||||
{
|
||||
Vector2 movementAmount = new Vector2(.1f, 0);
|
||||
|
||||
back.update(dt, movementAmount);
|
||||
|
||||
middle.update(dt, movementAmount);
|
||||
|
||||
front.update(dt, movementAmount);
|
||||
}
|
||||
|
||||
private void createBackground(String path)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -23,9 +23,8 @@ public class Vars {
|
|||
|
||||
// Filter bits
|
||||
public static final short BIT_PLAYER = 1;
|
||||
public static final short BIT_PRISMATIC = 1;
|
||||
public static final short BIT_ALL = 1;
|
||||
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_YELLOW = 16;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.game.misc;
|
||||
package com.game.misc.utils;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.physics.box2d.*;
|
|
@ -1,4 +1,4 @@
|
|||
package com.game.misc;
|
||||
package com.game.misc.utils;
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
@ -13,7 +13,8 @@ public class CameraUtils {
|
|||
{
|
||||
Vector3 pos = cam.position;
|
||||
pos.x = cam.position.x + (tarX - cam.position.x) * .2f;
|
||||
pos.y = cam.position.y + (tarY - cam.position.y) * .2f;;
|
||||
pos.y = cam.position.y + (tarY - cam.position.y) * .2f;
|
||||
|
||||
cam.position.set(pos);
|
||||
cam.update();
|
||||
}
|
||||
|
@ -21,24 +22,12 @@ public class CameraUtils {
|
|||
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) { pos.x = start.x; }
|
||||
if(pos.x > start.x + size.x) { pos.x = start.x + size.x; }
|
||||
|
||||
if(pos.x > start.x + size.x)
|
||||
{
|
||||
pos.x = start.x + size.x;
|
||||
}
|
||||
if(pos.y < start.y) { pos.y = start.y; }
|
||||
if(pos.y > start.y + size.y) { pos.y = start.y + size.y; }
|
||||
|
||||
if(pos.y > start.y + size.y)
|
||||
{
|
||||
pos.y = start.y + size.y;
|
||||
}
|
||||
cam.position.set(pos);
|
||||
cam.update();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.game.misc;
|
||||
package com.game.misc.utils;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
|
@ -1,4 +1,4 @@
|
|||
package com.game.misc;
|
||||
package com.game.misc.utils;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.Vector2;
|
|
@ -1,467 +0,0 @@
|
|||
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.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
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.TextureMapObject;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMap;
|
||||
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
|
||||
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
|
||||
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.App;
|
||||
import com.game.managers.ScreenManager;
|
||||
import com.game.misc.Box2dUtils;
|
||||
import com.game.misc.Vars;
|
||||
import com.game.screens.AbstractScreen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.game.misc.Vars.PPM;
|
||||
|
||||
/**
|
||||
* Created by Elliot on 16/02/2016.
|
||||
*/
|
||||
public class EndlessMode extends AbstractScreen {
|
||||
|
||||
private Skin skin;
|
||||
|
||||
// TODO, remove
|
||||
public boolean isDebug = false;
|
||||
|
||||
// Physics related
|
||||
private World world;
|
||||
private Box2DDebugRenderer b2dr; // TODO, remove
|
||||
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;
|
||||
private Vector2 tileSize;
|
||||
|
||||
// All Actors in level
|
||||
private com.game.actor.Player player;
|
||||
private ArrayList<com.game.actor.Platform> platforms = new ArrayList<com.game.actor.Platform>();
|
||||
|
||||
// Intro window
|
||||
private boolean hasPlayedOnce = false;
|
||||
private boolean isIntro;
|
||||
private Window introWindow;
|
||||
private Image introBackground;
|
||||
private TextButton butProceed;
|
||||
|
||||
// Pause window
|
||||
private boolean isPaused;
|
||||
private Window pauseWindow;
|
||||
private Image pauseBackground;
|
||||
private Image pauseGlow;
|
||||
private TextButton butContinue, butReset, butExit;
|
||||
private Vector2 buttonSize;
|
||||
|
||||
// Endgame window
|
||||
private boolean isEnd;
|
||||
private boolean isSuccess;
|
||||
private Window endgameWindow;
|
||||
private TextButton butNext;
|
||||
private Image failureBackground, successBackground;
|
||||
|
||||
private int levelNumber;
|
||||
|
||||
private Sound jumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/jumping.mp3"));
|
||||
private Sound colourchangeSound = Gdx.audio.newSound(Gdx.files.internal("sounds/colourchange.mp3"));
|
||||
|
||||
public EndlessMode(App app) {
|
||||
super(app);
|
||||
|
||||
skin = new Skin();
|
||||
world = new World(new Vector2(0, com.game.misc.Vars.GRAVITY.y), true);
|
||||
world.setContactListener(cl);
|
||||
|
||||
b2dr = new Box2DDebugRenderer(); // TODO, remove
|
||||
|
||||
b2dCam = new OrthographicCamera();
|
||||
b2dCam.setToOrtho(false, com.game.misc.Vars.SCREEN_WIDTH / PPM, com.game.misc.Vars.SCREEN_HEIGHT / PPM);
|
||||
|
||||
isIntro = true;
|
||||
isPaused = false;
|
||||
|
||||
buttonSize = new Vector2(50, 50);
|
||||
|
||||
isEnd = false;
|
||||
isSuccess = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
super.show();
|
||||
|
||||
skin.add("default-font", app.assets.get("badaboom60.ttf", BitmapFont.class));
|
||||
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
|
||||
|
||||
initLevel();
|
||||
initIntroWindow();
|
||||
initPauseWindow();
|
||||
initEndgameWindow(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
if (!isPaused && !isEnd && !isIntro) {
|
||||
world.step(dt, 6, 2);
|
||||
|
||||
com.game.misc.CameraUtils.lerpToTarget(cam, player.getPos().scl(PPM).x, 0);
|
||||
com.game.misc.CameraUtils.lerpToTarget(b2dCam, player.getPos().x, player.getPos().y);
|
||||
b2dCam.zoom = 5f;
|
||||
|
||||
Vector2 start = new Vector2(cam.viewportWidth / 2, cam.viewportHeight / 2);
|
||||
com.game.misc.CameraUtils.setBoundary(cam, start, new Vector2(mapWidth * tileSize.x - start.x * 2, mapHeight * tileSize.y - start.y * 2));
|
||||
|
||||
player.update(dt);
|
||||
}
|
||||
|
||||
if (pauseWindow.isVisible() != isPaused) {
|
||||
pauseWindow.setVisible(isPaused);
|
||||
pauseGlow.setVisible(isPaused);
|
||||
}
|
||||
|
||||
if (endgameWindow.isVisible() != isEnd) {
|
||||
initEndgameWindow(isSuccess);
|
||||
|
||||
endgameWindow.setVisible(isEnd);
|
||||
endgameWindow.setVisible(isEnd);
|
||||
}
|
||||
|
||||
stage.act(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(float dt) {
|
||||
super.render(dt);
|
||||
|
||||
app.sb.setProjectionMatrix(cam.combined);
|
||||
|
||||
if (!isDebug) {
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("textures/position0.png", Texture.class), cam.position.x - cam.viewportWidth / 2, cam.position.y - cam.viewportHeight / 2);
|
||||
app.sb.draw(app.assets.get("textures/position1.png", Texture.class), cam.position.x - cam.viewportWidth / 2, cam.position.y - (cam.viewportHeight / 2) + 75);
|
||||
app.sb.draw(app.assets.get("textures/position2.png", Texture.class), cam.position.x - cam.viewportWidth / 2, cam.position.y - (cam.viewportHeight / 2) - 150);
|
||||
player.render(app.sb);
|
||||
app.sb.end();
|
||||
|
||||
tmr.setView(cam);
|
||||
tmr.render();
|
||||
} else {
|
||||
b2dr.render(world, b2dCam.combined);
|
||||
}
|
||||
|
||||
stage.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInput() {
|
||||
if (Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
|
||||
jumpSound.play();
|
||||
player.jump();
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE)) {
|
||||
isPaused = !isPaused;
|
||||
System.out.println("isPaused: " + isPaused);
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) {
|
||||
if (!isPaused) {
|
||||
colourchangeSound.play();
|
||||
player.setCurColour(com.game.actor.Base.Colours.RED);
|
||||
}
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) {
|
||||
if (!isPaused) {
|
||||
colourchangeSound.play();
|
||||
player.setCurColour(com.game.actor.Base.Colours.GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) {
|
||||
if (!isPaused) {
|
||||
colourchangeSound.play();
|
||||
player.setCurColour(com.game.actor.Base.Colours.BLUE);
|
||||
}
|
||||
}
|
||||
if (Gdx.input.isKeyJustPressed(Input.Keys.NUM_4)) {
|
||||
if (!isPaused) {
|
||||
player.setCurColour(com.game.actor.Base.Colours.YELLOW);
|
||||
}
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(Input.Keys.V)) {
|
||||
isDebug = !isDebug;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
world.dispose();
|
||||
b2dr.dispose();
|
||||
tileMap.dispose();
|
||||
tmr.dispose();
|
||||
}
|
||||
|
||||
private void initLevel() {
|
||||
tileMap = new TmxMapLoader().load("endlessblocks/endless1.tmx");
|
||||
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");
|
||||
|
||||
MapLayer boundaryLayer = tileMap.getLayers().get("BOUNDARY");
|
||||
PolylineMapObject polylineObj = (PolylineMapObject) boundaryLayer.getObjects().get(0);
|
||||
initBoundary(polylineObj, "BOUNDARY", false);
|
||||
|
||||
tmr = new OrthogonalTiledMapRenderer(tileMap);
|
||||
|
||||
boundaryLayer = tileMap.getLayers().get("FAILBOUNDARY");
|
||||
polylineObj = (PolylineMapObject) boundaryLayer.getObjects().get(0);
|
||||
initBoundary(polylineObj, "FAILBOUNDARY", true);
|
||||
|
||||
MapLayer playerLayer = tileMap.getLayers().get("PLAYER");
|
||||
TextureMapObject playerObj = (TextureMapObject) playerLayer.getObjects().get(0);
|
||||
player = new com.game.actor.Player(world, new Vector2(playerObj.getX(), playerObj.getY()), new Vector2(60, 60), com.game.actor.Base.Colours.NONE);
|
||||
|
||||
for (int row = 0; row < platformLayer.getHeight(); row++) {
|
||||
for (int col = 0; col < platformLayer.getWidth(); col++) {
|
||||
TiledMapTileLayer.Cell cell = platformLayer.getCell(col, row);
|
||||
|
||||
if (cell == null) {
|
||||
continue;
|
||||
}
|
||||
if (cell.getTile() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cell.getTile().getId() == 1) {
|
||||
platforms.add(new com.game.actor.Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), com.game.actor.Base.Colours.RED, com.game.misc.Vars.BIT_RED, com.game.misc.Vars.BIT_PLAYER));
|
||||
} else if (cell.getTile().getId() == 2) {
|
||||
platforms.add(new com.game.actor.Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), com.game.actor.Base.Colours.GREEN, com.game.misc.Vars.BIT_GREEN, com.game.misc.Vars.BIT_PLAYER));
|
||||
} else if (cell.getTile().getId() == 3) {
|
||||
platforms.add(new com.game.actor.Platform(world, new Vector2((col + 0.5f) * tileSize.x, (row + 0.5f) * tileSize.y), new Vector2(tileSize.x, tileSize.y), com.game.actor.Base.Colours.BLUE, com.game.misc.Vars.BIT_BLUE, com.game.misc.Vars.BIT_PLAYER));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initBoundary(PolylineMapObject polylineObj, String userData, boolean isSensor)
|
||||
{
|
||||
Polyline r = polylineObj.getPolyline();
|
||||
BodyDef bd = new BodyDef();
|
||||
bd.type = BodyDef.BodyType.StaticBody;
|
||||
|
||||
Body body = world.createBody(bd);
|
||||
|
||||
float[] v = r.getTransformedVertices();
|
||||
Vector2[] finalV = new Vector2[v.length / 2];
|
||||
|
||||
for(int i = 0; i < v.length / 2; ++i)
|
||||
{
|
||||
finalV[i] = new Vector2();
|
||||
finalV[i].x = v[i * 2] / PPM;
|
||||
finalV[i].y = v[i * 2 + 1] / PPM;
|
||||
}
|
||||
|
||||
Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_PRISMATIC, Vars.BIT_PLAYER);
|
||||
}
|
||||
|
||||
private void initIntroWindow() {
|
||||
isPaused = true;
|
||||
introWindow = new Window("Level " + levelNumber, skin);
|
||||
introWindow.getTitleLabel().setPosition(350, 500);
|
||||
introBackground = new Image(app.assets.get("textures/level1Intro.png", Texture.class));
|
||||
introWindow.setBackground(introBackground.getDrawable());
|
||||
introWindow.setSize(700, 500);
|
||||
introWindow.setPosition(280, 50);
|
||||
introWindow.setVisible(true);
|
||||
|
||||
butProceed = new TextButton("PROCEED", skin, "default");
|
||||
butProceed.setPosition((introWindow.getWidth() / 4) * 3, buttonSize.y + 360);
|
||||
butProceed.setSize(buttonSize.x, buttonSize.y);
|
||||
butProceed.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
introWindow.setVisible(false);
|
||||
isIntro = false;
|
||||
isPaused = false;
|
||||
}
|
||||
});
|
||||
|
||||
introWindow.addActor(butProceed);
|
||||
|
||||
|
||||
if (!hasPlayedOnce) {
|
||||
stage.addActor(introWindow);
|
||||
hasPlayedOnce = true;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void initEndgameWindow(boolean success) {
|
||||
isPaused = true;
|
||||
if (success) {
|
||||
endgameWindow = new Window("Success", skin);
|
||||
successBackground = new Image(app.assets.get("textures/successBackground.png", Texture.class));
|
||||
endgameWindow.setBackground(successBackground.getDrawable());
|
||||
|
||||
butNext = new TextButton("Next", skin, "default");
|
||||
butNext.setPosition((pauseWindow.getWidth() / 2) - buttonSize.x / 2, buttonSize.y + 240);
|
||||
butNext.setSize(buttonSize.x, buttonSize.y);
|
||||
butNext.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
app.sm.setPlayScreen(levelNumber + 1);
|
||||
}
|
||||
});
|
||||
endgameWindow.addActor(butNext);
|
||||
} else {
|
||||
endgameWindow = new Window("Failure", skin);
|
||||
failureBackground = new Image(app.assets.get("textures/failureBackground.png", Texture.class));
|
||||
endgameWindow.setBackground(failureBackground.getDrawable());
|
||||
}
|
||||
endgameWindow.getTitleLabel().setPosition(350, 500);
|
||||
endgameWindow.setSize(700, 500);
|
||||
endgameWindow.setPosition(280, 50);
|
||||
endgameWindow.setVisible(false);
|
||||
|
||||
endgameWindow.addActor(butReset);
|
||||
endgameWindow.addActor(butExit);
|
||||
|
||||
stage.addActor(pauseGlow);
|
||||
stage.addActor(endgameWindow);
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
||||
// 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() != com.game.actor.Player.Action.IDLE) {
|
||||
player.setAction(com.game.actor.Player.Action.IDLE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fa.getUserData().equals("PLAYER") && fb.getUserData().equals("PASSBOUNDARY") ||
|
||||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("PASSBOUNDARY")) {
|
||||
isEnd = true;
|
||||
isSuccess = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (fa.getUserData().equals("PLAYER") && fb.getUserData().equals("FAILBOUNDARY") ||
|
||||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("FAILBOUNDARY")) {
|
||||
isEnd = true;
|
||||
isSuccess = false;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endContact(Contact contact) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preSolve(Contact contact, Manifold oldManifold) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postSolve(Contact contact, ContactImpulse impulse) {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
|
@ -50,7 +50,7 @@ public class Leaderboard extends AbstractScreen {
|
|||
super.render(dt);
|
||||
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("textures/leaderboardBackground.jpg", Texture.class), 0, 0);
|
||||
app.sb.draw(app.assets.get("textures/backgrounds/leaderboardBackground.jpg", Texture.class), 0, 0);
|
||||
app.sb.end();
|
||||
|
||||
stage.draw();
|
||||
|
|
|
@ -54,7 +54,7 @@ public class LevelSelect extends AbstractScreen {
|
|||
super.render(dt);
|
||||
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("textures/levelSelectBackground.jpg", Texture.class), 0, 0);
|
||||
app.sb.draw(app.assets.get("textures/backgrounds/levelSelectBackground.jpg", Texture.class), 0, 0);
|
||||
app.sb.end();
|
||||
|
||||
stage.draw();
|
||||
|
@ -106,7 +106,7 @@ public class LevelSelect extends AbstractScreen {
|
|||
butEndless.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
app.sm.setScreen(ScreenManager.Screen.ENDLESSMODE);
|
||||
//app.sm.setScreen(ScreenManager.Screen.ENDLESSMODE); TODO, finish this ;)
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@ public class Loading extends AbstractScreen {
|
|||
|
||||
loadFont("fonts/badaboom.TTF", 60, Color.BLACK);
|
||||
|
||||
app.assets.load("textures/player_red.png", Texture.class);
|
||||
app.assets.load("textures/player/player_red.png", Texture.class);
|
||||
app.assets.finishLoading(); // make sure player texture and font is loaded
|
||||
|
||||
logo = app.assets.get("textures/player_red.png", Texture.class);
|
||||
logo = app.assets.get("textures/player/player_red.png", Texture.class);
|
||||
loadingRect = new Rectangle(stage.getWidth() / 6f, (stage.getHeight() / 2f - 25), 0, 25);
|
||||
|
||||
assetsToLoad();
|
||||
|
@ -97,25 +97,30 @@ public class Loading extends AbstractScreen {
|
|||
loadFont("fonts/badaboom.TTF", 45, Color.BLACK);
|
||||
|
||||
// Textures
|
||||
app.assets.load("textures/badlogic.jpg", Texture.class);
|
||||
app.assets.load("textures/menuBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/leaderboardBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/levelSelectBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/pauseBackground.png", Texture.class);
|
||||
app.assets.load("textures/failureBackground.png", Texture.class);
|
||||
app.assets.load("textures/successBackground.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/Spikes.png", Texture.class);
|
||||
app.assets.load("textures/backgrounds/menuBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/backgrounds/leaderboardBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/backgrounds/levelSelectBackground.jpg", Texture.class);
|
||||
app.assets.load("textures/backgrounds/pauseBackground.png", Texture.class);
|
||||
app.assets.load("textures/backgrounds/failureBackground.png", Texture.class);
|
||||
app.assets.load("textures/backgrounds/successBackground.png", Texture.class);
|
||||
app.assets.load("textures/backgrounds/position0.png", Texture.class);
|
||||
app.assets.load("textures/backgrounds/position1.png", Texture.class);
|
||||
app.assets.load("textures/backgrounds/position2.png", Texture.class);
|
||||
|
||||
for(int i = 1; i <= 10; i++)
|
||||
{
|
||||
app.assets.load("textures/level" + i + "Intro.png", Texture.class);
|
||||
app.assets.load("textures/intros/level" + i + "Intro.png", Texture.class);
|
||||
}
|
||||
app.assets.load("textures/player_green.png", Texture.class);
|
||||
app.assets.load("textures/player_blue.png", Texture.class);
|
||||
app.assets.load("textures/player_yellow.png", Texture.class);
|
||||
app.assets.load("textures/player/player_green.png", Texture.class);
|
||||
app.assets.load("textures/player/player_blue.png", Texture.class);
|
||||
app.assets.load("textures/player/player_yellow.png", Texture.class);
|
||||
|
||||
app.assets.load("textures/enemies/redAlive.png", Texture.class);
|
||||
app.assets.load("textures/enemies/redDead.png", Texture.class);
|
||||
app.assets.load("textures/enemies/greenAlive.png", Texture.class);
|
||||
app.assets.load("textures/enemies/greenDead.png", Texture.class);
|
||||
app.assets.load("textures/enemies/blueAlive.png", Texture.class);
|
||||
app.assets.load("textures/enemies/blueDead.png", Texture.class);
|
||||
|
||||
// Spritesheets
|
||||
app.assets.load("spritesheets/platformSet.png", Texture.class);
|
||||
|
|
|
@ -61,7 +61,7 @@ public class Menu extends AbstractScreen {
|
|||
super.render(dt);
|
||||
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("textures/menuBackground.jpg", Texture.class), 0, 0);
|
||||
app.sb.draw(app.assets.get("textures/backgrounds/menuBackground.jpg", Texture.class), 0, 0);
|
||||
app.sb.end();
|
||||
|
||||
stage.draw();
|
||||
|
|
|
@ -2,12 +2,12 @@ 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.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.maps.MapLayer;
|
||||
import com.badlogic.gdx.maps.MapObjects;
|
||||
import com.badlogic.gdx.maps.MapProperties;
|
||||
import com.badlogic.gdx.maps.objects.PolylineMapObject;
|
||||
import com.badlogic.gdx.maps.objects.TextureMapObject;
|
||||
|
@ -20,20 +20,26 @@ import com.badlogic.gdx.math.Polyline;
|
|||
import com.badlogic.gdx.math.Rectangle;
|
||||
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.utils.ClickListener;
|
||||
import com.game.actor.Base;
|
||||
import com.game.actor.Platform;
|
||||
import com.game.actor.Enemy;
|
||||
import com.game.actor.object.Platform;
|
||||
import com.game.actor.Player;
|
||||
import com.game.App;
|
||||
import com.game.actor.Spike;
|
||||
import com.game.managers.ScreenManager;
|
||||
import com.game.misc.*;
|
||||
import com.game.misc.myWindow;
|
||||
import com.game.misc.utils.myButton;
|
||||
import com.game.misc.utils.myWindow;
|
||||
import com.game.misc.utils.Box2dUtils;
|
||||
import com.game.misc.utils.CameraUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.game.misc.Vars.BIT_ALL;
|
||||
import static com.game.misc.Vars.BIT_PLAYER;
|
||||
import static com.game.misc.Vars.PPM;
|
||||
|
||||
/**
|
||||
|
@ -41,30 +47,6 @@ import static com.game.misc.Vars.PPM;
|
|||
*/
|
||||
public class Play extends AbstractScreen {
|
||||
|
||||
private Skin skin;
|
||||
|
||||
// TODO, remove
|
||||
public boolean isDebug = false;
|
||||
|
||||
// Physics related
|
||||
private World world;
|
||||
private Box2DDebugRenderer b2dr; // TODO, remove
|
||||
private OrthographicCamera b2dCam; // TODO, remove
|
||||
|
||||
// TileMap and Map Renderer
|
||||
private TiledMap tileMap;
|
||||
private OrthogonalTiledMapRenderer tmr;
|
||||
private float mapWidth, mapHeight;
|
||||
private Vector2 tileSize;
|
||||
|
||||
// All Actors in level
|
||||
private Player player;
|
||||
private ArrayList<Platform> platforms = new ArrayList<Platform>();
|
||||
private ArrayList<Spike> spikes = new ArrayList<Spike>();
|
||||
|
||||
// Windows
|
||||
private HashMap<GameState, myWindow> windows = new HashMap<GameState, myWindow>();
|
||||
|
||||
private GameState curGameState;
|
||||
public enum GameState
|
||||
{
|
||||
|
@ -75,26 +57,44 @@ public class Play extends AbstractScreen {
|
|||
FAILURE,
|
||||
}
|
||||
|
||||
// Progress bar
|
||||
|
||||
// Physics related
|
||||
private World world;
|
||||
public boolean isDebug = false;
|
||||
private Box2DDebugRenderer b2dr; // TODO, remove
|
||||
private OrthographicCamera b2dCam; // TODO, remove
|
||||
|
||||
// TileMap and Map Renderer
|
||||
private TiledMap tileMap;
|
||||
private OrthogonalTiledMapRenderer tmr;
|
||||
private float mapWidth, mapHeight;
|
||||
private Vector2 tileSize;
|
||||
private int levelNumber;
|
||||
|
||||
// All Actors in level
|
||||
private Player player;
|
||||
private ArrayList<Platform> platforms = new ArrayList<Platform>();
|
||||
private ArrayList<Enemy> enemies = new ArrayList<Enemy>();
|
||||
|
||||
// Windows
|
||||
private Skin skin;
|
||||
private HashMap<GameState, myWindow> windows = new HashMap<GameState, myWindow>();
|
||||
|
||||
// HUD
|
||||
private Rectangle progressRect;
|
||||
private Texture progressTexture;
|
||||
private float percent;
|
||||
private float progressX;
|
||||
|
||||
private int levelNumber;
|
||||
private Image uiRedImage, uiGreenImage, uiBlueImage;
|
||||
|
||||
public Play(App app, int levelNumber) {
|
||||
super(app);
|
||||
|
||||
skin = new Skin();
|
||||
|
||||
this.levelNumber = levelNumber;
|
||||
|
||||
skin = new Skin();
|
||||
world = new World(new Vector2(0, Vars.GRAVITY.y), true);
|
||||
world.setContactListener(cl);
|
||||
|
||||
b2dr = new Box2DDebugRenderer(); // TODO, remove
|
||||
|
||||
b2dCam = new OrthographicCamera();
|
||||
b2dCam.setToOrtho(false, Vars.SCREEN_WIDTH / PPM, Vars.SCREEN_HEIGHT / PPM);
|
||||
}
|
||||
|
@ -108,12 +108,21 @@ public class Play extends AbstractScreen {
|
|||
skin.load(Gdx.files.internal("spritesheets/uiskin.json"));
|
||||
|
||||
progressRect = new Rectangle(stage.getWidth() - 550, (stage.getHeight() - 50), 0, 25);
|
||||
progressTexture = app.assets.get("textures/player_red.png", Texture.class);
|
||||
progressTexture = app.assets.get("textures/player/player_red.png", Texture.class);
|
||||
progressX = progressRect.x;
|
||||
|
||||
uiRedImage = new Image(app.assets.get("textures/player/player_red.png", Texture.class));
|
||||
uiRedImage.setPosition(84, (stage.getHeight() - 70));
|
||||
uiGreenImage = new Image(app.assets.get("textures/player/player_green.png", Texture.class));
|
||||
uiGreenImage.setPosition(148, (stage.getHeight() - 70));
|
||||
uiBlueImage = new Image(app.assets.get("textures/player/player_blue.png", Texture.class));
|
||||
uiBlueImage.setPosition(212, (stage.getHeight() - 70));
|
||||
uiRedImage.setSize(64, 64);
|
||||
uiGreenImage.setSize(32, 32);
|
||||
uiBlueImage.setSize(32, 32);
|
||||
|
||||
initLevel();
|
||||
System.out.println("Finished initLevel");
|
||||
initWindows();
|
||||
System.out.println("Finished initWindows");
|
||||
setCurGameState(GameState.INTRO);
|
||||
}
|
||||
|
||||
|
@ -122,11 +131,10 @@ public class Play extends AbstractScreen {
|
|||
|
||||
if(curGameState == GameState.PLAYING)
|
||||
{
|
||||
world.step(dt, 6, 2);
|
||||
world.step(Vars.STEP, 6, 2);
|
||||
|
||||
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));
|
||||
|
@ -149,10 +157,15 @@ public class Play extends AbstractScreen {
|
|||
if(!isDebug)
|
||||
{
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("textures/position0.png", Texture.class), (cam.position.x - cam.viewportWidth / 2), cam.position.y - cam.viewportHeight / 2);
|
||||
app.sb.draw(app.assets.get("textures/position1.png", Texture.class), (cam.position.x - cam.viewportWidth / 2) * .1f, cam.position.y - (cam.viewportHeight / 2) + 75);
|
||||
app.sb.draw(app.assets.get("textures/position2.png", Texture.class), (cam.position.x - cam.viewportWidth / 2) * .01f, cam.position.y - (cam.viewportHeight / 2) - 150);
|
||||
app.sb.draw(app.assets.get("textures/backgrounds/position0.png", Texture.class), (cam.position.x - cam.viewportWidth / 2), cam.position.y - cam.viewportHeight / 2);
|
||||
app.sb.draw(app.assets.get("textures/backgrounds/position1.png", Texture.class), (cam.position.x - cam.viewportWidth / 2), cam.position.y - (cam.viewportHeight / 2) + 75);
|
||||
app.sb.draw(app.assets.get("textures/backgrounds/position2.png", Texture.class), (cam.position.x - cam.viewportWidth / 2), cam.position.y - (cam.viewportHeight / 2) - 150);
|
||||
player.render(app.sb);
|
||||
|
||||
for(Enemy e : enemies)
|
||||
{
|
||||
e.render(app.sb);
|
||||
}
|
||||
app.sb.end();
|
||||
|
||||
tmr.setView(cam);
|
||||
|
@ -169,7 +182,9 @@ public class Play extends AbstractScreen {
|
|||
app.sr.end();
|
||||
|
||||
app.sb.begin();
|
||||
app.sb.draw(app.assets.get("spritesheets/platformSet.png", Texture.class), 100, (stage.getHeight() - 50));
|
||||
uiRedImage.draw(app.sb, 1f);
|
||||
uiGreenImage.draw(app.sb, 1f);
|
||||
uiBlueImage.draw(app.sb, 1f);
|
||||
app.sb.draw(progressTexture, progressX, progressRect.y, 30, 30);
|
||||
app.sb.end();
|
||||
}
|
||||
|
@ -191,28 +206,9 @@ public class Play extends AbstractScreen {
|
|||
player.jump();
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1))
|
||||
{
|
||||
player.setCurColour(Base.Colours.RED);
|
||||
progressTexture = app.assets.get("textures/player_red.png", Texture.class);
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2))
|
||||
{
|
||||
player.setCurColour(Base.Colours.GREEN);
|
||||
progressTexture = app.assets.get("textures/player_green.png", Texture.class);
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) {
|
||||
player.setCurColour(Base.Colours.BLUE);
|
||||
progressTexture = app.assets.get("textures/player_blue.png", Texture.class);
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_4))
|
||||
{
|
||||
player.setCurColour(Base.Colours.YELLOW);
|
||||
progressTexture = app.assets.get("textures/player_yellow.png", Texture.class);
|
||||
}
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) { changeColour(Base.Colours.RED); }
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) { changeColour(Base.Colours.GREEN); }
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) { changeColour(Base.Colours.BLUE); }
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE))
|
||||
|
@ -238,6 +234,32 @@ public class Play extends AbstractScreen {
|
|||
tmr.dispose();
|
||||
}
|
||||
|
||||
private void changeColour(Base.Colours curColour)
|
||||
{
|
||||
player.setCurColour(curColour);
|
||||
switch(curColour)
|
||||
{
|
||||
case RED:
|
||||
progressTexture = app.assets.get("textures/player/player_red.png", Texture.class);
|
||||
uiRedImage.setSize(64, 64);
|
||||
uiGreenImage.setSize(32, 32);
|
||||
uiBlueImage.setSize(32, 32);
|
||||
break;
|
||||
case GREEN:
|
||||
progressTexture = app.assets.get("textures/player/player_green.png", Texture.class);
|
||||
uiGreenImage.setSize(64, 64);
|
||||
uiRedImage.setSize(32, 32);
|
||||
uiBlueImage.setSize(32, 32);
|
||||
break;
|
||||
case BLUE:
|
||||
progressTexture = app.assets.get("textures/player/player_blue.png", Texture.class);
|
||||
uiBlueImage.setSize(64, 64);
|
||||
uiGreenImage.setSize(32, 32);
|
||||
uiRedImage.setSize(32, 32);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void initLevel()
|
||||
{
|
||||
tileMap = new TmxMapLoader().load("levels/level" + levelNumber + ".tmx");
|
||||
|
@ -250,7 +272,6 @@ 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);
|
||||
|
@ -266,7 +287,20 @@ public class Play extends AbstractScreen {
|
|||
|
||||
MapLayer playerLayer = tileMap.getLayers().get("PLAYER");
|
||||
TextureMapObject playerObj = (TextureMapObject)playerLayer.getObjects().get(0);
|
||||
player = new Player(world, new Vector2(playerObj.getX(), playerObj.getY()), new Vector2(60, 60), Base.Colours.NONE);
|
||||
player = new Player(world, new Vector2(playerObj.getX(), playerObj.getY()), new Vector2(60, 60), Base.Colours.WHITE);
|
||||
|
||||
MapLayer enemyLayer = tileMap.getLayers().get("ENEMIES");
|
||||
MapObjects enemyObjs = enemyLayer.getObjects();
|
||||
|
||||
for(int i = 0; i < enemyObjs.getCount(); i++)
|
||||
{
|
||||
TextureMapObject tmo = (TextureMapObject)enemyObjs.get(i);
|
||||
MapProperties mp = tmo.getProperties();
|
||||
|
||||
if(mp.get("Colour").equals("RED")) { enemies.add(new Enemy(world, new Vector2(tmo.getX(), tmo.getY()), new Vector2(64, 64), Base.Colours.RED, BIT_ALL, BIT_PLAYER)); }
|
||||
else if(mp.get("Colour").equals("GREEN")) { enemies.add(new Enemy(world, new Vector2(tmo.getX(), tmo.getY()), new Vector2(64, 64), Base.Colours.GREEN, BIT_ALL, BIT_PLAYER)); }
|
||||
else if(mp.get("Colour").equals("BLUE")) { enemies.add(new Enemy(world, new Vector2(tmo.getX() + 32, tmo.getY() + 32), new Vector2(64, 64), Base.Colours.GREEN, BIT_ALL, BIT_PLAYER)); }
|
||||
}
|
||||
|
||||
for(int row = 0; row < platformLayer.getHeight(); row++)
|
||||
{
|
||||
|
@ -280,21 +314,9 @@ public class Play extends AbstractScreen {
|
|||
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)); }
|
||||
else if(cell.getTile().getId() == 4) { 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.WHITE, Vars.BIT_ALL, 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)); }
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private void initBoundary(PolylineMapObject polylineObj, String userData, boolean isSensor)
|
||||
|
@ -315,7 +337,7 @@ public class Play extends AbstractScreen {
|
|||
finalV[i].y = v[i * 2 + 1] / PPM;
|
||||
}
|
||||
|
||||
Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_PRISMATIC, Vars.BIT_PLAYER);
|
||||
Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_ALL, Vars.BIT_PLAYER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -323,33 +345,18 @@ public class Play extends AbstractScreen {
|
|||
*/
|
||||
private void initWindows()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
Vector2 winPos = new Vector2(280, 50);
|
||||
Vector2 winSize = new Vector2(700, 500);
|
||||
|
||||
windows.put(GameState.PLAYING, new myWindow("", new Vector2(0, 0), new Vector2(0, 0), skin, app.assets.get("textures/player_red.png", Texture.class)));
|
||||
windows.put(GameState.INTRO, new myWindow("Level " + levelNumber, winPos, winSize, skin, app.assets.get("textures/level" + levelNumber + "Intro.png", Texture.class)));
|
||||
windows.put(GameState.PAUSED, new myWindow("", winPos, winSize, skin, app.assets.get("textures/pauseBackground.png", Texture.class)));
|
||||
windows.put(GameState.SUCCESS, new myWindow("", winPos, winSize, skin, app.assets.get("textures/successBackground.png", Texture.class)));
|
||||
windows.put(GameState.FAILURE, new myWindow("", winPos, winSize, skin, app.assets.get("textures/failureBackground.png", Texture.class)));
|
||||
windows.put(GameState.PLAYING, new myWindow("", new Vector2(0, 0), new Vector2(0, 0), skin, app.assets.get("textures/player/player_red.png", Texture.class)));
|
||||
windows.put(GameState.INTRO, new myWindow("Level " + levelNumber, winPos, winSize, skin, app.assets.get("textures/intros/level" + levelNumber + "Intro.png", Texture.class)));
|
||||
windows.put(GameState.PAUSED, new myWindow("", winPos, winSize, skin, app.assets.get("textures/backgrounds/pauseBackground.png", Texture.class)));
|
||||
windows.put(GameState.SUCCESS, new myWindow("", winPos, winSize, skin, app.assets.get("textures/backgrounds/successBackground.png", Texture.class)));
|
||||
windows.put(GameState.FAILURE, new myWindow("", winPos, winSize, skin, app.assets.get("textures/backgrounds/failureBackground.png", Texture.class)));
|
||||
|
||||
// Init INTRO buttons
|
||||
myWindow tempWindow = windows.get(GameState.INTRO);
|
||||
tempWindow.addButton(new myButton("Continue", new Vector2((tempWindow.getX() * 2) - 5, tempWindow.getHeight() - 50), skin, "default", new ClickListener() {
|
||||
=======
|
||||
introWindow = new Window("Level "+levelNumber, skin);
|
||||
introWindow.getTitleLabel().setPosition(350, 500);
|
||||
introBackground = new Image(app.assets.get("textures/level" + levelNumber + "Intro.png", Texture.class));
|
||||
introWindow.setBackground(introBackground.getDrawable());
|
||||
introWindow.setSize(700, 500);
|
||||
introWindow.setPosition(280, 50);
|
||||
introWindow.setVisible(true);
|
||||
|
||||
TextButton butProceed = new TextButton("PROCEED", skin, "default");
|
||||
butProceed.setPosition((introWindow.getWidth() / 4) * 3, buttonSize.y + 360);
|
||||
butProceed.setSize(buttonSize.x, buttonSize.y);
|
||||
butProceed.addListener(new ClickListener() {
|
||||
>>>>>>> origin/master
|
||||
@Override
|
||||
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
|
||||
setCurGameState(GameState.PLAYING);
|
||||
|
@ -452,12 +459,17 @@ public class Play extends AbstractScreen {
|
|||
}
|
||||
}
|
||||
|
||||
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("SPIKES") ||
|
||||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("SPIKES"))
|
||||
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("ENEMY") ||
|
||||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("ENEMY"))
|
||||
{
|
||||
setCurGameState(GameState.FAILURE);
|
||||
System.out.println("FAILURE - TOUCHED SPIKE");
|
||||
return;
|
||||
for(Enemy e : enemies)
|
||||
{
|
||||
if(e.getFixtures().contains(fa, false) || e.getFixtures().contains(fb, false))
|
||||
{
|
||||
e.setAlive(false);
|
||||
e.setCurColour(e.getCurColour());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("PASSBOUNDARY") ||
|
||||
|
|
|
@ -35,12 +35,11 @@ public class ScreenManager {
|
|||
screens.put(Screen.MENU, new Menu(app));
|
||||
screens.put(Screen.LEADERBOARD, new Leaderboard(app));
|
||||
screens.put(Screen.LEVELSELECT, new LevelSelect(app));
|
||||
screens.put(Screen.ENDLESSMODE, new EndlessMode(app));
|
||||
//screens.put(Screen.ENDLESSMODE, new EndlessMode(app));
|
||||
}
|
||||
|
||||
public void setPlayScreen(int levelNumber)
|
||||
{
|
||||
|
||||
// remove loaded level
|
||||
if(screens.get(Screen.PLAY) != null)
|
||||
{
|
||||
|
|
Reference in a new issue