From 7689a6261648cb81243b5e9bf1089fa5b5fbb83d Mon Sep 17 00:00:00 2001 From: marco Date: Wed, 8 Sep 2021 17:07:54 -0600 Subject: [PATCH] Fixed the speed bug where runner would go faster on the android phone, but slower on the web. --- lib/game_state.dart | 18 ++++++++++-------- lib/main.dart | 10 +++++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/game_state.dart b/lib/game_state.dart index c88003c..94264e2 100644 --- a/lib/game_state.dart +++ b/lib/game_state.dart @@ -6,6 +6,7 @@ class GameState extends Component { bool isPaused = false; int numCoins = 0; int distance = 0; + late MyGame gameRef; @override void update(double dt) { @@ -19,7 +20,8 @@ class GameState extends Component { numCoins++; } - void setUp() { + void setUp(MyGame gameRef) { + this.gameRef = gameRef; numCoins = 0; distance = 0; start = DateTime.now().microsecondsSinceEpoch; @@ -52,19 +54,19 @@ class GameState extends Component { if (!isPaused) { switch (getLevel()) { case 7: - return 250.0; + return gameRef.viewport.canvasSize.x * 0.25; case 6: - return 200.0; + return gameRef.viewport.canvasSize.x * 0.20; case 5: - return 180.0; + return gameRef.viewport.canvasSize.x * 0.18; case 4: - return 160.0; + return gameRef.viewport.canvasSize.x * 0.16; case 3: - return 140.0; + return gameRef.viewport.canvasSize.x * 0.14; case 2: - return 120.0; + return gameRef.viewport.canvasSize.x * 0.12; default: - return 100.0; + return gameRef.viewport.canvasSize.x * 0.1; } } else { return 0; diff --git a/lib/main.dart b/lib/main.dart index 754a1c8..bb92be2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,6 +10,7 @@ import 'package:firo_runner/wire_holder.dart'; import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame/flame.dart'; +import 'package:flame/game.dart' as flame; import 'package:flame/game.dart'; import 'package:flame/gestures.dart'; import 'package:flame/keyboard.dart'; @@ -64,6 +65,13 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents { bool loaded = false; late Wire wire; + MyGame() : super() { + viewport.resize(Vector2(1920, 1080)); + } + + // @override + // flame.Viewport viewport = FixedResolutionViewport(Vector2(1920, 1080)); + @override Future onLoad() async { // debugMode = true; @@ -180,7 +188,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents { wireHolder.setUp(); bugHolder.setUp(); - gameState.setUp(); + gameState.setUp(this); runner.setUp();