Skip to content

Commit

Permalink
docs: Update t-rex game to use TapCallbacks (#2888)
Browse files Browse the repository at this point in the history
Update t-rex game to use `TapCallbacks` instead of `TapDetector`, in
anticipation of [deprecating the
latter](#2886).

Also update the term high score to avoid a dictionary entry.

Co-authored-by: Lukas Klingsbo <[email protected]>
  • Loading branch information
luanpotter and spydon authored Dec 1, 2023
1 parent 1aa4098 commit 81930e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion .github/.cspell/words_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ gamepads
gameplay
gapless
grayscale
highscore
hoverable
hoverables
inactives
Expand Down
12 changes: 6 additions & 6 deletions examples/games/trex/lib/trex_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:trex_game/player.dart';
enum GameState { playing, intro, gameOver }

class TRexGame extends FlameGame
with KeyboardEvents, TapDetector, HasCollisionDetection {
with KeyboardEvents, TapCallbacks, HasCollisionDetection {
static const String description = '''
A game similar to the game in chrome that you get to play while offline.
Press space or tap/click the screen to jump, the more obstacles you manage
Expand All @@ -33,11 +33,11 @@ class TRexGame extends FlameGame
late final TextComponent scoreText;

int _score = 0;
int _highscore = 0;
int _highScore = 0;
int get score => _score;
set score(int newScore) {
_score = newScore;
scoreText.text = '${scoreString(_score)} HI ${scoreString(_highscore)}';
scoreText.text = '${scoreString(_score)} HI ${scoreString(_highScore)}';
}

String scoreString(int score) => score.toString().padLeft(5, '0');
Expand Down Expand Up @@ -99,7 +99,7 @@ class TRexGame extends FlameGame
}

@override
void onTapDown(TapDownInfo info) {
void onTapDown(TapDownEvent event) {
onAction();
}

Expand All @@ -125,8 +125,8 @@ class TRexGame extends FlameGame
currentSpeed = startSpeed;
gameOverPanel.visible = false;
timePlaying = 0.0;
if (score > _highscore) {
_highscore = score;
if (score > _highScore) {
_highScore = score;
}
score = 0;
_distanceTraveled = 0;
Expand Down

0 comments on commit 81930e2

Please sign in to comment.