fix: plunger and tapping positions

pull/282/head
alestiago 3 years ago
parent dea68d65ee
commit fe4eea948c

@ -87,7 +87,7 @@ class PinballGame extends Forge2DGame
@override @override
void onTapDown(TapDownInfo info) { void onTapDown(TapDownInfo info) {
if (info.raw.kind == PointerDeviceKind.touch) { if (info.raw.kind == PointerDeviceKind.touch) {
final rocket = children.whereType<RocketSpriteComponent>().first; final rocket = descendants().whereType<RocketSpriteComponent>().first;
final bounds = rocket.topLeftPosition & rocket.size; final bounds = rocket.topLeftPosition & rocket.size;
// NOTE(wolfen): As long as Flame does not have https://github.com/flame-engine/flame/issues/1586 we need to check it at the highest level manually. // NOTE(wolfen): As long as Flame does not have https://github.com/flame-engine/flame/issues/1586 we need to check it at the highest level manually.
@ -153,23 +153,27 @@ class _GameBallsController extends ComponentController<PinballGame>
@override @override
void onNewState(GameState state) { void onNewState(GameState state) {
super.onNewState(state); super.onNewState(state);
_spawnBall(); spawnBall();
} }
@override @override
void onMount() { Future<void> onLoad() async {
super.onMount(); await super.onLoad();
_spawnBall(); spawnBall();
} }
void _spawnBall() { void spawnBall() {
// TODO(alestiago): Refactor with behavioural pattern.
component.ready().whenComplete(() {
final plunger = parent!.descendants().whereType<Plunger>().single;
final ball = ControlledBall.launch( final ball = ControlledBall.launch(
characterTheme: component.characterTheme, characterTheme: component.characterTheme,
)..initialPosition = Vector2( )..initialPosition = Vector2(
Vector2(41.1, 43).x, plunger.body.position.x,
Vector2(41.1, 45).y - Ball.size.y, plunger.body.position.y - Ball.size.y,
); );
component.firstChild<ZCanvasComponent>()?.add(ball); component.firstChild<ZCanvasComponent>()?.add(ball);
});
} }
} }
@ -181,7 +185,7 @@ class DebugPinballGame extends PinballGame with FPSCounter {
characterTheme: characterTheme, characterTheme: characterTheme,
audio: audio, audio: audio,
) { ) {
controller = _DebugGameBallsController(this); controller = _GameBallsController(this);
} }
@override @override
@ -202,10 +206,6 @@ class DebugPinballGame extends PinballGame with FPSCounter {
} }
} }
class _DebugGameBallsController extends _GameBallsController {
_DebugGameBallsController(PinballGame game) : super(game);
}
// TODO(wolfenrain): investigate this CI failure. // TODO(wolfenrain): investigate this CI failure.
// coverage:ignore-start // coverage:ignore-start
class _DebugInformation extends Component with HasGameRef<DebugPinballGame> { class _DebugInformation extends Component with HasGameRef<DebugPinballGame> {

Loading…
Cancel
Save