Skip to content

Commit 81930e2

Browse files
luanpotterspydon
andauthored
docs: Update t-rex game to use TapCallbacks (#2888)
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]>
1 parent 1aa4098 commit 81930e2

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

.github/.cspell/words_dictionary.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ gamepads
1111
gameplay
1212
gapless
1313
grayscale
14-
highscore
1514
hoverable
1615
hoverables
1716
inactives

examples/games/trex/lib/trex_game.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'package:trex_game/player.dart';
1515
enum GameState { playing, intro, gameOver }
1616

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

3535
int _score = 0;
36-
int _highscore = 0;
36+
int _highScore = 0;
3737
int get score => _score;
3838
set score(int newScore) {
3939
_score = newScore;
40-
scoreText.text = '${scoreString(_score)} HI ${scoreString(_highscore)}';
40+
scoreText.text = '${scoreString(_score)} HI ${scoreString(_highScore)}';
4141
}
4242

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

101101
@override
102-
void onTapDown(TapDownInfo info) {
102+
void onTapDown(TapDownEvent event) {
103103
onAction();
104104
}
105105

@@ -125,8 +125,8 @@ class TRexGame extends FlameGame
125125
currentSpeed = startSpeed;
126126
gameOverPanel.visible = false;
127127
timePlaying = 0.0;
128-
if (score > _highscore) {
129-
_highscore = score;
128+
if (score > _highScore) {
129+
_highScore = score;
130130
}
131131
score = 0;
132132
_distanceTraveled = 0;

0 commit comments

Comments
 (0)