Fixed the speed bug where runner would go faster on the android phone, but slower on the web.

This commit is contained in:
Marco Salazar 2021-09-08 17:07:54 -06:00
parent 88207b67ce
commit 7689a62616
2 changed files with 19 additions and 9 deletions

View File

@ -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;

View File

@ -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<void> 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();