From 0abae880d3d987e12bd22c4cd9ebf6d4d63931da Mon Sep 17 00:00:00 2001 From: Matt Low Date: Tue, 13 Nov 2018 17:58:42 +0400 Subject: [PATCH] Add MenuState, start with it and switch back when a game is finished --- core/assets/playBtn.png | Bin 0 -> 2794 bytes core/src/com/me/brickbuster/BrickBuster.java | 4 +- .../com/me/brickbuster/state/MenuState.java | 49 ++++++++++++++++++ .../com/me/brickbuster/state/PlayState.java | 17 +++++- core/src/com/me/brickbuster/state/State.java | 10 +++- 5 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 core/assets/playBtn.png create mode 100644 core/src/com/me/brickbuster/state/MenuState.java diff --git a/core/assets/playBtn.png b/core/assets/playBtn.png new file mode 100644 index 0000000000000000000000000000000000000000..fde35774c7ca2425c4269607aeb318effd1680f3 GIT binary patch literal 2794 zcmWkw3p~^78{f=aW~?EXNT-=KxlKyB6lr5~tE{4b!8fpvf} zQ%M16U-(5JfKEQjiF8T{C@iI*3}CLzB%X}|fiOkCD!63)CKw>?WPf|494s^aA&Exn{ z^>LW3H8{?6%XYV{5dZuU;*h+)d@T6f(!(UlCGLnG-Lh+4w@L~MhAgpfIU;htC;1_D zO%+>U_Nw;asu%pSBga2mP^+Y1Ejj;=>=SrF-JJY9B%dm-JmR@6QRHK{y-}g@eb0A7 zXL^jtOy>#eRjRW#Xiz5C03oC7gc+UEvyweJOM#k-p>5iM(oCObodPyYJ2$#Wp{jfI z?yAZ@4@S5=O?qCmz!9n-bMu$17d^O_THZnSTc?cF`2~QV&%xV+2xR3RTCd$4i^kyDfmuZXjRu} z?!XZr8!F{fJQQbL*n~%Kqst)zr8%yba4oxLq^@>dsQ@Xd(aozV(-VJx^&n1*CR5!cJT>ln4Tum}8yZ`kwv7dhhl-Xi zkg>=LUo}40@>|xV>2}mJ^QE>7qK&R(&?`c%CRSlI@+f{s6mrnhB#E|2{AW}r3z@sP zQMHoJG2qtau?uFZo$)DAu>sd7r;*~D%G(W50cTIFr0cc&6hZ4D<>*s6D~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pq_E0$Tqf##+lei{T=n51!rzW3V+m~v&08+_h9rH#i zbD?eIy_7qBun<}?DEvQw=5#={dkM+NNAe9>gmmlyi$PkPdi8Q$*XQZihAKb#lYLY;zOBC=# zzmkGx2i46_^jhEQ`T=PbRb~$up^S&F>plH3w5GWH;EGl79-Kye^{5L0jqL@IEoZY6 zHt%izQx62BDdgrn3}Org$N| zV_Te+-$C;!6sxZ(1C3QQg<$q;n7^G<67tWbCF9=?mdV8rQZ$@mg1>kCKNY1b_p*y86nrhxvR5OcwJ*fg)bLs z$Mn8!t`H2)drJ!;@Nyu2T@NfM%J$ioeh=l>5&ZUXKdaWpIu9DtW17qkaNNTToI8+t snYN4h+g5_gaAEQ?= 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();