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() {
final ball = ControlledBall.launch( // TODO(alestiago): Refactor with behavioural pattern.
characterTheme: component.characterTheme, component.ready().whenComplete(() {
)..initialPosition = Vector2( final plunger = parent!.descendants().whereType<Plunger>().single;
Vector2(41.1, 43).x, final ball = ControlledBall.launch(
Vector2(41.1, 45).y - Ball.size.y, characterTheme: component.characterTheme,
); )..initialPosition = Vector2(
component.firstChild<ZCanvasComponent>()?.add(ball); plunger.body.position.x,
plunger.body.position.y - Ball.size.y,
);
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