mirror of https://github.com/flutter/pinball.git
feat: add rocket plunger (#180)
* feat: plunger rocket * feat: added plunger zone and placed rocket over plunger * chore: doc and unused import * refactor: move rocket to pinball components * refactor: created Launcher to group rocket, plunger and launchramp * chore: unused import * test: plunger and rocket tests * Update lib/game/components/launcher.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/launcher.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: add LauncherRamp nested to Launcher Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> Co-authored-by: Erick <erickzanardoo@gmail.com>pull/186/head
parent
034c3719bf
commit
333f91fc1e
Before Width: | Height: | Size: 11 KiB |
@ -0,0 +1,26 @@
|
|||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball/game/components/components.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart' hide Assets;
|
||||||
|
|
||||||
|
/// {@template launcher}
|
||||||
|
/// A [Blueprint] which creates the [Plunger], [RocketSpriteComponent] and
|
||||||
|
/// [LaunchRamp].
|
||||||
|
/// {@endtemplate}
|
||||||
|
class Launcher extends Forge2DBlueprint {
|
||||||
|
/// {@macro launcher}
|
||||||
|
Launcher();
|
||||||
|
|
||||||
|
/// [Plunger] to launch the [Ball] onto the board.
|
||||||
|
late final Plunger plunger;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void build(Forge2DGame gameRef) {
|
||||||
|
plunger = ControlledPlunger(compressionDistance: 12.3)
|
||||||
|
..initialPosition = Vector2(40.1, -38);
|
||||||
|
|
||||||
|
final _rocket = RocketSpriteComponent()..position = Vector2(43, 62);
|
||||||
|
|
||||||
|
addAll([_rocket, plunger]);
|
||||||
|
addBlueprint(LaunchRamp());
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 26 KiB |
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:pinball_components/gen/assets.gen.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart' hide Assets;
|
||||||
|
|
||||||
|
/// {@template rocket_sprite_component}
|
||||||
|
/// A [SpriteComponent] for the rocket over [Plunger].
|
||||||
|
/// {@endtemplate}
|
||||||
|
class RocketSpriteComponent extends SpriteComponent with HasGameRef {
|
||||||
|
// TODO(ruimiguel): change this priority to be over launcher ramp and bottom
|
||||||
|
// wall.
|
||||||
|
/// {@macro rocket_sprite_component}
|
||||||
|
RocketSpriteComponent() : super(priority: 5);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
final sprite = await gameRef.loadSprite(
|
||||||
|
Assets.images.plunger.rocket.keyName,
|
||||||
|
);
|
||||||
|
this.sprite = sprite;
|
||||||
|
size = sprite.originalSize / 10;
|
||||||
|
anchor = Anchor.center;
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 57 KiB |
@ -0,0 +1,28 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('RocketSpriteComponent', () {
|
||||||
|
final tester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
tester.testGameWidget(
|
||||||
|
'renders correctly',
|
||||||
|
setUp: (game, tester) async {
|
||||||
|
game.camera.followVector2(Vector2.zero());
|
||||||
|
await game.ensureAdd(RocketSpriteComponent());
|
||||||
|
},
|
||||||
|
verify: (game, tester) async {
|
||||||
|
await expectLater(
|
||||||
|
find.byGame<TestGame>(),
|
||||||
|
matchesGoldenFile('golden/plunger/rocket.png'),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue