Refactoring and platform graphics

This commit is contained in:
Ash Reynolds 2016-02-22 18:36:56 +00:00
parent 9f2627947c
commit 3b1aea382d
11 changed files with 357 additions and 203 deletions

View file

@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="64"
viewBox="0 0 256 63.999999"
id="svg3336"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="drawing.svg">
<defs
id="defs3338" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="4.8751698"
inkscape:cx="99.91327"
inkscape:cy="34.380608"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1920"
inkscape:window-height="1017"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
units="px" />
<metadata
id="metadata3341">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-988.3622)">
<g
id="g3420"
transform="matrix(0.93368387,0,0,0.93368387,-41.263389,954.8465)">
<rect
ry="2.5253799"
style="fill:#2b0000;fill-opacity:1;stroke:none"
id="rect3361"
width="68.545685"
height="68.545685"
x="44.194176"
y="35.896206" />
<rect
transform="scale(-1,-1)"
y="-102.16905"
x="-110.46702"
height="64"
width="64"
id="rect3344"
style="fill:#ff0000;fill-opacity:1;stroke:none" />
<path
sodipodi:nodetypes="cccc"
inkscape:connector-curvature="0"
id="rect3378"
d="m 110.46702,102.16905 -64.000002,0 c 64.000002,-64.000002 0,0 64.000002,-64.000002 z"
style="fill:#d40000;fill-opacity:1;stroke:none" />
</g>
<g
id="g3425"
transform="matrix(0.93368387,0,0,0.93368387,-47.52904,954.84649)">
<rect
y="35.896206"
x="119.45054"
height="68.545685"
width="68.545685"
id="rect3402"
style="fill:#112b00;fill-opacity:1;stroke:none"
ry="2.5253799" />
<rect
style="fill:#66ff00;fill-opacity:1;stroke:none"
id="rect3404"
width="64"
height="64"
x="-185.72339"
y="-102.16905"
transform="scale(-1,-1)" />
<path
style="fill:#55d400;fill-opacity:1;stroke:none"
d="m 185.72338,102.16905 -64,0 c 64,-64.000002 0,0 64,-64.000002 z"
id="path3406"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
</g>
<g
id="g3430"
transform="matrix(0.93368387,0,0,0.93368387,-54.266272,954.84649)">
<rect
ry="2.5253799"
style="fill:#00222b;fill-opacity:1;stroke:none"
id="rect3408"
width="68.545685"
height="68.545685"
x="195.21198"
y="35.896206" />
<rect
transform="scale(-1,-1)"
y="-102.16905"
x="-261.48483"
height="64"
width="64"
id="rect3410"
style="fill:#00ccff;fill-opacity:1;stroke:none" />
<path
sodipodi:nodetypes="cccc"
inkscape:connector-curvature="0"
id="path3412"
d="m 261.48482,102.16905 -64,0 c 64,-64.000002 0,0 64,-64.000002 z"
style="fill:#00aad4;fill-opacity:1;stroke:none" />
</g>
<g
id="g3435"
transform="matrix(0.93368387,0,0,0.93368387,-59.117193,954.84649)">
<rect
y="35.896206"
x="268.95312"
height="68.545685"
width="68.545685"
id="rect3414"
style="fill:#2b2200;fill-opacity:1;stroke:none"
ry="2.5253799" />
<rect
style="fill:#ffcc00;fill-opacity:1;stroke:none"
id="rect3416"
width="64"
height="64"
x="-335.22598"
y="-102.16905"
transform="scale(-1,-1)" />
<path
style="fill:#d4aa00;fill-opacity:1;stroke:none"
d="m 335.22596,102.16905 -64,0 c 64,-64.000002 0,0 64,-64.000002 z"
id="path3418"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

View file

@ -27,7 +27,7 @@ public class Platform extends Base {
}, },
"PLATFORM", "PLATFORM",
true, true,
Vars.BIT_MISC, Vars.BIT_PRISMATIC,
Vars.BIT_PLAYER Vars.BIT_PLAYER
); );
} }

View file

@ -1,5 +1,7 @@
package com.game.actor; 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.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@ -30,6 +32,9 @@ public class Player extends Base {
DEAD DEAD
} }
private Sound jumpSound;
private Sound colourchangeSound;
public Player(World world, Vector2 pos, Vector2 size, Colours curColour) { public Player(World world, Vector2 pos, Vector2 size, Colours curColour) {
super(world, pos, size, "", curColour); super(world, pos, size, "", curColour);
curAction = Action.IDLE; curAction = Action.IDLE;
@ -38,7 +43,10 @@ public class Player extends Base {
BodyDef.BodyType.DynamicBody, BodyDef.BodyType.DynamicBody,
pos pos
); );
Box2dUtils.makeCircle(body, size.x, "PLAYER", false, Vars.BIT_PLAYER, (short)(Vars.BIT_RED | Vars.BIT_MISC)); Box2dUtils.makeCircle(body, size.x, "PLAYER", false, Vars.BIT_PLAYER, (short)(Vars.BIT_RED | Vars.BIT_PRISMATIC));
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_red.png", Texture.class));
} }
@ -70,6 +78,7 @@ public class Player extends Base {
if(curAction != Action.FALLING) if(curAction != Action.FALLING)
{ {
curAction = Action.JUMPING; curAction = Action.JUMPING;
jumpSound.play();
} }
} }
@ -120,5 +129,6 @@ public class Player extends Base {
filter.maskBits = bits; filter.maskBits = bits;
body.getFixtureList().first().setFilterData(filter); body.getFixtureList().first().setFilterData(filter);
colourchangeSound.play();
} }
} }

View file

@ -31,7 +31,7 @@ public class Spike extends Base {
}, },
"SPIKE", "SPIKE",
true, true,
Vars.BIT_MISC, Vars.BIT_PRISMATIC,
Vars.BIT_PLAYER Vars.BIT_PLAYER
); );
} }

View file

@ -22,10 +22,10 @@ public class Vars {
public static final Vector2 SCROLLSPEED = new Vector2(150f, 0); public static final Vector2 SCROLLSPEED = new Vector2(150f, 0);
// Filter bits // Filter bits
public static final short BIT_PLAYER = 1;
public static final short BIT_PRISMATIC = 1;
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_YELLOW = 16; public static final short BIT_YELLOW = 16;
public static final short BIT_PLAYER = 32;
public static final short BIT_MISC = 64;
} }

View file

@ -0,0 +1,19 @@
package com.game.misc;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
/**
* Created by Ash on 22/02/2016.
*/
public class myButton extends TextButton {
public myButton(String text, Vector2 pos, Skin skin, String styleName, ClickListener cl) {
super(text, skin, styleName);
this.setPosition(pos.x, pos.y);
this.setSize(50, 50);
this.addListener(cl);
}
}

View file

@ -0,0 +1,32 @@
package com.game.misc;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
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 java.util.ArrayList;
/**
* Created by Ash on 22/02/2016.
*/
public class myWindow extends Window {
protected ArrayList<TextButton> buttons = new ArrayList<TextButton>();
public myWindow(String title, Vector2 pos, Vector2 size, Skin skin, Texture backgroundTexture) {
super(title, skin);
setBackground(new Image(backgroundTexture).getDrawable());
setPosition(pos.x, pos.y);
setSize(size.x, size.y);
setVisible(false);
}
public void addButton(TextButton newButton)
{
buttons.add(newButton);
this.addActor(newButton);
}
}

View file

@ -288,7 +288,7 @@ public class EndlessMode extends AbstractScreen {
finalV[i].y = v[i * 2 + 1] / PPM; finalV[i].y = v[i * 2 + 1] / PPM;
} }
Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_MISC, Vars.BIT_PLAYER); Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_PRISMATIC, Vars.BIT_PLAYER);
} }
private void initIntroWindow() { private void initIntroWindow() {

View file

@ -20,10 +20,7 @@ import com.badlogic.gdx.math.Polyline;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
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.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.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;
@ -31,12 +28,11 @@ import com.game.actor.Player;
import com.game.App; import com.game.App;
import com.game.actor.Spike; import com.game.actor.Spike;
import com.game.managers.ScreenManager; import com.game.managers.ScreenManager;
import com.game.misc.Box2dUtils; import com.game.misc.*;
import com.game.misc.CameraUtils; import com.game.misc.myWindow;
import com.game.misc.Vars;
import javax.xml.soap.Text;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import static com.game.misc.Vars.PPM; import static com.game.misc.Vars.PPM;
@ -66,23 +62,18 @@ public class Play extends AbstractScreen {
private ArrayList<Platform> platforms = new ArrayList<Platform>(); private ArrayList<Platform> platforms = new ArrayList<Platform>();
private ArrayList<Spike> spikes = new ArrayList<Spike>(); private ArrayList<Spike> spikes = new ArrayList<Spike>();
// Intro window // Windows
private boolean isIntro; private HashMap<GameState, myWindow> windows = new HashMap<GameState, myWindow>();
private Window introWindow;
private Image introBackground;
// Pause window private GameState curGameState;
private boolean isPaused; public enum GameState
private Window pauseWindow; {
private Image pauseBackground; PLAYING,
private Image pauseGlow; INTRO,
private Vector2 buttonSize; PAUSED,
SUCCESS,
// Endgame window FAILURE,
private boolean isEnd; }
private boolean isSuccess;
private Window endgameWindow;
private Image failureBackground, successBackground;
// Progress bar // Progress bar
private Rectangle progressRect; private Rectangle progressRect;
@ -92,9 +83,6 @@ public class Play extends AbstractScreen {
private int levelNumber; 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 Play(App app, int levelNumber) { public Play(App app, int levelNumber) {
super(app); super(app);
@ -109,14 +97,6 @@ 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);
isIntro = true;
isPaused = false;
buttonSize = new Vector2(50, 50);
isEnd = false;
isSuccess = false;
} }
@Override @Override
@ -131,14 +111,16 @@ public class Play extends AbstractScreen {
progressTexture = app.assets.get("textures/player_red.png", Texture.class); progressTexture = app.assets.get("textures/player_red.png", Texture.class);
initLevel(); initLevel();
initIntroWindow(); System.out.println("Finished initLevel");
initPauseWindow(); initWindows();
initEndgameWindow(false); System.out.println("Finished initWindows");
setCurGameState(GameState.INTRO);
} }
@Override @Override
public void update(float dt) { public void update(float dt) {
if(!isPaused && !isEnd && !isIntro)
if(curGameState == GameState.PLAYING)
{ {
world.step(dt, 6, 2); world.step(dt, 6, 2);
@ -155,19 +137,6 @@ public class Play extends AbstractScreen {
player.update(dt); player.update(dt);
} }
if(pauseWindow.isVisible() != isPaused)
{
pauseWindow.setVisible(isPaused);
pauseGlow.setVisible(isPaused);
}
if(endgameWindow.isVisible() != isEnd)
{
initEndgameWindow(isSuccess);
endgameWindow.setVisible(isEnd);
pauseGlow.setVisible(isEnd);
}
stage.act(dt); stage.act(dt);
} }
@ -214,30 +183,27 @@ public class Play extends AbstractScreen {
@Override @Override
public void handleInput() { public void handleInput() {
if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE))
{
isPaused = !isPaused;
System.out.println("isPaused: " + isPaused);
}
if(!isPaused && !isEnd && !isIntro) if(curGameState == GameState.PLAYING)
{ {
if(Gdx.input.isKeyPressed(Input.Keys.SPACE))
{
player.jump();
}
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1)) if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_1))
{ {
colourchangeSound.play();
player.setCurColour(Base.Colours.RED); player.setCurColour(Base.Colours.RED);
progressTexture = app.assets.get("textures/player_red.png", Texture.class); progressTexture = app.assets.get("textures/player_red.png", Texture.class);
} }
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2))
{ {
colourchangeSound.play();
player.setCurColour(Base.Colours.GREEN); player.setCurColour(Base.Colours.GREEN);
progressTexture = app.assets.get("textures/player_green.png", Texture.class); progressTexture = app.assets.get("textures/player_green.png", Texture.class);
} }
if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) { if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) {
colourchangeSound.play();
player.setCurColour(Base.Colours.BLUE); player.setCurColour(Base.Colours.BLUE);
progressTexture = app.assets.get("textures/player_blue.png", Texture.class); progressTexture = app.assets.get("textures/player_blue.png", Texture.class);
} }
@ -247,16 +213,20 @@ public class Play extends AbstractScreen {
player.setCurColour(Base.Colours.YELLOW); player.setCurColour(Base.Colours.YELLOW);
progressTexture = app.assets.get("textures/player_yellow.png", Texture.class); progressTexture = app.assets.get("textures/player_yellow.png", Texture.class);
} }
if(Gdx.input.isKeyPressed(Input.Keys.SPACE))
{
jumpSound.play();
player.jump();
}
} }
if(Gdx.input.isKeyJustPressed(Input.Keys.V)) { isDebug = !isDebug; } if(Gdx.input.isKeyJustPressed(Input.Keys.ESCAPE))
{
if(curGameState == GameState.PAUSED) { setCurGameState(GameState.PLAYING); }
else { setCurGameState(GameState.PAUSED); }
}
if(curGameState == GameState.INTRO)
{
if(Gdx.input.isKeyPressed(Input.Keys.SPACE)) { setCurGameState(GameState.PLAYING); }
}
if(Gdx.input.isKeyJustPressed(Input.Keys.X)) { isDebug = !isDebug; }
} }
@Override @Override
@ -313,7 +283,7 @@ public class Play extends AbstractScreen {
} }
} }
for(int row = 0; row < spikeLayer.getHeight(); row++) /*for(int row = 0; row < spikeLayer.getHeight(); row++)
{ {
for(int col = 0; col < spikeLayer.getWidth(); col++) for(int col = 0; col < spikeLayer.getWidth(); col++)
{ {
@ -324,7 +294,7 @@ public class Play extends AbstractScreen {
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)); } 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) private void initBoundary(PolylineMapObject polylineObj, String userData, boolean isSensor)
@ -345,143 +315,108 @@ public class Play extends AbstractScreen {
finalV[i].y = v[i * 2 + 1] / PPM; finalV[i].y = v[i * 2 + 1] / PPM;
} }
Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_MISC, Vars.BIT_PLAYER); Box2dUtils.makeChain(body, finalV, userData, isSensor, Vars.BIT_PRISMATIC, Vars.BIT_PLAYER);
} }
private void initIntroWindow() /**
* Method that creates the overlay windows for the intro, pause, sucess and failure states
*/
private void initWindows()
{ {
introWindow = new Window("Level "+levelNumber, skin); Vector2 winPos = new Vector2(280, 50);
introWindow.getTitleLabel().setPosition(350, 500); Vector2 winSize = new Vector2(700, 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);
TextButton butProceed = new TextButton("PROCEED", skin, "default"); windows.put(GameState.PLAYING, new myWindow("", new Vector2(0, 0), new Vector2(0, 0), skin, app.assets.get("textures/player_red.png", Texture.class)));
butProceed.setPosition((introWindow.getWidth() / 4) * 3, buttonSize.y + 360); windows.put(GameState.INTRO, new myWindow("Level " + levelNumber, winPos, winSize, skin, app.assets.get("textures/level" + levelNumber + "Intro.png", Texture.class)));
butProceed.setSize(buttonSize.x, buttonSize.y); windows.put(GameState.PAUSED, new myWindow("", winPos, winSize, skin, app.assets.get("textures/pauseBackground.png", Texture.class)));
butProceed.addListener(new ClickListener() { 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)));
// 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() {
@Override @Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
introWindow.setVisible(false); setCurGameState(GameState.PLAYING);
isIntro = false;
isPaused = false;
} }
}); }));
introWindow.addActor(butProceed); // Init PAUSED buttons
tempWindow = windows.get(GameState.PAUSED);
stage.addActor(introWindow); tempWindow.addButton(new myButton("Continue", new Vector2((tempWindow.getX() / 2) - 25, 290), skin, "default", new ClickListener() {
}
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);
TextButton 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 @Override
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
isPaused = false; setCurGameState(GameState.PLAYING);
} }
}); }));
tempWindow.addButton(new myButton("Reset", new Vector2((tempWindow.getX() / 2) - 25, 190), skin, "default", new ClickListener() {
TextButton 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 @Override
public void clicked (com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setPlayScreen(levelNumber); app.sm.setPlayScreen(levelNumber);
} }
}); }));
tempWindow.addButton(new myButton("Exit", new Vector2((tempWindow.getX() / 2) - 25, 90), skin, "default", new ClickListener() {
TextButton 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 @Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setScreen(ScreenManager.Screen.MENU); app.sm.setScreen(ScreenManager.Screen.MENU);
} }
}); }));
pauseGlow = new Image(app.assets.get("textures/pauseGlow.png", Texture.class)); // Init SUCCESS buttons
pauseGlow.setVisible(false); tempWindow = windows.get(GameState.SUCCESS);
tempWindow.addButton(new myButton("Continue", new Vector2((tempWindow.getX() / 2) - 25, 290), skin, "default", new ClickListener() {
@Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setPlayScreen(levelNumber + 1);
}
}));
tempWindow.addButton(new myButton("Reset", new Vector2((tempWindow.getX() / 2) - 25, 190), skin, "default", new ClickListener() {
@Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setPlayScreen(levelNumber);
}
}));
tempWindow.addButton(new myButton("Exit", new Vector2((tempWindow.getX() / 2) - 25, 90), skin, "default", new ClickListener() {
@Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setScreen(ScreenManager.Screen.MENU);
}
}));
pauseWindow.addActor(butContinue); // Init FAILURE buttons
pauseWindow.addActor(butReset); tempWindow = windows.get(GameState.FAILURE);
pauseWindow.addActor(butExit); tempWindow.addButton(new myButton("Reset", new Vector2((tempWindow.getX() / 2) - 25, 190), skin, "default", new ClickListener() {
@Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setPlayScreen(levelNumber);
}
}));
tempWindow.addButton(new myButton("Exit", new Vector2((tempWindow.getX() / 2) - 25, 90), skin, "default", new ClickListener() {
@Override
public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) {
app.sm.setScreen(ScreenManager.Screen.MENU);
}
}));
stage.addActor(pauseGlow); for(myWindow w : windows.values())
stage.addActor(pauseWindow); {
} stage.addActor(w);
private void initEndgameWindow(boolean success)
{
if (success) {
endgameWindow = new Window("Success", skin);
successBackground = new Image(app.assets.get("textures/successBackground.png", Texture.class));
endgameWindow.setBackground(successBackground.getDrawable());
TextButton 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);
TextButton 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);
}
});
TextButton 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);
}
});
endgameWindow.addActor(butReset);
endgameWindow.addActor(butExit);
stage.addActor(endgameWindow);
} }
// Accessors // Accessors
// Mutators // Mutators
private void setCurGameState(GameState newGameState)
{
if(curGameState != null) {
windows.get(curGameState).setVisible(false); // hide last window
}
curGameState = newGameState;
System.out.println("Showing: " + curGameState.name() + " window");
windows.get(curGameState).setVisible(true); // show new window
}
// Contact Listener // Contact Listener
ContactListener cl = new ContactListener() { ContactListener cl = new ContactListener() {
@ -502,33 +437,29 @@ public class Play extends AbstractScreen {
} }
} }
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("SPIKES") ||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("SPIKES"))
{
setCurGameState(GameState.FAILURE);
System.out.println("FAILURE - TOUCHED SPIKE");
return;
}
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("PASSBOUNDARY") || if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("PASSBOUNDARY") ||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("PASSBOUNDARY")) fb.getUserData().equals("PLAYER") && fa.getUserData().equals("PASSBOUNDARY"))
{ {
isEnd = true; setCurGameState(GameState.SUCCESS);
isSuccess = true; System.out.println("SUCCESS");
System.out.println("Success");
return; return;
} }
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("FAILBOUNDARY") || if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("FAILBOUNDARY") ||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("FAILBOUNDARY")) fb.getUserData().equals("PLAYER") && fa.getUserData().equals("FAILBOUNDARY"))
{ {
isEnd = true; setCurGameState(GameState.FAILURE);
isSuccess = false; System.out.println("FAILURE - TOUCHED FAILBOUNDARY");
System.out.println("Failure");
return; return;
} }
if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("SPIKES") ||
fb.getUserData().equals("PLAYER") && fa.getUserData().equals("SPIKES"))
{
isEnd = true;
isSuccess = false;
System.out.println("Failure");
return;
}
} }
@Override @Override