Skip to content

Commit

Permalink
rework activity game over
Browse files Browse the repository at this point in the history
  • Loading branch information
bemoty committed Nov 15, 2019
1 parent bf514e6 commit 55f8964
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;
import java.util.Random;
import lombok.Getter;
import lombok.Setter;
import tirol.htlanichstrasse.htlcatcher.R;

/**
Expand All @@ -32,6 +33,7 @@ public class ScrollingImageView extends View {

@Getter
private List<Bitmap> bitmaps;
@Setter
private float speed;
private int[] scene;
private int arrayIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void onClick(final View view) {
startActivity(new Intent(this, MainActivity.class));
break;
}

}

}
87 changes: 87 additions & 0 deletions app/src/main/res/layout/activity_game.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version = "1.0" encoding = "utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:scrolling_image_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand Down Expand Up @@ -32,13 +33,15 @@
scrolling_image_view:speed="0.2dp"
scrolling_image_view:src="@drawable/layer1" />

<!-- awesome clouds in front of city -->
<com.q42.android.scrollingimageview.ScrollingImageView
android:id="@+id/scrolling_clouds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
scrolling_image_view:speed="0.4dp"
scrolling_image_view:src="@drawable/clouds" />

<!-- floor -->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -50,12 +53,16 @@
scrolling_image_view:layout_constraintBottom_toBottomOf="parent"
scrolling_image_view:speed="2.0dp"
scrolling_image_view:src="@drawable/layer2" />

</android.support.constraint.ConstraintLayout>

<!-- game -->
<tirol.htlanichstrasse.htlcatcher.game.GameView
android:id="@+id/gameView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<!-- stage 2 -->
<TextView
android:id="@+id/stage2"
android:layout_width="match_parent"
Expand All @@ -73,6 +80,7 @@
android:translationY="-300dp"
android:visibility="gone" />

<!-- stage 3 -->
<TextView
android:id="@+id/stage3"
android:layout_width="match_parent"
Expand All @@ -90,4 +98,83 @@
android:textSize="56sp"
android:visibility="gone" />

<!-- game over stuff -->
<LinearLayout
android:id="@+id/gameOver"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorSoftBlack"
android:orientation="vertical"
android:visibility="gone">

<ImageView
android:id="@+id/htlLogo"
android:layout_width="fill_parent"
android:layout_height="@dimen/logo_height"
android:layout_marginTop="20dp"
android:contentDescription="@string/gameover_title_description"
app:srcCompat="@mipmap/ic_launcher_foreground" />

<TextView
android:id="@+id/gameOverText"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-black"
android:text="@string/gameover_title"
android:textAlignment="center"
android:textColor="@android:color/white"
android:textSize="30sp"
android:textStyle="bold" />

<LinearLayout
android:id="@+id/scoreLinLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="vertical">
<TextView
android:id="@+id/pointsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textAlignment="center"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/timeView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textAlignment="center"
android:textColor="@android:color/white" />
</LinearLayout>

<Button
android:id="@+id/restartButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:background="@drawable/button_game_over_design"
android:fontFamily="sans-serif-black"
android:onClick="onClick"
android:text="@string/gameover_newgame"
android:textColor="@android:color/white" />

<Button
android:id="@+id/backToMenu"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:background="@drawable/button_game_over_design"
android:fontFamily="sans-serif-black"
android:onClick="onClick"
android:text="@string/backToMainMenu"
android:textColor="@android:color/white" />

</LinearLayout>

</FrameLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_gameover.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="end"
android:text="@string/gameover_footer"
android:text=""
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="@+id/creditFooter"
app:layout_constraintEnd_toEndOf="parent" />
Expand All @@ -85,7 +85,7 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@string/credit_footer"
android:text=""
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-de-rAT/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<string name="main_takephoto_button">Foto aufnehmen</string>
<string name="backToMainMenu">Hauptmenü</string>
<string name="gameDescription">HTLCatcher ist ein Flappy-Bird-ähnliches Spiel bei dem du so lange wie möglich durch auf dich zukommende Hindernisse navigieren musst. Je länger dir dies gelingt, desto mehr Punkte erhältst du. Zusätzlich dazu kannst du versuchen, vorbeifliegende HTL Logos zu fangen, um noch mehr Punkte zu erhalten.</string>
<string name="gameover_footer">© HTL Anichstraße</string>
<string name="gameover_gametime">Spielzeit: %1$d Sekunde(n)</string>
<string name="gameover_newgame">Neues Spiel starten</string>
<string name="gameover_score">Punkte: %1$d</string>
Expand All @@ -18,7 +17,6 @@
<string name="main_takephoto_toast_nopermission">(Die App benötigt dafür Zugriff auf deine Kamera)</string>
<string name="main_takephoto_toast_nophoto">Bitte zuerst ein Foto machen!</string>
<string name="main_title">HTL Catcher</string>
<string name="credit_footer">Rossi N. | Winkler J. | Sammer H.</string>
<string name="game_stage3">Sudden Death!</string>
<string name="game_stage2">LEVEL UP!</string>
</resources>
2 changes: 0 additions & 2 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<string name="main_takephoto_button">Foto aufnehmen</string>
<string name="backToMainMenu">Hauptmenü</string>
<string name="gameDescription">HTLCatcher ist ein Flappy-Bird-ähnliches Spiel bei dem du so lange wie möglich durch auf dich zukommende Hindernisse navigieren musst. Je länger dir dies gelingt, desto mehr Punkte erhältst du. Zusätzlich dazu kannst du versuchen, vorbeifliegende HTL Logos zu fangen, um noch mehr Punkte zu erhalten.</string>
<string name="gameover_footer">© HTL Anichstraße</string>
<string name="gameover_gametime">Spielzeit: %1$d Sekunde(n)</string>
<string name="gameover_newgame">Neues Spiel starten</string>
<string name="gameover_score">Punkte: %1$d</string>
Expand All @@ -18,7 +17,6 @@
<string name="main_takephoto_toast_nopermission">(Die App benötigt dafür Zugriff auf deine Kamera)</string>
<string name="main_takephoto_toast_nophoto">Bitte zuerst ein Foto machen!</string>
<string name="main_title">HTL Catcher</string>
<string name="credit_footer">Rossi N. | Winkler J. | Sammer H.</string>
<string name="game_stage3">Sudden Death!</string>
<string name="game_stage2">LEVEL UP!</string>
</resources>
2 changes: 0 additions & 2 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<string name="main_takephoto_button">Take photo</string>
<string name="backToMainMenu">Main Menu</string>
<string name="gameDescription">HTlCatcher is a Flappy-Bird-inspired game where you have to navigate your avatar through approaching obstacles as long as possible. The longer you manage to navigate through them, the more points you get. Additionally, you can try to catch passing HTL logos to acquire even more points.</string>
<string name="gameover_footer">© HTL Anichstraße</string>
<string name="gameover_gametime">Time: %1$d second(s)</string>
<string name="gameover_newgame">Start new game</string>
<string name="gameover_score">Points: %1$d</string>
Expand All @@ -18,7 +17,6 @@
<string name="main_takephoto_toast_nopermission">(The app needs access to your camera for this)</string>
<string name="main_takephoto_toast_nophoto">Please take a photo first!</string>
<string name="main_title">HTL Catcher</string>
<string name="credit_footer">Rossi N. | Winkler J. | Sammer H.</string>
<string name="game_stage3">Sudden Death!</string>
<string name="game_stage2">LEVEL UP!</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorSoftBlack">#99000000</color>
</resources>
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<string name="main_takephoto_button">Take photo</string>
<string name="backToMainMenu">Main Menu</string>
<string name="gameDescription">HTLCatcher is a Flappy-Bird-inspired game where you have to navigate your player character through approaching obstacles as long as possible. The longer you manage to navigate through them, the more points you get. Additionally, you can try to catch passing HTL logos to get even more points.</string>
<string name="gameover_footer">© HTL Anichstraße</string>
<string name="gameover_gametime">Time: %1$d second(s)</string>
<string name="gameover_newgame">Start new game</string>
<string name="gameover_score">Points: %1$d</string>
Expand All @@ -17,7 +16,6 @@
<string name="main_takephoto_toast_nopermission">(The app needs access to your camera for this)</string>
<string name="main_takephoto_toast_nophoto">Please take a photo first!</string>
<string name="main_title">HTL Catcher</string>
<string name="credit_footer">Rossi N. | Winkler J. | Sammer H.</string>
<string name="game_stage3">Sudden Death!</string>
<string name="instruction">You can control your avatar by tapping on the display. Upon every tap, your character jumps up a bit but then immediately falls back down due to gravitational affectation.</string>
<string name="game_stage2">LEVEL UP!</string>
Expand Down

0 comments on commit 55f8964

Please sign in to comment.