|
|
@ -2,6 +2,7 @@ import 'dart:math' as math;
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pinball_components/gen/assets.gen.dart';
|
|
|
|
import 'package:pinball_components/gen/assets.gen.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart' hide Assets;
|
|
|
|
import 'package:pinball_components/pinball_components.dart' hide Assets;
|
|
|
|
import 'package:pinball_flame/pinball_flame.dart';
|
|
|
|
import 'package:pinball_flame/pinball_flame.dart';
|
|
|
@ -33,8 +34,60 @@ class SpaceshipRamp extends Blueprint {
|
|
|
|
_SpaceshipRampForegroundRailing(),
|
|
|
|
_SpaceshipRampForegroundRailing(),
|
|
|
|
_SpaceshipRampBase()..initialPosition = Vector2(1.7, -20),
|
|
|
|
_SpaceshipRampBase()..initialPosition = Vector2(1.7, -20),
|
|
|
|
_SpaceshipRampBackgroundRailingSpriteComponent(),
|
|
|
|
_SpaceshipRampBackgroundRailingSpriteComponent(),
|
|
|
|
|
|
|
|
SpaceshipRampArrowSpriteComponent(),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Forwards the sprite to the next [SpaceshipRampArrowSpriteState].
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// If the current state is the last one it cycles back to the initial state.
|
|
|
|
|
|
|
|
void progress() => children.firstChild<SpaceshipRampArrowSpriteComponent>()?.progress();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Indicates the state of the arrow on the [SpaceshipRamp].
|
|
|
|
|
|
|
|
@visibleForTesting
|
|
|
|
|
|
|
|
enum SpaceshipRampArrowSpriteState {
|
|
|
|
|
|
|
|
/// Arrow with no dashes lit up.
|
|
|
|
|
|
|
|
inactive,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Arrow with 1 light lit up.
|
|
|
|
|
|
|
|
active1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Arrow with 2 lights lit up.
|
|
|
|
|
|
|
|
active2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Arrow with 3 lights lit up.
|
|
|
|
|
|
|
|
active3,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Arrow with 4 lights lit up.
|
|
|
|
|
|
|
|
active4,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Arrow with all 5 lights lit up.
|
|
|
|
|
|
|
|
active5,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extension on SpaceshipRampArrowSpriteState {
|
|
|
|
|
|
|
|
String get path {
|
|
|
|
|
|
|
|
switch (this) {
|
|
|
|
|
|
|
|
case SpaceshipRampArrowSpriteState.inactive:
|
|
|
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.inactive.keyName;
|
|
|
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active1:
|
|
|
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.active1.keyName;
|
|
|
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active2:
|
|
|
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.active2.keyName;
|
|
|
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active3:
|
|
|
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.active3.keyName;
|
|
|
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active4:
|
|
|
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.active4.keyName;
|
|
|
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active5:
|
|
|
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.active5.keyName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SpaceshipRampArrowSpriteState get next {
|
|
|
|
|
|
|
|
return SpaceshipRampArrowSpriteState
|
|
|
|
|
|
|
|
.values[(index + 1) % SpaceshipRampArrowSpriteState.values.length];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRampBackground extends BodyComponent
|
|
|
|
class _SpaceshipRampBackground extends BodyComponent
|
|
|
@ -113,19 +166,21 @@ class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
|
|
|
|
with HasGameRef {
|
|
|
|
with HasGameRef {
|
|
|
|
_SpaceshipRampBackgroundRailingSpriteComponent()
|
|
|
|
_SpaceshipRampBackgroundRailingSpriteComponent()
|
|
|
|
: super(
|
|
|
|
: super(
|
|
|
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
|
|
|
position: Vector2(-11.7, -54.3),
|
|
|
|
priority: RenderPriority.spaceshipRampBackgroundRailing,
|
|
|
|
priority: RenderPriority.spaceshipRampBackgroundRailing,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
final sprite = await gameRef.loadSprite(
|
|
|
|
final sprite = Sprite(
|
|
|
|
|
|
|
|
gameRef.images.fromCache(
|
|
|
|
Assets.images.spaceship.ramp.railingBackground.keyName,
|
|
|
|
Assets.images.spaceship.ramp.railingBackground.keyName,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
this.sprite = sprite;
|
|
|
|
this.sprite = sprite;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
|
|
|
position = Vector2(-11.7, -54.3);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -134,13 +189,50 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
final sprite = await gameRef.loadSprite(
|
|
|
|
final sprite = Sprite(
|
|
|
|
|
|
|
|
gameRef.images.fromCache(
|
|
|
|
Assets.images.spaceship.ramp.main.keyName,
|
|
|
|
Assets.images.spaceship.ramp.main.keyName,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
this.sprite = sprite;
|
|
|
|
this.sprite = sprite;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
anchor = Anchor.center;
|
|
|
|
anchor = Anchor.center;
|
|
|
|
position = Vector2(-11.7, -53.6);
|
|
|
|
position = Vector2(-10.7, -53.6);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// {@template spaceship_ramp_arrow_sprite_component}
|
|
|
|
|
|
|
|
/// An arrow inside [SpaceshipRamp].
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Lights up a each dash whenever a [Ball] gets into [SpaceshipRamp].
|
|
|
|
|
|
|
|
/// {@endtemplate}
|
|
|
|
|
|
|
|
class SpaceshipRampArrowSpriteComponent
|
|
|
|
|
|
|
|
extends SpriteGroupComponent<SpaceshipRampArrowSpriteState>
|
|
|
|
|
|
|
|
with HasGameRef {
|
|
|
|
|
|
|
|
/// {@macro spaceship_ramp_arrow_sprite_component}
|
|
|
|
|
|
|
|
SpaceshipRampArrowSpriteComponent()
|
|
|
|
|
|
|
|
: super(
|
|
|
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
|
|
|
position: Vector2(-3.9, -56.5),
|
|
|
|
|
|
|
|
priority: RenderPriority.spaceshipRampArrow,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Changes arrow image to the next [Sprite].
|
|
|
|
|
|
|
|
void progress() => current = current?.next;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
|
|
|
final sprites = <SpaceshipRampArrowSpriteState, Sprite>{};
|
|
|
|
|
|
|
|
this.sprites = sprites;
|
|
|
|
|
|
|
|
for (final spriteState in SpaceshipRampArrowSpriteState.values) {
|
|
|
|
|
|
|
|
sprites[spriteState] = Sprite(
|
|
|
|
|
|
|
|
gameRef.images.fromCache(spriteState.path),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current = SpaceshipRampArrowSpriteState.inactive;
|
|
|
|
|
|
|
|
size = sprites[current]!.originalSize / 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -149,8 +241,10 @@ class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
final sprite = await gameRef.loadSprite(
|
|
|
|
final sprite = Sprite(
|
|
|
|
|
|
|
|
gameRef.images.fromCache(
|
|
|
|
Assets.images.spaceship.ramp.boardOpening.keyName,
|
|
|
|
Assets.images.spaceship.ramp.boardOpening.keyName,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
this.sprite = sprite;
|
|
|
|
this.sprite = sprite;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
@ -221,16 +315,22 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
|
|
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRampForegroundRailingSpriteComponent extends SpriteComponent
|
|
|
|
class _SpaceshipRampForegroundRailingSpriteComponent extends SpriteComponent
|
|
|
|
with HasGameRef {
|
|
|
|
with HasGameRef {
|
|
|
|
|
|
|
|
_SpaceshipRampForegroundRailingSpriteComponent()
|
|
|
|
|
|
|
|
: super(
|
|
|
|
|
|
|
|
anchor: Anchor.center,
|
|
|
|
|
|
|
|
position: Vector2(-12.3, -52.5),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
await super.onLoad();
|
|
|
|
await super.onLoad();
|
|
|
|
final sprite = await gameRef.loadSprite(
|
|
|
|
final sprite = Sprite(
|
|
|
|
|
|
|
|
gameRef.images.fromCache(
|
|
|
|
Assets.images.spaceship.ramp.railingForeground.keyName,
|
|
|
|
Assets.images.spaceship.ramp.railingForeground.keyName,
|
|
|
|
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
this.sprite = sprite;
|
|
|
|
this.sprite = sprite;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
|
|
|
position = Vector2(-12.3, -52.5);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|