diff --git a/core/assets/playBtn.png b/core/assets/playBtn.png new file mode 100644 index 0000000..fde3577 Binary files /dev/null and b/core/assets/playBtn.png differ diff --git a/core/src/com/me/brickbuster/BrickBuster.java b/core/src/com/me/brickbuster/BrickBuster.java index 30add0e..eff946f 100644 --- a/core/src/com/me/brickbuster/BrickBuster.java +++ b/core/src/com/me/brickbuster/BrickBuster.java @@ -10,7 +10,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.Viewport; -import com.me.brickbuster.state.PlayState; +import com.me.brickbuster.state.MenuState; public class BrickBuster extends Game { @@ -39,7 +39,7 @@ public class BrickBuster extends Game { sb = new SpriteBatch(); sr = new ShapeRenderer(); - setScreen(new PlayState(this)); + setScreen(new MenuState(this)); } @Override diff --git a/core/src/com/me/brickbuster/state/MenuState.java b/core/src/com/me/brickbuster/state/MenuState.java new file mode 100644 index 0000000..09c6708 --- /dev/null +++ b/core/src/com/me/brickbuster/state/MenuState.java @@ -0,0 +1,49 @@ +package com.me.brickbuster.state; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.math.Vector3; +import com.me.brickbuster.BrickBuster; + +public class MenuState extends State { + + private Texture playButton; + + public MenuState(BrickBuster game) { + super(game); + } + + @Override + public void setup() { + this.playButton = new Texture(Gdx.files.internal("playBtn.png")); + } + + @Override + public void render() { + game.sb.begin(); + game.sb.draw(playButton, + BrickBuster.BOARD_WIDTH/2-playButton.getWidth()/2, + BrickBuster.BOARD_HEIGHT/2-playButton.getHeight()/2); + game.sb.end(); + } + + @Override + public void update(float dt) { + if (Gdx.input.justTouched()) { + Vector3 clickLoc = game.cam.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0)); + if (clickLoc.x >= BrickBuster.BOARD_WIDTH/2-playButton.getWidth()/2 + && clickLoc.x <= BrickBuster.BOARD_WIDTH/2+playButton.getWidth()/2 + && clickLoc.y >= BrickBuster.BOARD_HEIGHT/2-playButton.getHeight()/2 + && clickLoc.y <= BrickBuster.BOARD_HEIGHT/2+playButton.getHeight()/2) { + game.setScreen(new PlayState(game)); + dispose(); + } + } + } + + @Override + public void dispose() { + super.dispose(); + playButton.dispose(); + } +} diff --git a/core/src/com/me/brickbuster/state/PlayState.java b/core/src/com/me/brickbuster/state/PlayState.java index 813935c..787ef93 100644 --- a/core/src/com/me/brickbuster/state/PlayState.java +++ b/core/src/com/me/brickbuster/state/PlayState.java @@ -115,12 +115,25 @@ public class PlayState extends State { } if (bricks.isEmpty()) { - // TODO: Fix this - go to an after-game menu - //create(); + game.setScreen(new MenuState(game)); + dispose(); } updateTime = System.nanoTime() - start; } + @Override + public void dispose() { + super.dispose(); + + powerUps.clear(); + powerUps = null; + balls.clear(); + balls = null; + bricks.clear(); + bricks = null; + paddle = null; + } + public int getShieldCount() { return shieldCount; } diff --git a/core/src/com/me/brickbuster/state/State.java b/core/src/com/me/brickbuster/state/State.java index 22fe224..84abf53 100644 --- a/core/src/com/me/brickbuster/state/State.java +++ b/core/src/com/me/brickbuster/state/State.java @@ -6,6 +6,7 @@ import com.me.brickbuster.BrickBuster; public abstract class State extends ScreenAdapter { protected final BrickBuster game; + private boolean disposed; public State(BrickBuster game) { this.game = game; @@ -15,7 +16,14 @@ public abstract class State extends ScreenAdapter { @Override public final void render(float delta) { update(delta); - render(); + if (!disposed) { + render(); + } + } + + @Override + public void dispose() { + this.disposed = true; } public abstract void setup();