Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update t-rex game to use TapCallbacks #2888

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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