From 00e6879c394b438458a2b29a05ed033ab91bc17f Mon Sep 17 00:00:00 2001 From: "Yu Squire[ Yu, Tsung-Ying ]" Date: Tue, 12 Nov 2024 19:10:07 +0800 Subject: [PATCH] refactor: using newer flame api --- lib/asset_manager/sprite_manager.dart | 3 +- lib/controllers/playing/obstacle.dart | 12 +++- lib/controllers/playing/obstacle/bird.dart | 18 +++--- lib/controllers/playing/obstacle/bus.dart | 10 +-- lib/controllers/playing/obstacle/car.dart | 10 +-- lib/controllers/playing/obstacle/person.dart | 18 +++--- lib/controllers/playing/player.dart | 66 ++++++++++---------- lib/controllers/playing/road.dart | 12 ++-- lib/controllers/playing/roads.dart | 10 +-- lib/controllers/scalable_sprite.dart | 6 +- lib/http_service.dart | 3 +- lib/main.dart | 34 +++++----- lib/overlays/game_over.dart | 2 +- lib/overlays/instruction.dart | 2 +- lib/overlays/joystick.dart | 2 +- lib/overlays/loading_icon.dart | 5 +- lib/overlays/milage_hud.dart | 2 +- lib/overlays/start_game.dart | 2 +- lib/screens/loading.dart | 2 +- lib/screens/playing.dart | 5 +- lib/screens/title.dart | 2 +- 21 files changed, 113 insertions(+), 113 deletions(-) diff --git a/lib/asset_manager/sprite_manager.dart b/lib/asset_manager/sprite_manager.dart index 12719df..dd626d1 100644 --- a/lib/asset_manager/sprite_manager.dart +++ b/lib/asset_manager/sprite_manager.dart @@ -33,8 +33,7 @@ abstract class SpriteManager { static Future> _generateSpritesList(int length, Future Function(int index) generator) async { final List spriteList = List.filled(length, null); - await Future.wait( - List.generate(length, (index) => generator(index).then((sprite) => spriteList[index] = sprite))); + await Future.wait(List.generate(length, (index) => generator(index).then((sprite) => spriteList[index] = sprite))); return List.unmodifiable(spriteList); } } diff --git a/lib/controllers/playing/obstacle.dart b/lib/controllers/playing/obstacle.dart index 64a78a3..df77c87 100644 --- a/lib/controllers/playing/obstacle.dart +++ b/lib/controllers/playing/obstacle.dart @@ -2,6 +2,8 @@ import 'dart:async'; import 'package:flame/collisions.dart'; import 'package:flame/components.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; import 'package:ncu_biking/controllers/scalable_sprite.dart'; class Obstacle extends ScalableSprite { @@ -16,8 +18,12 @@ class Obstacle extends ScalableSprite { @override FutureOr onLoad() { - // _hitbox.debugColor = Colors.green; - // _hitbox.debugMode = true; + if (kDebugMode) { + _hitbox.debugColor = Colors.green; + _hitbox.debugMode = true; + _hitbox.isSolid = true; + } + add(PositionComponent( anchor: Anchor.center, children: [_hitbox], @@ -27,7 +33,7 @@ class Obstacle extends ScalableSprite { @override void onMount() { - onGameResize(gameRef.size); + onGameResize(game.size); super.onMount(); } diff --git a/lib/controllers/playing/obstacle/bird.dart b/lib/controllers/playing/obstacle/bird.dart index 667bb9d..a85257d 100644 --- a/lib/controllers/playing/obstacle/bird.dart +++ b/lib/controllers/playing/obstacle/bird.dart @@ -20,7 +20,7 @@ class Bird extends Obstacle { @override FutureOr onLoad() async { for (int i = 0; i < 4; i++) { - _sprites.add(gameRef.spriteManager.birds[i]); + _sprites.add(game.spriteManager.birds[i]); } sprite = _sprites.first; anchor = Anchor.center; @@ -42,20 +42,20 @@ class Bird extends Obstacle { @override void onMount() { position = Vector2( - gameRef.size.x / 2 + (_rightForward ? -1 : 1) * 520 * gameRef.scale, - size.y + Random().nextInt((gameRef.size.y / 3 - size.y).toInt()), + game.size.x / 2 + (_rightForward ? -1 : 1) * 520 * game.scale, + size.y + Random().nextInt((game.size.y / 3 - size.y).toInt()), ); super.onMount(); } @override void update(double dt) { - if (gameRef.isPlaying) { - position.y += (gameRef.baseSpeed + _speed) * dt * gameRef.scale; - position.x += (_rightForward ? 1 : -1) * _speed * dt * gameRef.scale; - if (position.y > gameRef.size.y + size.y || - position.x < gameRef.size.x / 2 - 550 * gameRef.scale || - position.x > gameRef.size.x / 2 + 550 * gameRef.scale) { + if (game.isPlaying) { + position.y += (game.baseSpeed + _speed) * dt * game.scale; + position.x += (_rightForward ? 1 : -1) * _speed * dt * game.scale; + if (position.y > game.size.y + size.y || + position.x < game.size.x / 2 - 550 * game.scale || + position.x > game.size.x / 2 + 550 * game.scale) { removeFromParent(); } } diff --git a/lib/controllers/playing/obstacle/bus.dart b/lib/controllers/playing/obstacle/bus.dart index 54d53c9..0e4f9c2 100644 --- a/lib/controllers/playing/obstacle/bus.dart +++ b/lib/controllers/playing/obstacle/bus.dart @@ -18,7 +18,7 @@ class Bus extends Obstacle { @override FutureOr onLoad() async { for (int i = 0; i < 6; i++) { - _sprites.add(gameRef.spriteManager.buses[i]); + _sprites.add(game.spriteManager.buses[i]); } sprite = _sprites.first; anchor = Anchor.center; @@ -40,16 +40,16 @@ class Bus extends Obstacle { @override void onMount() { position = Vector2( - gameRef.size.x / 2, - gameRef.size.y + size.y / 2, + game.size.x / 2, + game.size.y + size.y / 2, ); super.onMount(); } @override void update(double dt) { - if (gameRef.isPlaying) { - position.y -= gameRef.baseSpeed * dt * gameRef.scale; + if (game.isPlaying) { + position.y -= game.baseSpeed * dt * game.scale; if (position.y < -size.y) { removeFromParent(); } diff --git a/lib/controllers/playing/obstacle/car.dart b/lib/controllers/playing/obstacle/car.dart index 592db41..a9f4fbd 100644 --- a/lib/controllers/playing/obstacle/car.dart +++ b/lib/controllers/playing/obstacle/car.dart @@ -12,7 +12,7 @@ class Car extends Obstacle { @override FutureOr onLoad() async { - sprite = gameRef.spriteManager.cars[Random().nextInt(3)]; + sprite = game.spriteManager.cars[Random().nextInt(3)]; anchor = Anchor.center; angle = pi / 180 * 90; return super.onLoad(); @@ -21,7 +21,7 @@ class Car extends Obstacle { @override void onMount() { position = Vector2( - gameRef.size.x / 2 + (Random().nextBool() ? 1 : -1) * 400 * gameRef.scale, + game.size.x / 2 + (Random().nextBool() ? 1 : -1) * 400 * game.scale, -size.y / 2, ); super.onMount(); @@ -29,9 +29,9 @@ class Car extends Obstacle { @override void update(double dt) { - if (gameRef.isPlaying) { - position.y += gameRef.baseSpeed * dt * gameRef.scale; - if (position.y > gameRef.size.y + size.y) { + if (game.isPlaying) { + position.y += game.baseSpeed * dt * game.scale; + if (position.y > game.size.y + size.y) { removeFromParent(); } } diff --git a/lib/controllers/playing/obstacle/person.dart b/lib/controllers/playing/obstacle/person.dart index 112058f..6c3a1ad 100644 --- a/lib/controllers/playing/obstacle/person.dart +++ b/lib/controllers/playing/obstacle/person.dart @@ -19,7 +19,7 @@ class Person extends Obstacle { @override FutureOr onLoad() async { for (int i = 0; i < 4; i++) { - _sprites.add(gameRef.spriteManager.persons[i]); + _sprites.add(game.spriteManager.persons[i]); } sprite = _sprites.first; anchor = Anchor.center; @@ -41,20 +41,20 @@ class Person extends Obstacle { @override void onMount() { position = Vector2( - gameRef.size.x / 2 + (_rightForward ? -1 : 1) * 520 * gameRef.scale, - size.y + Random().nextInt((gameRef.size.y / 2 - size.y).toInt()), + game.size.x / 2 + (_rightForward ? -1 : 1) * 520 * game.scale, + size.y + Random().nextInt((game.size.y / 2 - size.y).toInt()), ); super.onMount(); } @override void update(double dt) { - if (gameRef.isPlaying) { - position.y += gameRef.baseSpeed * dt * gameRef.scale; - position.x += (_rightForward ? 1 : -1) * _speed * dt * gameRef.scale; - if (position.y > gameRef.size.y + size.y || - position.x < gameRef.size.x / 2 - 550 * gameRef.scale || - position.x > gameRef.size.x / 2 + 550 * gameRef.scale) { + if (game.isPlaying) { + position.y += game.baseSpeed * dt * game.scale; + position.x += (_rightForward ? 1 : -1) * _speed * dt * game.scale; + if (position.y > game.size.y + size.y || + position.x < game.size.x / 2 - 550 * game.scale || + position.x > game.size.x / 2 + 550 * game.scale) { removeFromParent(); } } diff --git a/lib/controllers/playing/player.dart b/lib/controllers/playing/player.dart index 6fcc1ef..3929ad7 100644 --- a/lib/controllers/playing/player.dart +++ b/lib/controllers/playing/player.dart @@ -3,6 +3,8 @@ import 'dart:collection'; import 'package:flame/collisions.dart'; import 'package:flame/components.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:ncu_biking/controllers/playing/obstacle.dart'; import 'package:ncu_biking/controllers/scalable_sprite.dart'; @@ -11,8 +13,8 @@ import 'package:ncu_biking/main.dart'; class Player extends ScalableSprite with CollisionCallbacks, KeyboardHandler { Player({super.coefficient = 0.12}); - late final double _forwardSpeed = gameRef.baseSpeed + 300; - late final double _backwardSpeed = gameRef.baseSpeed; + late final double _forwardSpeed = game.baseSpeed + 300; + late final double _backwardSpeed = game.baseSpeed; final double _offsetSpeed = 5; final _hitbox = RectangleHitbox(); final _sprites = Queue(); @@ -24,13 +26,16 @@ class Player extends ScalableSprite with CollisionCallbacks, KeyboardHandler { @override FutureOr onLoad() async { for (int i = 0; i < 3; i++) { - _sprites.add(gameRef.spriteManager.players[i]); + _sprites.add(game.spriteManager.players[i]); } sprite = _sprites.first; anchor = Anchor.center; - // _hitbox.debugColor = Colors.red; - // _hitbox.debugMode = true; + if (kDebugMode) { + _hitbox.debugColor = Colors.red; + _hitbox.debugMode = true; + _hitbox.isSolid = true; + } animationTimer = Timer( 0.2, @@ -52,39 +57,39 @@ class Player extends ScalableSprite with CollisionCallbacks, KeyboardHandler { _offset = 0; _offsetDest = 0; position = _getDefaultPosition(); - onGameResize(gameRef.size); + onGameResize(game.size); super.onMount(); } @override void update(double dt) { - position.x = gameRef.size.x / 2 + _offset * 330 * gameRef.scale; + position.x = game.size.x / 2 + _offset * 330 * game.scale; - if (!gameRef.isPlaying) { + if (!game.isPlaying) { super.update(dt); return; } - if (_isMovingForward && position.y > gameRef.size.y * 0.15) { - position.y -= _forwardSpeed * dt * gameRef.scale; - gameRef.milage += dt * _forwardSpeed; + if (_isMovingForward && position.y > game.size.y * 0.15) { + position.y -= _forwardSpeed * dt * game.scale; + game.milage += dt * _forwardSpeed; milageChangeNotifier.notify(); } else if (position.y < _getDefaultPosition().y) { - position.y += _backwardSpeed * dt * gameRef.scale; + position.y += _backwardSpeed * dt * game.scale; } else { position.y = _getDefaultPosition().y; - gameRef.milage += dt * _backwardSpeed; + game.milage += dt * _backwardSpeed; milageChangeNotifier.notify(); } if (_offsetDest != _offset) { if (_offsetDest < _offset) { - _offset -= _offsetSpeed * dt * gameRef.scale; + _offset -= _offsetSpeed * dt * game.scale; if (_offsetDest >= _offset) { _offset = _offsetDest.toDouble(); } } else { - _offset += _offsetSpeed * dt * gameRef.scale; + _offset += _offsetSpeed * dt * game.scale; if (_offsetDest <= _offset) { _offset = _offsetDest.toDouble(); } @@ -107,7 +112,7 @@ class Player extends ScalableSprite with CollisionCallbacks, KeyboardHandler { @override bool onKeyEvent(KeyEvent event, Set keysPressed) { - if (gameRef.isPlaying) { + if (game.isPlaying) { if (event is KeyDownEvent) { switch (event.logicalKey) { case LogicalKeyboardKey.arrowLeft: @@ -140,15 +145,14 @@ class Player extends ScalableSprite with CollisionCallbacks, KeyboardHandler { } @override - void onCollisionStart( - Set intersectionPoints, PositionComponent other) { + void onCollisionStart(Set intersectionPoints, PositionComponent other) { try { - gameRef.crashed = other.parent as Obstacle; + game.crashed = other.parent as Obstacle; } catch (e) { - gameRef.crashed = null; + game.crashed = null; } - gameRef.overlays.add("game_over"); - gameRef.isPlaying = false; + game.overlays.add("game_over"); + game.isPlaying = false; super.onCollisionStart(intersectionPoints, other); } @@ -169,7 +173,7 @@ class Player extends ScalableSprite with CollisionCallbacks, KeyboardHandler { } Vector2 _getDefaultPosition() { - return Vector2(gameRef.size.x / 2, gameRef.size.y * 0.9); + return Vector2(game.size.x / 2, game.size.y * 0.9); } } @@ -181,26 +185,24 @@ class _PositionHitbox extends PositionComponent with CollisionCallbacks { @override void onCollision(Set intersectionPoints, PositionComponent other) { - if (parent is CollisionCallbacks) { - (parent as CollisionCallbacks).onCollision(intersectionPoints, other); + if (parent case final CollisionCallbacks parent) { + parent.onCollision(intersectionPoints, other); } super.onCollision(intersectionPoints, other); } @override - void onCollisionStart( - Set intersectionPoints, PositionComponent other) { - if (parent is CollisionCallbacks) { - (parent as CollisionCallbacks) - .onCollisionStart(intersectionPoints, other); + void onCollisionStart(Set intersectionPoints, PositionComponent other) { + if (parent case final CollisionCallbacks parent) { + parent.onCollisionStart(intersectionPoints, other); } super.onCollisionStart(intersectionPoints, other); } @override void onCollisionEnd(PositionComponent other) { - if (parent is CollisionCallbacks) { - (parent as CollisionCallbacks).onCollisionEnd(other); + if (parent case final CollisionCallbacks parent) { + parent.onCollisionEnd(other); } super.onCollisionEnd(other); } diff --git a/lib/controllers/playing/road.dart b/lib/controllers/playing/road.dart index 93d117a..bb5966d 100644 --- a/lib/controllers/playing/road.dart +++ b/lib/controllers/playing/road.dart @@ -12,18 +12,18 @@ class Road extends ScalableSprite { final Function()? _onArrived; Road? linked; - late final double _speed = gameRef.baseSpeed; + late final double _speed = game.baseSpeed; @override void update(double dt) { - if (gameRef.isPlaying) { + if (game.isPlaying) { if (linked == null) { - position.y += dt * _speed * gameRef.scale; - if (position.y > gameRef.size.y + size.y) { + position.y += dt * _speed * game.scale; + if (position.y > game.size.y + size.y) { if (_onArrived != null) _onArrived!.call(); } } else { - position.y = linked!.y - linked!.size.y + dt * _speed * gameRef.scale; + position.y = linked!.y - linked!.size.y + dt * _speed * game.scale; } } super.update(dt); @@ -31,7 +31,7 @@ class Road extends ScalableSprite { @override void onGameResize(Vector2 size) { - position.x = gameRef.size.x / 2; + position.x = game.size.x / 2; super.onGameResize(size); } } diff --git a/lib/controllers/playing/roads.dart b/lib/controllers/playing/roads.dart index c3c19ad..8292ff4 100644 --- a/lib/controllers/playing/roads.dart +++ b/lib/controllers/playing/roads.dart @@ -5,27 +5,27 @@ import 'package:flame/components.dart'; import 'package:ncu_biking/controllers/playing/road.dart'; import 'package:ncu_biking/main.dart'; -class Roads extends Component with HasGameRef
{ +class Roads extends Component with HasGameReference { final roads = Queue(); @override FutureOr onLoad() async { for (int i = 0; i < 4; i++) { roads.add(Road( - sprite: gameRef.spriteManager.roads[i], + sprite: game.spriteManager.roads[i], linked: roads.lastOrNull, onArrived: () { remove(roads.first); roads.first.linked = roads.last; roads.add(roads.removeFirst()); roads.first.linked = null; - roads.first.y = gameRef.size.y; + roads.first.y = game.size.y; add(roads.elementAt(1)); }, ) ..anchor = Anchor.bottomCenter - ..x = gameRef.size.x / 2 - ..y = gameRef.size.y); + ..x = game.size.x / 2 + ..y = game.size.y); if (i < 2) { add(roads.last); diff --git a/lib/controllers/scalable_sprite.dart b/lib/controllers/scalable_sprite.dart index 10f0042..2ee505a 100644 --- a/lib/controllers/scalable_sprite.dart +++ b/lib/controllers/scalable_sprite.dart @@ -1,7 +1,7 @@ import 'package:flame/components.dart'; import 'package:ncu_biking/main.dart'; -class ScalableSprite extends SpriteComponent with HasGameRef
{ +class ScalableSprite extends SpriteComponent with HasGameReference { ScalableSprite({ required this.coefficient, super.sprite, @@ -12,9 +12,7 @@ class ScalableSprite extends SpriteComponent with HasGameRef
{ @override void onGameResize(Vector2 size) { super.size = (sprite?.originalSize ?? Vector2.zero()) * - (gameRef.scale * - coefficient * - (gameRef.coverWidth / (sprite?.originalSize ?? Vector2.zero()).x)); + (game.scale * coefficient * (game.coverWidth / (sprite?.originalSize ?? Vector2.zero()).x)); super.onGameResize(size); } } diff --git a/lib/http_service.dart b/lib/http_service.dart index 881162a..ab3d6ff 100644 --- a/lib/http_service.dart +++ b/lib/http_service.dart @@ -20,8 +20,7 @@ class HttpService { initializeInterceptors(); } - Future _request(String path, - {required String method, Map? query}) async { + Future _request(String path, {required String method, Map? query}) async { Response response; try { response = await _dio.request( diff --git a/lib/main.dart b/lib/main.dart index 5e4b9b5..f8d8349 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -54,15 +54,15 @@ Future main() async { ), )), home: Scaffold( - body: GameWidget( - game: Main(token: token), + body: GameWidget( + game: NcuBikingGame(token: token), overlayBuilderMap: { - "loading_icon": (BuildContext context, Main game) => LoadingIcon(game: game), - "start_game": (BuildContext context, Main game) => StartGame(game: game), - "instruction": (BuildContext context, Main game) => Instruction(game: game), - "milage_hud": (BuildContext context, Main game) => MilageHud(game: game), - "joystick": (BuildContext context, Main game) => Joystick(game: game), - "game_over": (BuildContext context, Main game) => GameOver(game: game), + "loading_icon": (_, game) => LoadingIcon(game: game), + "start_game": (_, game) => StartGame(game: game), + "instruction": (_, game) => Instruction(game: game), + "milage_hud": (_, game) => MilageHud(game: game), + "joystick": (_, game) => Joystick(game: game), + "game_over": (_, game) => GameOver(game: game), }, initialActiveOverlays: const ["loading_icon"], ), @@ -71,8 +71,8 @@ Future main() async { )); } -class Main extends FlameGame with HasKeyboardHandlerComponents, HasCollisionDetection { - Main({String? token}) { +class NcuBikingGame extends FlameGame with HasKeyboardHandlerComponents, HasCollisionDetection { + NcuBikingGame({String? token}) { httpService = HttpService( "https://api.game.ncufresh.ncu.edu.tw", token: token, @@ -101,14 +101,12 @@ class Main extends FlameGame with HasKeyboardHandlerComponents, HasCollisionDete @override FutureOr onLoad() async { await Future.wait([ - () async { - add(_backgroundSprite - ..sprite = await Sprite.load("cover/background.png") - ..anchor = Anchor.center); - }(), - () async { - faviconImage = (await rootBundle.load("assets/images/cover/favicon.gif")).buffer.asUint8List(); - }(), + Sprite.load("cover/background.png").then((sprite) => add( + _backgroundSprite + ..sprite = sprite + ..anchor = Anchor.center, + )), + rootBundle.load("assets/images/cover/favicon.gif").then((data) => faviconImage = data.buffer.asUint8List()), ]); add(router = RouterComponent( diff --git a/lib/overlays/game_over.dart b/lib/overlays/game_over.dart index 0c99f7c..221f012 100644 --- a/lib/overlays/game_over.dart +++ b/lib/overlays/game_over.dart @@ -14,7 +14,7 @@ class GameOver extends StatefulWidget { required this.game, }); - final Main game; + final NcuBikingGame game; @override State createState() => _GameOverState(); diff --git a/lib/overlays/instruction.dart b/lib/overlays/instruction.dart index a80cf9b..95ca329 100644 --- a/lib/overlays/instruction.dart +++ b/lib/overlays/instruction.dart @@ -8,7 +8,7 @@ class Instruction extends StatefulWidget { required this.game, }); - final Main game; + final NcuBikingGame game; @override State createState() => _InstructionState(); diff --git a/lib/overlays/joystick.dart b/lib/overlays/joystick.dart index d169008..be200ff 100644 --- a/lib/overlays/joystick.dart +++ b/lib/overlays/joystick.dart @@ -8,7 +8,7 @@ class Joystick extends StatelessWidget { required this.game, }); - final Main game; + final NcuBikingGame game; @override Widget build(BuildContext context) { diff --git a/lib/overlays/loading_icon.dart b/lib/overlays/loading_icon.dart index 1a6e71e..10a3859 100644 --- a/lib/overlays/loading_icon.dart +++ b/lib/overlays/loading_icon.dart @@ -9,7 +9,7 @@ class LoadingIcon extends StatelessWidget { required this.game, }); - final Main game; + final NcuBikingGame game; @override Widget build(BuildContext context) { @@ -24,8 +24,7 @@ class LoadingIcon extends StatelessWidget { Container( width: squareSize, height: squareSize, - constraints: const BoxConstraints( - maxHeight: squareSizeLimit, maxWidth: squareSizeLimit), + constraints: const BoxConstraints(maxHeight: squareSizeLimit, maxWidth: squareSizeLimit), child: Image.memory(game.faviconImage), ), Text( diff --git a/lib/overlays/milage_hud.dart b/lib/overlays/milage_hud.dart index dbb8d37..5ada5a5 100644 --- a/lib/overlays/milage_hud.dart +++ b/lib/overlays/milage_hud.dart @@ -8,7 +8,7 @@ class MilageHud extends StatelessWidget { required this.game, }); - final Main game; + final NcuBikingGame game; @override Widget build(BuildContext context) { diff --git a/lib/overlays/start_game.dart b/lib/overlays/start_game.dart index 14984ad..3d1cab6 100644 --- a/lib/overlays/start_game.dart +++ b/lib/overlays/start_game.dart @@ -7,7 +7,7 @@ class StartGame extends StatelessWidget { required this.game, }); - final Main game; + final NcuBikingGame game; @override Widget build(BuildContext context) { diff --git a/lib/screens/loading.dart b/lib/screens/loading.dart index c704e7c..2359728 100644 --- a/lib/screens/loading.dart +++ b/lib/screens/loading.dart @@ -5,7 +5,7 @@ import 'package:ncu_biking/asset_manager/image_manager.dart'; import 'package:ncu_biking/main.dart'; import 'package:ncu_biking/asset_manager/sprite_manager.dart'; -class Loading extends Component with HasGameRef
{ +class Loading extends Component with HasGameRef { @override FutureOr onLoad() async { await Future.wait([ diff --git a/lib/screens/playing.dart b/lib/screens/playing.dart index 638867b..6d56850 100644 --- a/lib/screens/playing.dart +++ b/lib/screens/playing.dart @@ -15,7 +15,7 @@ import 'package:ncu_biking/main.dart'; /// - Person, 橫向移動 /// - Bird, 斜向後移動 -class Playing extends Component with HasGameRef
{ +class Playing extends Component with HasGameRef { final double _updateTime = 0.1; int stage = 0; @@ -98,8 +98,7 @@ class Playing extends Component with HasGameRef
{ } bool _toGenerate(int index) { - return Random().nextDouble() < _frequencyTable[stage][index] && - _coldDown[index] <= 0; + return Random().nextDouble() < _frequencyTable[stage][index] && _coldDown[index] <= 0; } void _coldDownReset(int index) { diff --git a/lib/screens/title.dart b/lib/screens/title.dart index 56094f0..1370379 100644 --- a/lib/screens/title.dart +++ b/lib/screens/title.dart @@ -4,7 +4,7 @@ import 'package:flame/components.dart'; import 'package:flame/input.dart'; import 'package:ncu_biking/main.dart'; -class Title extends Component with HasGameRef
{ +class Title extends Component with HasGameRef { final _cover = SpriteComponent(); final _startButton = SpriteButtonComponent();