From 3b1aea382dfb094135c7f59596837ac1b712bc9c Mon Sep 17 00:00:00 2001 From: Ash Reynolds Date: Mon, 22 Feb 2016 18:36:56 +0000 Subject: [PATCH] Refactoring and platform graphics --- core/assets/spritesheets/drawing.svg | 162 ++++++++++ core/assets/spritesheets/platformSet.png | Bin 3123 -> 1146 bytes core/assets/spritesheets/platformSetOld.png | Bin 0 -> 3123 bytes core/src/com/game/Actor/Platform.java | 2 +- core/src/com/game/Actor/Player.java | 12 +- core/src/com/game/Actor/Spike.java | 2 +- core/src/com/game/Misc/Vars.java | 4 +- core/src/com/game/Misc/myButton.java | 19 ++ core/src/com/game/Misc/myWindow.java | 32 ++ core/src/com/game/Screens/EndlessMode.java | 2 +- core/src/com/game/Screens/Play.java | 325 ++++++++------------ 11 files changed, 357 insertions(+), 203 deletions(-) create mode 100644 core/assets/spritesheets/drawing.svg create mode 100644 core/assets/spritesheets/platformSetOld.png create mode 100644 core/src/com/game/Misc/myButton.java create mode 100644 core/src/com/game/Misc/myWindow.java diff --git a/core/assets/spritesheets/drawing.svg b/core/assets/spritesheets/drawing.svg new file mode 100644 index 0000000..ee95e20 --- /dev/null +++ b/core/assets/spritesheets/drawing.svg @@ -0,0 +1,162 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/assets/spritesheets/platformSet.png b/core/assets/spritesheets/platformSet.png index c09d717f6cd3f313db51c746c2999f4f3b5ae583..86159afc98dd75c54841145ba98ca0acb14facfa 100644 GIT binary patch literal 1146 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K595~p3Eg9TJBm z!VS6m)mmAEn)3FXIphCnPrP!G#q|F&kA5ETTiJ5I!T-Sf106P(80HI~**9%T^p7b< zG4&H?)J9M3ylu0;ewK-L{m)5ne+3`bnfk%}gZmd3LC+08wlDFRxo-ZEMgP|8oGAO7 z8MrNeQ*6DL&apeD^5zFj%H|ymVhnfSp8oRRjrryu)F$&rgnqbwmn~);f8CzOZXdG+ z>m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*X zRZ(B@wgR8wBYjw%AJ-fwmnh&^Mvw{{&lqQ_val|Cm73`CH9rnUd_fe5e>%92R95(B zxqaDd#luFfnoy1OhGW#ia@~lMD@I>uda`;<#HPeHjI)gc45|(Cms)+R@bYOI>3`CG zr=O;?ibdXKG(jPH%D%oWTxspOIO#D)#D?{G=wp*DAwVk@oX z@StU$E-4clsYWcJABQP{5Kp7O7x8h_jS zodULkEgi_{zb~RLv-4^y3(V_Hy>2I!ho_%3p4`vtQVHU`e$`usYhk&etjrXb;-uO* zj(IevJf^(W{A~00OjUEFj4P*utg>Y7^$4dgQux0~B$bSX@Sl)Qw>M*r0q4g3#`6P9 z4lHdfS%z7^GLyCsX6DR{<>jR!nS6Y7ksI~-Q* zN3E+Kv=J~7f?*3o5yaD)z`KDxf!i#;th4V9E4Dp{yed@V)Urd!hHeks7FrU~d3jfI z6Y{k9mic)!`2s$+OjqKMnT}#@w?_Bq~>0N^^X}T&%Lwrswj1Z)p zlAjcDTCCtYre$8s_0+Hk4rL3%8B;Gzk>9) zJ8lo~L>?f%%5O_B6{Zwf8dVx8o8;Up$i);(K8jYpCOIXsvmGtQb0@B@2-5&kDN zk;<-^WxDg8@&$zB_fCy{uj#5nJQfeHvv88{=Om;?`X9-zJYHxc2c}A%Ygi7m5kF z)@P50w0Z__71N=6P=O$T3Jbg;3#*Rm_#MnDs$@iE=*FiEHy_eu&&elh3jyD5Qp?7}3;Q3rEpj^>hfn=zR|dV(&QXa? z8gv12;52TmZP!xnM^>UVag!ZX7J47Hio>Sg-bu HbJYI;&dJf6 diff --git a/core/assets/spritesheets/platformSetOld.png b/core/assets/spritesheets/platformSetOld.png new file mode 100644 index 0000000000000000000000000000000000000000..c09d717f6cd3f313db51c746c2999f4f3b5ae583 GIT binary patch literal 3123 zcma)8XFS`D_x)P2S`u1&*Ql+cR#8fXMr~SqRzy|Qh*?sqMyXYMRZwcvqCsejrb_Ku zd$f<#it!kY@$pL?}q?jKrF}%vb3D!h#e#Zg%s39=DToD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u HbJYI;&dJf6 literal 0 HcmV?d00001 diff --git a/core/src/com/game/Actor/Platform.java b/core/src/com/game/Actor/Platform.java index aa70903..f2e02e8 100644 --- a/core/src/com/game/Actor/Platform.java +++ b/core/src/com/game/Actor/Platform.java @@ -27,7 +27,7 @@ public class Platform extends Base { }, "PLATFORM", true, - Vars.BIT_MISC, + Vars.BIT_PRISMATIC, Vars.BIT_PLAYER ); } diff --git a/core/src/com/game/Actor/Player.java b/core/src/com/game/Actor/Player.java index 84c4499..2968fe9 100644 --- a/core/src/com/game/Actor/Player.java +++ b/core/src/com/game/Actor/Player.java @@ -1,5 +1,7 @@ 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; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -30,6 +32,9 @@ public class Player extends Base { DEAD } + private Sound jumpSound; + private Sound colourchangeSound; + public Player(World world, Vector2 pos, Vector2 size, Colours curColour) { super(world, pos, size, "", curColour); curAction = Action.IDLE; @@ -38,7 +43,10 @@ public class Player extends Base { BodyDef.BodyType.DynamicBody, 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)); } @@ -70,6 +78,7 @@ public class Player extends Base { if(curAction != Action.FALLING) { curAction = Action.JUMPING; + jumpSound.play(); } } @@ -120,5 +129,6 @@ public class Player extends Base { filter.maskBits = bits; body.getFixtureList().first().setFilterData(filter); + colourchangeSound.play(); } } diff --git a/core/src/com/game/Actor/Spike.java b/core/src/com/game/Actor/Spike.java index 36e51f8..ded3a14 100644 --- a/core/src/com/game/Actor/Spike.java +++ b/core/src/com/game/Actor/Spike.java @@ -31,7 +31,7 @@ public class Spike extends Base { }, "SPIKE", true, - Vars.BIT_MISC, + Vars.BIT_PRISMATIC, Vars.BIT_PLAYER ); } diff --git a/core/src/com/game/Misc/Vars.java b/core/src/com/game/Misc/Vars.java index 9d1ffea..06d436b 100644 --- a/core/src/com/game/Misc/Vars.java +++ b/core/src/com/game/Misc/Vars.java @@ -22,10 +22,10 @@ public class Vars { public static final Vector2 SCROLLSPEED = new Vector2(150f, 0); // 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_GREEN = 4; public static final short BIT_BLUE = 8; public static final short BIT_YELLOW = 16; - public static final short BIT_PLAYER = 32; - public static final short BIT_MISC = 64; } diff --git a/core/src/com/game/Misc/myButton.java b/core/src/com/game/Misc/myButton.java new file mode 100644 index 0000000..fe273de --- /dev/null +++ b/core/src/com/game/Misc/myButton.java @@ -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); + } +} diff --git a/core/src/com/game/Misc/myWindow.java b/core/src/com/game/Misc/myWindow.java new file mode 100644 index 0000000..67babc4 --- /dev/null +++ b/core/src/com/game/Misc/myWindow.java @@ -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 buttons = new ArrayList(); + + 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); + } +} diff --git a/core/src/com/game/Screens/EndlessMode.java b/core/src/com/game/Screens/EndlessMode.java index 7f18e5f..819f043 100644 --- a/core/src/com/game/Screens/EndlessMode.java +++ b/core/src/com/game/Screens/EndlessMode.java @@ -288,7 +288,7 @@ public class EndlessMode extends AbstractScreen { 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() { diff --git a/core/src/com/game/Screens/Play.java b/core/src/com/game/Screens/Play.java index 389177c..0d4ba91 100644 --- a/core/src/com/game/Screens/Play.java +++ b/core/src/com/game/Screens/Play.java @@ -20,10 +20,7 @@ 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.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.Platform; @@ -31,12 +28,11 @@ import com.game.actor.Player; import com.game.App; import com.game.actor.Spike; import com.game.managers.ScreenManager; -import com.game.misc.Box2dUtils; -import com.game.misc.CameraUtils; -import com.game.misc.Vars; +import com.game.misc.*; +import com.game.misc.myWindow; -import javax.xml.soap.Text; import java.util.ArrayList; +import java.util.HashMap; import static com.game.misc.Vars.PPM; @@ -66,23 +62,18 @@ public class Play extends AbstractScreen { private ArrayList platforms = new ArrayList(); private ArrayList spikes = new ArrayList(); - // Intro window - private boolean isIntro; - private Window introWindow; - private Image introBackground; + // Windows + private HashMap windows = new HashMap(); - // Pause window - private boolean isPaused; - private Window pauseWindow; - private Image pauseBackground; - private Image pauseGlow; - private Vector2 buttonSize; - - // Endgame window - private boolean isEnd; - private boolean isSuccess; - private Window endgameWindow; - private Image failureBackground, successBackground; + private GameState curGameState; + public enum GameState + { + PLAYING, + INTRO, + PAUSED, + SUCCESS, + FAILURE, + } // Progress bar private Rectangle progressRect; @@ -92,9 +83,6 @@ public class Play extends AbstractScreen { 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) { super(app); @@ -109,14 +97,6 @@ public class Play extends AbstractScreen { b2dCam = new OrthographicCamera(); 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 @@ -131,14 +111,16 @@ public class Play extends AbstractScreen { progressTexture = app.assets.get("textures/player_red.png", Texture.class); initLevel(); - initIntroWindow(); - initPauseWindow(); - initEndgameWindow(false); + System.out.println("Finished initLevel"); + initWindows(); + System.out.println("Finished initWindows"); + setCurGameState(GameState.INTRO); } @Override public void update(float dt) { - if(!isPaused && !isEnd && !isIntro) + + if(curGameState == GameState.PLAYING) { world.step(dt, 6, 2); @@ -155,19 +137,6 @@ public class Play extends AbstractScreen { 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); } @@ -214,30 +183,27 @@ public class Play extends AbstractScreen { @Override 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)) { - colourchangeSound.play(); player.setCurColour(Base.Colours.RED); progressTexture = app.assets.get("textures/player_red.png", Texture.class); } if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_2)) { - colourchangeSound.play(); player.setCurColour(Base.Colours.GREEN); progressTexture = app.assets.get("textures/player_green.png", Texture.class); } if(Gdx.input.isKeyJustPressed(Input.Keys.NUM_3)) { - colourchangeSound.play(); player.setCurColour(Base.Colours.BLUE); progressTexture = app.assets.get("textures/player_blue.png", Texture.class); } @@ -247,16 +213,20 @@ public class Play extends AbstractScreen { player.setCurColour(Base.Colours.YELLOW); 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 @@ -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++) { @@ -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)); } } - } + }*/ } 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; } - 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); - 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); + Vector2 winPos = new Vector2(280, 50); + Vector2 winSize = new Vector2(700, 500); - 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() { + 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))); + + // 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 public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { - introWindow.setVisible(false); - isIntro = false; - isPaused = false; + setCurGameState(GameState.PLAYING); } - }); + })); - introWindow.addActor(butProceed); - - stage.addActor(introWindow); - } - - 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() { + // Init PAUSED buttons + tempWindow = windows.get(GameState.PAUSED); + 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) { - isPaused = false; + public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { + setCurGameState(GameState.PLAYING); } - }); - - 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() { + })); + 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) { + 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() { + })); + 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); } - }); + })); - pauseGlow = new Image(app.assets.get("textures/pauseGlow.png", Texture.class)); - pauseGlow.setVisible(false); + // Init SUCCESS buttons + 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); - pauseWindow.addActor(butReset); - pauseWindow.addActor(butExit); + // Init FAILURE buttons + tempWindow = windows.get(GameState.FAILURE); + 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); - stage.addActor(pauseWindow); - } - - 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()); + for(myWindow w : windows.values()) + { + stage.addActor(w); } - 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 // 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 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") || fb.getUserData().equals("PLAYER") && fa.getUserData().equals("PASSBOUNDARY")) { - isEnd = true; - isSuccess = true; - System.out.println("Success"); + setCurGameState(GameState.SUCCESS); + System.out.println("SUCCESS"); return; } if(fa.getUserData().equals("PLAYER") && fb.getUserData().equals("FAILBOUNDARY") || fb.getUserData().equals("PLAYER") && fa.getUserData().equals("FAILBOUNDARY")) { - isEnd = true; - isSuccess = false; - System.out.println("Failure"); + setCurGameState(GameState.FAILURE); + System.out.println("FAILURE - TOUCHED FAILBOUNDARY"); 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