mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 04:47:13 +08:00 
			
		
		
		
	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](https://github.com/flame-engine/flame/pull/2886). Also update the term high score to avoid a dictionary entry. Co-authored-by: Lukas Klingsbo <me@lukas.fyi>
This commit is contained in:
		
							
								
								
									
										1
									
								
								.github/.cspell/words_dictionary.txt
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.github/.cspell/words_dictionary.txt
									
									
									
									
										vendored
									
									
								
							@ -11,7 +11,6 @@ gamepads
 | 
			
		||||
gameplay
 | 
			
		||||
gapless
 | 
			
		||||
grayscale
 | 
			
		||||
highscore
 | 
			
		||||
hoverable
 | 
			
		||||
hoverables
 | 
			
		||||
inactives
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
@ -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');
 | 
			
		||||
@ -99,7 +99,7 @@ class TRexGame extends FlameGame
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void onTapDown(TapDownInfo info) {
 | 
			
		||||
  void onTapDown(TapDownEvent event) {
 | 
			
		||||
    onAction();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user