2021-09-04 04:17:12 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/bug_holder.dart';
|
|
|
|
import 'package:firo_runner/circuit_background.dart';
|
|
|
|
import 'package:firo_runner/coin_holder.dart';
|
2021-09-17 01:39:42 +00:00
|
|
|
import 'package:firo_runner/debris_holder.dart';
|
2021-09-09 22:56:26 +00:00
|
|
|
import 'package:firo_runner/firework.dart';
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/game_state.dart';
|
2021-09-16 21:15:32 +00:00
|
|
|
import 'package:firo_runner/moving_object.dart';
|
2021-09-14 17:23:02 +00:00
|
|
|
import 'package:firo_runner/platform.dart';
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/platform_holder.dart';
|
2021-09-17 03:17:51 +00:00
|
|
|
import 'package:firo_runner/wall_holder.dart';
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/wire.dart';
|
|
|
|
import 'package:firo_runner/wire_holder.dart';
|
2021-09-02 22:30:18 +00:00
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame/extensions.dart';
|
|
|
|
import 'package:flame/flame.dart';
|
|
|
|
import 'package:flame/game.dart';
|
|
|
|
import 'package:flame/gestures.dart';
|
|
|
|
import 'package:flame/keyboard.dart';
|
|
|
|
import 'package:flame_audio/flame_audio.dart';
|
2021-08-31 16:46:17 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-09-02 22:30:18 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/runner.dart';
|
2021-09-06 22:04:41 +00:00
|
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
2021-08-31 16:46:17 +00:00
|
|
|
|
2021-09-20 20:32:10 +00:00
|
|
|
import 'package:firo_runner/lose_menu_overlay.dart';
|
|
|
|
|
2021-09-08 21:44:12 +00:00
|
|
|
const COLOR = Color(0xFFDDC0A3);
|
2021-09-04 22:56:08 +00:00
|
|
|
|
2021-09-07 20:45:42 +00:00
|
|
|
const LEVEL2 = 10000000;
|
|
|
|
const LEVEL3 = 20000000;
|
|
|
|
const LEVEL4 = 30000000;
|
|
|
|
const LEVEL5 = 40000000;
|
|
|
|
const LEVEL6 = 50000000;
|
|
|
|
const LEVEL7 = 60000000;
|
|
|
|
|
2021-09-20 20:32:10 +00:00
|
|
|
const OVERLAY_PRIORITY = 110;
|
2021-09-04 22:56:08 +00:00
|
|
|
const RUNNER_PRIORITY = 100;
|
2021-09-09 22:56:26 +00:00
|
|
|
const BUG_PRIORITY = 75;
|
|
|
|
const COIN_PRIORITY = 70;
|
2021-09-04 22:56:08 +00:00
|
|
|
const PLATFORM_PRIORITY = 50;
|
2021-09-17 03:17:51 +00:00
|
|
|
const WALL_PRIORITY = 40;
|
2021-09-17 01:39:42 +00:00
|
|
|
const DEBRIS_PRIORITY = 30;
|
2021-09-04 22:56:08 +00:00
|
|
|
const WIRE_PRIORITY = 25;
|
2021-09-09 22:56:26 +00:00
|
|
|
const FIREWORK_PRIORITY = 15;
|
|
|
|
const WINDOW_PRIORITY = 10;
|
2021-09-02 22:30:18 +00:00
|
|
|
|
2021-09-20 20:32:10 +00:00
|
|
|
const overlayText = TextStyle(
|
|
|
|
fontSize: 30,
|
|
|
|
color: Colors.white,
|
|
|
|
);
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Flame.device.fullScreen();
|
|
|
|
await Flame.device.setLandscape();
|
|
|
|
final myGame = MyGame();
|
2021-09-20 20:32:10 +00:00
|
|
|
runApp(GameWidget<MyGame>(
|
|
|
|
game: myGame,
|
|
|
|
overlayBuilderMap: {
|
|
|
|
'gameOver': (_, myGame) {
|
|
|
|
return LoseMenuOverlay(game: myGame);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
));
|
2021-08-31 16:46:17 +00:00
|
|
|
}
|
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
int getNearestPlatform(int level) {
|
|
|
|
return level <= 0
|
|
|
|
? 0
|
|
|
|
: level <= 3
|
|
|
|
? 2
|
|
|
|
: level <= 6
|
|
|
|
? 5
|
|
|
|
: 8;
|
|
|
|
}
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
class MyGame extends BaseGame with PanDetector, TapDetector, KeyboardEvents {
|
2021-09-09 22:56:26 +00:00
|
|
|
TextPaint fireworksPaint = TextPaint(
|
|
|
|
config: const TextPaintConfig(
|
|
|
|
fontSize: 48.0, fontFamily: 'Codystar', color: COLOR),
|
2021-09-02 22:30:18 +00:00
|
|
|
);
|
|
|
|
|
2021-09-20 20:32:10 +00:00
|
|
|
TextPaint scoresPaint = TextPaint(
|
|
|
|
config: const TextPaintConfig(fontSize: 16.0, color: COLOR),
|
|
|
|
);
|
|
|
|
|
2021-09-05 01:05:08 +00:00
|
|
|
late CircuitBackground circuitBackground;
|
2021-09-03 23:29:18 +00:00
|
|
|
late PlatformHolder platformHolder;
|
2021-09-04 22:56:08 +00:00
|
|
|
late CoinHolder coinHolder;
|
|
|
|
late WireHolder wireHolder;
|
2021-09-05 00:18:37 +00:00
|
|
|
late BugHolder bugHolder;
|
2021-09-09 22:56:26 +00:00
|
|
|
late Firework fireworks;
|
2021-09-17 01:39:42 +00:00
|
|
|
late DebrisHolder debrisHolder;
|
2021-09-17 03:17:51 +00:00
|
|
|
late WallHolder wallHolder;
|
2021-09-04 04:17:12 +00:00
|
|
|
Random random = Random();
|
2021-09-06 22:04:41 +00:00
|
|
|
bool playingMusic = false;
|
2021-09-03 23:29:18 +00:00
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
late Runner runner;
|
2021-09-03 23:29:18 +00:00
|
|
|
late GameState gameState;
|
2021-09-02 22:30:18 +00:00
|
|
|
late double blockSize;
|
|
|
|
|
2021-09-03 23:29:18 +00:00
|
|
|
bool loaded = false;
|
2021-09-20 20:32:10 +00:00
|
|
|
bool firstDeath = true;
|
2021-09-04 22:56:08 +00:00
|
|
|
late Wire wire;
|
2021-09-20 20:32:10 +00:00
|
|
|
late TextComponent _distance;
|
|
|
|
late TextComponent _coins;
|
2021-09-03 23:29:18 +00:00
|
|
|
|
2021-09-08 23:07:54 +00:00
|
|
|
MyGame() : super() {
|
|
|
|
viewport.resize(Vector2(1920, 1080));
|
|
|
|
}
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
2021-09-04 22:56:08 +00:00
|
|
|
// debugMode = true;
|
2021-09-02 22:30:18 +00:00
|
|
|
FlameAudio.bgm.initialize();
|
|
|
|
|
2021-09-05 01:05:08 +00:00
|
|
|
circuitBackground = CircuitBackground(this);
|
|
|
|
await circuitBackground.load();
|
2021-09-03 23:29:18 +00:00
|
|
|
platformHolder = PlatformHolder();
|
2021-09-16 21:15:32 +00:00
|
|
|
await platformHolder.load();
|
2021-09-04 22:56:08 +00:00
|
|
|
coinHolder = CoinHolder();
|
2021-09-16 21:15:32 +00:00
|
|
|
await coinHolder.load();
|
2021-09-04 22:56:08 +00:00
|
|
|
wireHolder = WireHolder();
|
2021-09-16 21:15:32 +00:00
|
|
|
await wireHolder.load();
|
2021-09-05 00:18:37 +00:00
|
|
|
bugHolder = BugHolder();
|
2021-09-16 21:15:32 +00:00
|
|
|
await bugHolder.load();
|
2021-09-17 01:39:42 +00:00
|
|
|
debrisHolder = DebrisHolder();
|
|
|
|
await debrisHolder.load();
|
2021-09-17 03:17:51 +00:00
|
|
|
wallHolder = WallHolder();
|
|
|
|
await wallHolder.load();
|
2021-09-09 22:56:26 +00:00
|
|
|
fireworks = Firework(this);
|
|
|
|
await fireworks.load();
|
2021-09-03 23:29:18 +00:00
|
|
|
|
|
|
|
gameState = GameState();
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
runner = Runner();
|
|
|
|
await runner.load(loadSpriteAnimation);
|
2021-09-03 23:29:18 +00:00
|
|
|
|
2021-09-06 22:04:41 +00:00
|
|
|
if (!kIsWeb) {
|
|
|
|
playMusic();
|
|
|
|
}
|
2021-09-03 23:29:18 +00:00
|
|
|
loaded = true;
|
2021-09-20 20:32:10 +00:00
|
|
|
_distance = TextComponent("Distance: 0",
|
|
|
|
position: Vector2(size.x - 100, 10), textRenderer: scoresPaint)
|
|
|
|
..anchor = Anchor.topRight;
|
|
|
|
_distance.changePriorityWithoutResorting(OVERLAY_PRIORITY);
|
|
|
|
_coins = TextComponent("Coins: 0",
|
|
|
|
position: Vector2(size.x - 10, 10), textRenderer: scoresPaint)
|
|
|
|
..anchor = Anchor.topRight;
|
|
|
|
_coins.changePriorityWithoutResorting(OVERLAY_PRIORITY);
|
2021-09-05 22:36:36 +00:00
|
|
|
setUp();
|
2021-09-03 23:29:18 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 22:04:41 +00:00
|
|
|
void playMusic() {
|
|
|
|
FlameAudio.bgm.play('Infinite_Spankage_M.mp3');
|
|
|
|
playingMusic = true;
|
|
|
|
}
|
|
|
|
|
2021-09-03 23:29:18 +00:00
|
|
|
void fillScreen() {
|
2021-09-05 22:36:36 +00:00
|
|
|
if (shouldReset) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-11 02:39:32 +00:00
|
|
|
|
|
|
|
platformHolder.generatePlatforms(this);
|
|
|
|
|
|
|
|
int wireChosenRegion = random.nextInt(9);
|
|
|
|
if (wireChosenRegion % 3 != 2 &&
|
|
|
|
wireChosenRegion != 6 &&
|
|
|
|
wireChosenRegion != 7) {
|
2021-09-17 03:26:57 +00:00
|
|
|
wireHolder.generateWire(this, wireChosenRegion);
|
2021-09-03 23:29:18 +00:00
|
|
|
}
|
2021-09-04 22:56:08 +00:00
|
|
|
|
2021-09-11 02:39:32 +00:00
|
|
|
int bugChosenRegion = random.nextInt(9);
|
2021-09-17 01:39:42 +00:00
|
|
|
if (bugChosenRegion % 3 != 2 && bugChosenRegion % 3 != 0) {
|
2021-09-17 03:26:57 +00:00
|
|
|
bugHolder.generateBug(this, bugChosenRegion);
|
2021-09-05 00:18:37 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 01:39:42 +00:00
|
|
|
int debrisChosenRegion = random.nextInt(9);
|
|
|
|
if (debrisChosenRegion % 3 == 0 && debrisChosenRegion != 6) {
|
2021-09-17 03:26:57 +00:00
|
|
|
debrisHolder.generateDebris(this, debrisChosenRegion);
|
2021-09-17 01:39:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-11 02:39:32 +00:00
|
|
|
int choseCoinLevel = random.nextInt(9);
|
|
|
|
if (choseCoinLevel % 3 != 2 && choseCoinLevel != 6) {
|
2021-09-17 03:26:57 +00:00
|
|
|
coinHolder.generateCoin(this, choseCoinLevel);
|
2021-09-04 04:17:12 +00:00
|
|
|
}
|
2021-09-17 03:17:51 +00:00
|
|
|
|
|
|
|
int wallChosenRegion = random.nextInt(9);
|
|
|
|
if (wallChosenRegion % 3 == 1 && wallChosenRegion != 7) {
|
2021-09-17 03:26:57 +00:00
|
|
|
wallHolder.generateWall(this, wallChosenRegion);
|
2021-09-17 03:17:51 +00:00
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 00:36:14 +00:00
|
|
|
bool isTooNearOtherObstacles(Rect rect) {
|
|
|
|
Rect obstacleBounds = Rect.fromLTRB(
|
2021-09-17 03:17:51 +00:00
|
|
|
3 * rect.left - 2 * (rect.left + blockSize) - 1,
|
|
|
|
3 * rect.top - 2 * (rect.top + blockSize) - 1,
|
|
|
|
3 * (rect.left + blockSize) - 2 * rect.left + 1,
|
|
|
|
3 * (rect.top + blockSize) - 2 * rect.top + 1);
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> wireLevel in wireHolder.objects) {
|
|
|
|
for (MovingObject wire in wireLevel) {
|
2021-09-05 00:36:14 +00:00
|
|
|
if (wire.intersect(obstacleBounds) != "none") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> coinLevel in coinHolder.objects) {
|
|
|
|
for (MovingObject coin in coinLevel) {
|
2021-09-05 00:36:14 +00:00
|
|
|
if (coin.intersect(obstacleBounds) != "none") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
for (List<MovingObject> bugLevel in bugHolder.objects) {
|
|
|
|
for (MovingObject bug in bugLevel) {
|
2021-09-05 00:36:14 +00:00
|
|
|
if (bug.intersect(obstacleBounds) != "none") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 01:39:42 +00:00
|
|
|
for (List<MovingObject> debrisLevel in debrisHolder.objects) {
|
|
|
|
for (MovingObject debris in debrisLevel) {
|
|
|
|
if (debris.intersect(obstacleBounds) != "none") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 03:17:51 +00:00
|
|
|
for (List<MovingObject> wallLevel in wallHolder.objects) {
|
|
|
|
for (MovingObject wall in wallLevel) {
|
|
|
|
if (wall.intersect(obstacleBounds) != "none") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-05 00:36:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-05 22:36:36 +00:00
|
|
|
bool shouldReset = false;
|
|
|
|
|
2021-09-20 20:32:10 +00:00
|
|
|
void displayLoss() {
|
2021-09-10 19:25:01 +00:00
|
|
|
if (!(runner.sprite.animation?.done() ?? false) &&
|
2021-09-20 20:32:10 +00:00
|
|
|
runner.sprite.animation!.loop == false &&
|
|
|
|
firstDeath) {
|
2021-09-05 22:36:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-09-20 20:32:10 +00:00
|
|
|
firstDeath = false;
|
|
|
|
overlays.add('gameOver');
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
2021-09-05 22:36:36 +00:00
|
|
|
runner.sprite.animation!.reset();
|
2021-09-20 20:32:10 +00:00
|
|
|
overlays.remove('gameOver');
|
2021-09-05 22:36:36 +00:00
|
|
|
shouldReset = false;
|
2021-09-08 21:44:12 +00:00
|
|
|
components.clear();
|
2021-09-05 22:36:36 +00:00
|
|
|
setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
void die() {
|
|
|
|
gameState.setPaused();
|
|
|
|
shouldReset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setUp() {
|
|
|
|
add(runner);
|
2021-09-09 22:56:26 +00:00
|
|
|
fireworks.setUp();
|
2021-09-05 22:36:36 +00:00
|
|
|
runner.sprite.clearEffects();
|
|
|
|
runner.sprite.current = RunnerState.run;
|
|
|
|
circuitBackground.setUp();
|
|
|
|
platformHolder.setUp();
|
|
|
|
coinHolder.setUp();
|
|
|
|
wireHolder.setUp();
|
|
|
|
bugHolder.setUp();
|
2021-09-17 01:39:42 +00:00
|
|
|
debrisHolder.setUp();
|
2021-09-17 03:17:51 +00:00
|
|
|
wallHolder.setUp();
|
2021-09-05 22:36:36 +00:00
|
|
|
|
2021-09-08 23:07:54 +00:00
|
|
|
gameState.setUp(this);
|
2021-09-05 22:36:36 +00:00
|
|
|
|
|
|
|
runner.setUp();
|
2021-09-20 20:32:10 +00:00
|
|
|
add(_coins);
|
|
|
|
add(_distance);
|
2021-09-05 22:36:36 +00:00
|
|
|
|
|
|
|
fillScreen();
|
2021-09-16 21:15:32 +00:00
|
|
|
platformHolder.objects[2][0].sprite.current = PlatformState.left;
|
|
|
|
platformHolder.objects[5][0].sprite.current = PlatformState.left;
|
2021-09-05 22:36:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 16:46:17 +00:00
|
|
|
@override
|
2021-09-02 22:30:18 +00:00
|
|
|
void render(Canvas canvas) {
|
2021-09-05 01:05:08 +00:00
|
|
|
circuitBackground.render(canvas);
|
2021-09-09 22:56:26 +00:00
|
|
|
fireworks.renderText(canvas);
|
2021-09-02 22:30:18 +00:00
|
|
|
super.render(canvas);
|
2021-09-13 19:21:52 +00:00
|
|
|
final fpsCount = fps(10000);
|
2021-09-09 22:56:26 +00:00
|
|
|
fireworksPaint.render(
|
2021-09-03 23:29:18 +00:00
|
|
|
canvas,
|
|
|
|
fpsCount.toString(),
|
|
|
|
Vector2(0, 0),
|
|
|
|
);
|
2021-08-31 16:46:17 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
@override
|
|
|
|
void update(double dt) {
|
2021-09-09 22:56:26 +00:00
|
|
|
fireworks.update(dt);
|
2021-09-03 23:29:18 +00:00
|
|
|
platformHolder.removePast(this);
|
2021-09-04 04:17:12 +00:00
|
|
|
coinHolder.removePast(this);
|
2021-09-04 22:56:08 +00:00
|
|
|
wireHolder.removePast(this);
|
2021-09-05 00:18:37 +00:00
|
|
|
bugHolder.removePast(this);
|
2021-09-17 01:39:42 +00:00
|
|
|
debrisHolder.removePast(this);
|
2021-09-17 03:17:51 +00:00
|
|
|
wallHolder.removePast(this);
|
2021-09-03 23:29:18 +00:00
|
|
|
fillScreen();
|
2021-09-02 22:30:18 +00:00
|
|
|
super.update(dt);
|
2021-09-05 01:05:08 +00:00
|
|
|
circuitBackground.update(dt);
|
2021-09-03 23:29:18 +00:00
|
|
|
gameState.update(dt);
|
|
|
|
platformHolder.update(dt);
|
2021-09-04 04:17:12 +00:00
|
|
|
coinHolder.update(dt);
|
2021-09-04 22:56:08 +00:00
|
|
|
wireHolder.update(dt);
|
2021-09-05 00:18:37 +00:00
|
|
|
bugHolder.update(dt);
|
2021-09-17 01:39:42 +00:00
|
|
|
debrisHolder.update(dt);
|
2021-09-17 03:17:51 +00:00
|
|
|
wallHolder.update(dt);
|
2021-09-20 20:32:10 +00:00
|
|
|
|
|
|
|
_distance.text = "Distance: ${gameState.getPlayerDistance()}";
|
|
|
|
_coins.text = "Coins: ${gameState.numCoins}";
|
|
|
|
if (shouldReset && !overlays.isActive('gameOver')) {
|
|
|
|
displayLoss();
|
2021-09-05 22:36:36 +00:00
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2021-09-08 21:44:12 +00:00
|
|
|
void onResize(Vector2 canvasSize) {
|
2021-09-16 17:38:46 +00:00
|
|
|
Vector2 oldSize = viewport.canvasSize;
|
2021-09-08 21:44:12 +00:00
|
|
|
super.onResize(canvasSize);
|
|
|
|
blockSize = canvasSize.y / 9;
|
2021-09-16 17:38:46 +00:00
|
|
|
if (loaded) {
|
|
|
|
double xRatio = canvasSize.x / oldSize.x;
|
|
|
|
double yRatio = canvasSize.y / oldSize.y;
|
|
|
|
circuitBackground.resize(canvasSize, xRatio, yRatio);
|
|
|
|
runner.resize(canvasSize, xRatio, yRatio);
|
|
|
|
platformHolder.resize(canvasSize, xRatio, yRatio);
|
|
|
|
coinHolder.resize(canvasSize, xRatio, yRatio);
|
|
|
|
wireHolder.resize(canvasSize, xRatio, yRatio);
|
|
|
|
bugHolder.resize(canvasSize, xRatio, yRatio);
|
2021-09-17 01:39:42 +00:00
|
|
|
debrisHolder.resize(canvasSize, xRatio, yRatio);
|
2021-09-17 03:17:51 +00:00
|
|
|
wallHolder.resize(canvasSize, xRatio, yRatio);
|
2021-09-16 17:38:46 +00:00
|
|
|
fireworks.resize(canvasSize, xRatio, yRatio);
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|
2021-08-31 16:46:17 +00:00
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
// Mobile controls
|
2021-09-04 22:56:08 +00:00
|
|
|
late List<double> xDeltas;
|
|
|
|
late List<double> yDeltas;
|
2021-09-02 22:30:18 +00:00
|
|
|
@override
|
|
|
|
void onPanStart(DragStartInfo info) {
|
2021-09-04 22:56:08 +00:00
|
|
|
xDeltas = List.empty(growable: true);
|
|
|
|
yDeltas = List.empty(growable: true);
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|
2021-08-31 16:46:17 +00:00
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
@override
|
|
|
|
void onPanUpdate(DragUpdateInfo info) {
|
2021-09-04 22:56:08 +00:00
|
|
|
xDeltas.add(info.delta.game.x);
|
|
|
|
yDeltas.add(info.delta.game.y);
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|
2021-08-31 16:46:17 +00:00
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
@override
|
|
|
|
void onPanEnd(DragEndInfo info) {
|
2021-09-06 22:04:41 +00:00
|
|
|
if (!playingMusic && kIsWeb) {
|
|
|
|
playMusic();
|
|
|
|
}
|
2021-09-04 22:56:08 +00:00
|
|
|
double xDelta = xDeltas.isEmpty
|
2021-09-02 22:30:18 +00:00
|
|
|
? 0
|
2021-09-04 22:56:08 +00:00
|
|
|
: xDeltas.reduce((value, element) => value + element);
|
|
|
|
double yDelta = yDeltas.isEmpty
|
2021-09-02 22:30:18 +00:00
|
|
|
? 0
|
2021-09-04 22:56:08 +00:00
|
|
|
: yDeltas.reduce((value, element) => value + element);
|
|
|
|
if (xDelta.abs() > yDelta.abs()) {
|
|
|
|
if (xDelta > 0) {
|
2021-09-02 22:30:18 +00:00
|
|
|
runner.control("right");
|
|
|
|
} else {
|
|
|
|
runner.control("left");
|
|
|
|
}
|
2021-09-04 22:56:08 +00:00
|
|
|
} else if (xDelta.abs() < yDelta.abs()) {
|
|
|
|
if (yDelta > 0) {
|
2021-09-02 22:30:18 +00:00
|
|
|
runner.control("down");
|
|
|
|
} else {
|
|
|
|
runner.control("up");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-31 16:46:17 +00:00
|
|
|
|
|
|
|
@override
|
2021-09-02 22:30:18 +00:00
|
|
|
void onTap() {
|
2021-09-06 22:04:41 +00:00
|
|
|
if (!playingMusic && kIsWeb) {
|
|
|
|
playMusic();
|
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
runner.control("center");
|
|
|
|
}
|
2021-08-31 16:46:17 +00:00
|
|
|
|
2021-09-02 22:30:18 +00:00
|
|
|
// Keyboard controls.
|
|
|
|
var keyboardKey;
|
|
|
|
@override
|
|
|
|
void onKeyEvent(RawKeyEvent event) {
|
2021-09-06 22:04:41 +00:00
|
|
|
if (!playingMusic && kIsWeb) {
|
|
|
|
playMusic();
|
|
|
|
}
|
2021-09-13 19:21:52 +00:00
|
|
|
print(event.data.logicalKey.keyId);
|
|
|
|
print(event.data.keyLabel);
|
2021-09-02 22:30:18 +00:00
|
|
|
if (event is RawKeyUpEvent) {
|
|
|
|
keyboardKey = null;
|
|
|
|
switch (event.data.keyLabel) {
|
|
|
|
case "w":
|
|
|
|
runner.control("up");
|
|
|
|
break;
|
|
|
|
case "a":
|
|
|
|
runner.control("left");
|
|
|
|
break;
|
|
|
|
case "s":
|
|
|
|
runner.control("down");
|
|
|
|
break;
|
|
|
|
case "d":
|
|
|
|
runner.control("right");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (event.data.logicalKey.keyId == 32) {
|
|
|
|
runner.control("down");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (event is RawKeyDownEvent && event.data.logicalKey.keyId == 32) {
|
|
|
|
if (keyboardKey == null) {
|
|
|
|
runner.control("center");
|
|
|
|
}
|
|
|
|
keyboardKey = "spacebar";
|
|
|
|
}
|
2021-08-31 16:46:17 +00:00
|
|
|
}
|
2021-09-02 22:30:18 +00:00
|
|
|
}
|