forked from marco/firo_runner
Fixed the speed bug where runner would go faster on the android phone, but slower on the web.
This commit is contained in:
parent
88207b67ce
commit
7689a62616
@ -6,6 +6,7 @@ class GameState extends Component {
|
|||||||
bool isPaused = false;
|
bool isPaused = false;
|
||||||
int numCoins = 0;
|
int numCoins = 0;
|
||||||
int distance = 0;
|
int distance = 0;
|
||||||
|
late MyGame gameRef;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void update(double dt) {
|
void update(double dt) {
|
||||||
@ -19,7 +20,8 @@ class GameState extends Component {
|
|||||||
numCoins++;
|
numCoins++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUp() {
|
void setUp(MyGame gameRef) {
|
||||||
|
this.gameRef = gameRef;
|
||||||
numCoins = 0;
|
numCoins = 0;
|
||||||
distance = 0;
|
distance = 0;
|
||||||
start = DateTime.now().microsecondsSinceEpoch;
|
start = DateTime.now().microsecondsSinceEpoch;
|
||||||
@ -52,19 +54,19 @@ class GameState extends Component {
|
|||||||
if (!isPaused) {
|
if (!isPaused) {
|
||||||
switch (getLevel()) {
|
switch (getLevel()) {
|
||||||
case 7:
|
case 7:
|
||||||
return 250.0;
|
return gameRef.viewport.canvasSize.x * 0.25;
|
||||||
case 6:
|
case 6:
|
||||||
return 200.0;
|
return gameRef.viewport.canvasSize.x * 0.20;
|
||||||
case 5:
|
case 5:
|
||||||
return 180.0;
|
return gameRef.viewport.canvasSize.x * 0.18;
|
||||||
case 4:
|
case 4:
|
||||||
return 160.0;
|
return gameRef.viewport.canvasSize.x * 0.16;
|
||||||
case 3:
|
case 3:
|
||||||
return 140.0;
|
return gameRef.viewport.canvasSize.x * 0.14;
|
||||||
case 2:
|
case 2:
|
||||||
return 120.0;
|
return gameRef.viewport.canvasSize.x * 0.12;
|
||||||
default:
|
default:
|
||||||
return 100.0;
|
return gameRef.viewport.canvasSize.x * 0.1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -10,6 +10,7 @@ import 'package:firo_runner/wire_holder.dart';
|
|||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flame/extensions.dart';
|
import 'package:flame/extensions.dart';
|
||||||
import 'package:flame/flame.dart';
|
import 'package:flame/flame.dart';
|
||||||
|
import 'package:flame/game.dart' as flame;
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:flame/gestures.dart';
|
import 'package:flame/gestures.dart';
|
||||||
import 'package:flame/keyboard.dart';
|
import 'package:flame/keyboard.dart';
|
||||||
@ -64,6 +65,13 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
late Wire wire;
|
late Wire wire;
|
||||||
|
|
||||||
|
MyGame() : super() {
|
||||||
|
viewport.resize(Vector2(1920, 1080));
|
||||||
|
}
|
||||||
|
|
||||||
|
// @override
|
||||||
|
// flame.Viewport viewport = FixedResolutionViewport(Vector2(1920, 1080));
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onLoad() async {
|
Future<void> onLoad() async {
|
||||||
// debugMode = true;
|
// debugMode = true;
|
||||||
@ -180,7 +188,7 @@ class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
|||||||
wireHolder.setUp();
|
wireHolder.setUp();
|
||||||
bugHolder.setUp();
|
bugHolder.setUp();
|
||||||
|
|
||||||
gameState.setUp();
|
gameState.setUp(this);
|
||||||
|
|
||||||
runner.setUp();
|
runner.setUp();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user