diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index 501ea514..c2a5351e 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -1,11 +1,13 @@ import 'dart:async'; +import 'dart:ui'; +import 'dart:math' as math; import 'package:flame/input.dart'; import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:pinball/game/game.dart'; class PinballGame extends Forge2DGame - with FlameBloc, HasKeyboardHandlerComponents { + with FlameBloc, HasKeyboardHandlerComponents, TapDetector { // TODO(erickzanardo): Change to the plumber position late final ballStartingPosition = screenToWorld( Vector2( @@ -18,6 +20,29 @@ class PinballGame extends Forge2DGame // TODO(alestiago): Change to the design position. late final flippersPosition = ballStartingPosition - Vector2(0, 5); + late final launcherRampPosition = screenToWorld( + Vector2( + camera.viewport.effectiveSize.x / 2, + camera.viewport.effectiveSize.y / 2, + ) + + Vector2(369, -155), + ); + late final jetpackRampPosition = screenToWorld( + Vector2( + camera.viewport.effectiveSize.x / 2, + camera.viewport.effectiveSize.y / 2, + ) + + Vector2(-150, -150), + ); + + late final sparkyRampPosition = screenToWorld( + Vector2( + camera.viewport.effectiveSize.x / 2, + camera.viewport.effectiveSize.y / 2, + ) + + Vector2(80, -100), + ); + @override void onAttach() { super.onAttach(); @@ -36,6 +61,8 @@ class PinballGame extends Forge2DGame addContactCallback(BottomWallBallContactCallback()); unawaited(_addFlippers()); + + unawaited(_addPaths()); } Future _addFlippers() async { @@ -97,4 +124,39 @@ class PinballGame extends Forge2DGame ), ); } + + Future _addPaths() async { + await add( + Pathway.straight( + color: const Color.fromARGB(255, 34, 255, 0), + position: launcherRampPosition, + start: Vector2(0, 0), + end: Vector2(0, 600), + width: 80, + ), + ); + + await add( + JetpackRamp( + position: jetpackRampPosition, + ), + ); + + await add( + SparkyRamp( + position: sparkyRampPosition, + ), + ); + } + + @override + void onTapDown(TapDownInfo details) { + super.onTapDown(details); + final tapPosition = details.eventPosition.game; + add( + Ball( + position: tapPosition, + ), + ); + } }