|
|
@ -1,6 +1,7 @@
|
|
|
|
// ignore_for_file: public_member_api_docs
|
|
|
|
// ignore_for_file: public_member_api_docs
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flame/extensions.dart';
|
|
|
|
import 'package:flame/input.dart';
|
|
|
|
import 'package:flame/input.dart';
|
|
|
|
import 'package:flame_bloc/flame_bloc.dart';
|
|
|
|
import 'package:flame_bloc/flame_bloc.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
@ -16,6 +17,13 @@ class PinballGame extends Forge2DGame
|
|
|
|
|
|
|
|
|
|
|
|
late final Plunger plunger;
|
|
|
|
late final Plunger plunger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final boardSize = Vector2(72, 128);
|
|
|
|
|
|
|
|
static final boardBounds = Rect.fromCenter(
|
|
|
|
|
|
|
|
center: Offset.zero,
|
|
|
|
|
|
|
|
width: boardSize.x,
|
|
|
|
|
|
|
|
height: -boardSize.y,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void onAttach() {
|
|
|
|
void onAttach() {
|
|
|
|
super.onAttach();
|
|
|
|
super.onAttach();
|
|
|
@ -27,11 +35,16 @@ class PinballGame extends Forge2DGame
|
|
|
|
_addContactCallbacks();
|
|
|
|
_addContactCallbacks();
|
|
|
|
|
|
|
|
|
|
|
|
await _addGameBoundaries();
|
|
|
|
await _addGameBoundaries();
|
|
|
|
unawaited(_addBoard());
|
|
|
|
unawaited(add(Board()));
|
|
|
|
unawaited(_addPlunger());
|
|
|
|
unawaited(_addPlunger());
|
|
|
|
unawaited(_addBonusWord());
|
|
|
|
unawaited(_addBonusWord());
|
|
|
|
unawaited(_addPaths());
|
|
|
|
unawaited(_addPaths());
|
|
|
|
unawaited(addFromBlueprint(Spaceship()));
|
|
|
|
unawaited(addFromBlueprint(Spaceship()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fix camera on the center of the board size
|
|
|
|
|
|
|
|
camera
|
|
|
|
|
|
|
|
..followVector2(screenToWorld(boardSize / 2))
|
|
|
|
|
|
|
|
..zoom = size.y / 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _addContactCallbacks() {
|
|
|
|
void _addContactCallbacks() {
|
|
|
@ -41,44 +54,27 @@ class PinballGame extends Forge2DGame
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _addGameBoundaries() async {
|
|
|
|
Future<void> _addGameBoundaries() async {
|
|
|
|
await add(BottomWall(this));
|
|
|
|
await add(BottomWall());
|
|
|
|
createBoundaries(this).forEach(add);
|
|
|
|
createBoundaries(this).forEach(add);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _addBoard() async {
|
|
|
|
|
|
|
|
final board = Board(
|
|
|
|
|
|
|
|
size: screenToWorld(
|
|
|
|
|
|
|
|
Vector2(
|
|
|
|
|
|
|
|
camera.viewport.effectiveSize.x,
|
|
|
|
|
|
|
|
camera.viewport.effectiveSize.y,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await add(board);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _addPlunger() async {
|
|
|
|
Future<void> _addPlunger() async {
|
|
|
|
plunger = Plunger(
|
|
|
|
plunger = Plunger(compressionDistance: 2);
|
|
|
|
compressionDistance: camera.viewport.effectiveSize.y / 12,
|
|
|
|
|
|
|
|
);
|
|
|
|
plunger.initialPosition = boardBounds.bottomRight.toVector2() -
|
|
|
|
plunger.initialPosition = screenToWorld(
|
|
|
|
|
|
|
|
Vector2(
|
|
|
|
Vector2(
|
|
|
|
camera.viewport.effectiveSize.x / 2 + 450,
|
|
|
|
8,
|
|
|
|
camera.viewport.effectiveSize.y - plunger.compressionDistance,
|
|
|
|
-10,
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await add(plunger);
|
|
|
|
await add(plunger);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _addBonusWord() async {
|
|
|
|
Future<void> _addBonusWord() async {
|
|
|
|
await add(
|
|
|
|
await add(
|
|
|
|
BonusWord(
|
|
|
|
BonusWord(
|
|
|
|
position: screenToWorld(
|
|
|
|
position: Vector2(
|
|
|
|
Vector2(
|
|
|
|
boardBounds.center.dx,
|
|
|
|
camera.viewport.effectiveSize.x / 2,
|
|
|
|
boardBounds.bottom + 10,
|
|
|
|
camera.viewport.effectiveSize.y - 50,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -86,18 +82,22 @@ class PinballGame extends Forge2DGame
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> _addPaths() async {
|
|
|
|
Future<void> _addPaths() async {
|
|
|
|
final jetpackRamp = JetpackRamp(
|
|
|
|
final jetpackRamp = JetpackRamp(
|
|
|
|
position: Vector2(42.6, -45),
|
|
|
|
position: Vector2(
|
|
|
|
|
|
|
|
PinballGame.boardBounds.left + 25,
|
|
|
|
|
|
|
|
PinballGame.boardBounds.top - 20,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
final launcherRamp = LauncherRamp(
|
|
|
|
final launcherRamp = LauncherRamp(
|
|
|
|
position: screenToWorld(
|
|
|
|
position: Vector2(
|
|
|
|
Vector2(
|
|
|
|
PinballGame.boardBounds.right - 23,
|
|
|
|
camera.viewport.effectiveSize.x / 2 + 400,
|
|
|
|
PinballGame.boardBounds.bottom + 40,
|
|
|
|
camera.viewport.effectiveSize.y / 2 - 330,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await addAll([jetpackRamp, launcherRamp]);
|
|
|
|
await addAll([
|
|
|
|
|
|
|
|
jetpackRamp,
|
|
|
|
|
|
|
|
launcherRamp,
|
|
|
|
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void spawnBall() {
|
|
|
|
void spawnBall() {
|
|
|
|