feat: add Dash animatronic (#169)
* feat: add Dash animatronic * refactor: controlled animatronic * fix: unused import * refactor: remove animatronic controller * chore: non-nullable onLoad * test: animatronic is in forestpull/183/head
After Width: | Height: | Size: 886 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
@ -0,0 +1,53 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
|
||||
/// {@template dash_animatronic}
|
||||
/// Animated Dash that sits on top of the [BigDashNestBumper].
|
||||
/// {@endtemplate}
|
||||
class DashAnimatronic extends SpriteAnimationComponent with HasGameRef {
|
||||
/// {@macro dash_animatronic}
|
||||
DashAnimatronic()
|
||||
: super(
|
||||
anchor: Anchor.center,
|
||||
playing: false,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
|
||||
final spriteSheet = await gameRef.images.load(
|
||||
Assets.images.dash.animatronic.keyName,
|
||||
);
|
||||
|
||||
const amountPerRow = 12;
|
||||
const amountPerColumn = 8;
|
||||
final textureSize = Vector2(
|
||||
spriteSheet.width / amountPerRow,
|
||||
spriteSheet.height / amountPerColumn,
|
||||
);
|
||||
size = textureSize / 10;
|
||||
|
||||
animation = SpriteAnimation.fromFrameData(
|
||||
spriteSheet,
|
||||
SpriteAnimationData.sequenced(
|
||||
amount: amountPerRow * amountPerColumn,
|
||||
amountPerRow: amountPerRow,
|
||||
stepTime: 1 / 24,
|
||||
textureSize: textureSize,
|
||||
loop: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
super.update(dt);
|
||||
if (animation != null) {
|
||||
if (animation!.isLastFrame) {
|
||||
animation!.reset();
|
||||
playing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
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() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
final flameTester = FlameTester(TestGame.new);
|
||||
|
||||
group('DashAnimatronic', () {
|
||||
flameTester.test(
|
||||
'loads correctly',
|
||||
(game) async {
|
||||
final dashAnimatronic = DashAnimatronic();
|
||||
await game.ensureAdd(dashAnimatronic);
|
||||
|
||||
expect(game.contains(dashAnimatronic), isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
flameTester.test(
|
||||
'stops animating after animation completes',
|
||||
(game) async {
|
||||
final dashAnimatronic = DashAnimatronic();
|
||||
await game.ensureAdd(dashAnimatronic);
|
||||
|
||||
dashAnimatronic.playing = true;
|
||||
dashAnimatronic.animation?.setToLast();
|
||||
game.update(1);
|
||||
|
||||
expect(dashAnimatronic.playing, isFalse);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|