From 55f8964b4837e037e099c0af9a7eb2df0603177e Mon Sep 17 00:00:00 2001 From: Bemoty Date: Fri, 15 Nov 2019 11:31:02 +0100 Subject: [PATCH] rework activity game over --- .../ScrollingImageView.java | 2 + .../htlcatcher/game/GameActivity.java | 51 ++++++++++- .../game/stats/GameOverActivity.java | 1 - app/src/main/res/layout/activity_game.xml | 87 +++++++++++++++++++ app/src/main/res/layout/activity_gameover.xml | 4 +- app/src/main/res/values-de-rAT/strings.xml | 2 - app/src/main/res/values-de/strings.xml | 2 - app/src/main/res/values-en/strings.xml | 2 - app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 2 - 10 files changed, 139 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/q42/android/scrollingimageview/ScrollingImageView.java b/app/src/main/java/com/q42/android/scrollingimageview/ScrollingImageView.java index 2807525..e2e7db8 100644 --- a/app/src/main/java/com/q42/android/scrollingimageview/ScrollingImageView.java +++ b/app/src/main/java/com/q42/android/scrollingimageview/ScrollingImageView.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Random; import lombok.Getter; +import lombok.Setter; import tirol.htlanichstrasse.htlcatcher.R; /** @@ -32,6 +33,7 @@ public class ScrollingImageView extends View { @Getter private List bitmaps; + @Setter private float speed; private int[] scene; private int arrayIndex = 0; diff --git a/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/GameActivity.java b/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/GameActivity.java index 7200812..fb61274 100644 --- a/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/GameActivity.java +++ b/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/GameActivity.java @@ -11,16 +11,20 @@ import android.util.Log; import android.view.MotionEvent; import android.view.View; +import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.view.animation.AccelerateDecelerateInterpolator; +import android.widget.TextView; +import com.q42.android.scrollingimageview.ScrollingImageView; import java.util.Timer; import java.util.TimerTask; import lombok.Getter; +import tirol.htlanichstrasse.htlcatcher.MainActivity; import tirol.htlanichstrasse.htlcatcher.R; import tirol.htlanichstrasse.htlcatcher.game.component.Floor; import tirol.htlanichstrasse.htlcatcher.game.stats.CatcherStatistics; -import tirol.htlanichstrasse.htlcatcher.game.stats.GameOverActivity; +import tirol.htlanichstrasse.htlcatcher.game.stats.CatcherStatistics.StatisticsAction; import tirol.htlanichstrasse.htlcatcher.util.Config; /** @@ -32,7 +36,8 @@ */ @SuppressWarnings("FieldCanBeLocal") @SuppressLint("ClickableViewAccessibility") -public class GameActivity extends AppCompatActivity implements View.OnTouchListener { +public class GameActivity extends AppCompatActivity implements View.OnTouchListener, + OnClickListener { /** * Static logging tag used for loggings from this class @@ -84,8 +89,30 @@ public void run() { // Check loss if (gameView.gameState == GameState.END) { cancel(); - finish(); - startActivity(new Intent(GameActivity.this, GameOverActivity.class)); + runOnUiThread(() -> { + final int shortAnimationDuration = getResources() + .getInteger(android.R.integer.config_shortAnimTime); + final View gameOverView = findViewById(R.id.gameOver); + gameOverView.setVisibility(View.VISIBLE); + gameOverView.setAlpha(0f); + gameOverView.animate().alpha(1f).setDuration(shortAnimationDuration) + .setListener(null); + ((ScrollingImageView) findViewById(R.id.scrolling_background)).setSpeed(0f); + ((ScrollingImageView) findViewById(R.id.scrolling_background_yellow)) + .setSpeed(0f); + ((ScrollingImageView) findViewById(R.id.scrolling_background_red)).setSpeed(0f); + ((ScrollingImageView) findViewById(R.id.scrolling_floor)).setSpeed(0f); + ((ScrollingImageView) findViewById(R.id.scrolling_clouds)).setSpeed(0f); + + // Load stats into view + final CatcherStatistics catcherStatistics = CatcherStatistics.getInstance(); + ((TextView) findViewById(R.id.pointsView)).setText( + getString(R.string.gameover_score, catcherStatistics.getPoints().get())); + ((TextView) findViewById(R.id.timeView)).setText( + getString(R.string.gameover_gametime, + catcherStatistics.points.get() - (catcherStatistics.caughtLogos.get() + * StatisticsAction.LOGO.getPoints()))); + }); } } }, 0, 50); @@ -194,4 +221,20 @@ public boolean onTouch(final View view, final MotionEvent event) { return true; } + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.restartButton: + finish(); + Intent intent = new Intent(this, GameActivity.class); + intent.putExtra("player_bm", getFilesDir() + "/PHOTO/me.png"); + startActivity(intent); + break; + case R.id.backToMenu: + finish(); + startActivity(new Intent(this, MainActivity.class)); + break; + } + } + } diff --git a/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/stats/GameOverActivity.java b/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/stats/GameOverActivity.java index 1bce752..cd77906 100644 --- a/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/stats/GameOverActivity.java +++ b/app/src/main/java/tirol/htlanichstrasse/htlcatcher/game/stats/GameOverActivity.java @@ -69,7 +69,6 @@ public void onClick(final View view) { startActivity(new Intent(this, MainActivity.class)); break; } - } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_game.xml b/app/src/main/res/layout/activity_game.xml index b9960a0..29f916f 100644 --- a/app/src/main/res/layout/activity_game.xml +++ b/app/src/main/res/layout/activity_game.xml @@ -1,5 +1,6 @@ + + @@ -50,12 +53,16 @@ scrolling_image_view:layout_constraintBottom_toBottomOf="parent" scrolling_image_view:speed="2.0dp" scrolling_image_view:src="@drawable/layer2" /> + + + + + + + + + + + + + + + + + +