|
|
|
@ -15,6 +15,12 @@ class SpaceshipRamp extends Forge2DBlueprint {
|
|
|
|
|
/// {@macro spaceship_ramp}
|
|
|
|
|
SpaceshipRamp();
|
|
|
|
|
|
|
|
|
|
/// Forwards the sprite to the next [SpaceshipRampArrowSpriteState].
|
|
|
|
|
///
|
|
|
|
|
/// If the current state is the last one it goes back to the initial state.
|
|
|
|
|
void progress() =>
|
|
|
|
|
firstChild<_SpaceshipRampArrowSpriteComponent>()?.progress();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void build(_) {
|
|
|
|
|
addAllContactCallback([
|
|
|
|
@ -23,16 +29,16 @@ class SpaceshipRamp extends Forge2DBlueprint {
|
|
|
|
|
|
|
|
|
|
final rightOpening = _SpaceshipRampOpening(
|
|
|
|
|
outsidePriority: RenderPriority.ballOnBoard,
|
|
|
|
|
rotation: math.pi,
|
|
|
|
|
rotation: -5 * math.pi / 180,
|
|
|
|
|
)
|
|
|
|
|
..initialPosition = Vector2(1.7, -19.8)
|
|
|
|
|
..initialPosition = Vector2(1.7, -20.2)
|
|
|
|
|
..layer = Layer.opening;
|
|
|
|
|
final leftOpening = _SpaceshipRampOpening(
|
|
|
|
|
outsideLayer: Layer.spaceship,
|
|
|
|
|
outsidePriority: RenderPriority.ballOnSpaceship,
|
|
|
|
|
rotation: math.pi,
|
|
|
|
|
rotation: -5 * math.pi / 180,
|
|
|
|
|
)
|
|
|
|
|
..initialPosition = Vector2(-13.7, -18.6)
|
|
|
|
|
..initialPosition = Vector2(-13.7, -19)
|
|
|
|
|
..layer = Layer.spaceshipEntranceRamp;
|
|
|
|
|
|
|
|
|
|
final spaceshipRamp = _SpaceshipRampBackground();
|
|
|
|
@ -59,8 +65,16 @@ class SpaceshipRamp extends Forge2DBlueprint {
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRampBackground extends BodyComponent
|
|
|
|
|
with InitialPosition, Layered {
|
|
|
|
|
_SpaceshipRampBackground() : super(priority: RenderPriority.spaceshipRamp) {
|
|
|
|
|
_SpaceshipRampBackground()
|
|
|
|
|
: super(
|
|
|
|
|
priority: RenderPriority.spaceshipRamp,
|
|
|
|
|
children: [
|
|
|
|
|
_SpaceshipRampBackgroundRampSpriteComponent(),
|
|
|
|
|
_SpaceshipRampArrowSpriteComponent(),
|
|
|
|
|
],
|
|
|
|
|
) {
|
|
|
|
|
layer = Layer.spaceshipEntranceRamp;
|
|
|
|
|
renderBody = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Width between walls of the ramp.
|
|
|
|
@ -112,14 +126,6 @@ class _SpaceshipRampBackground extends BodyComponent
|
|
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
await super.onLoad();
|
|
|
|
|
renderBody = false;
|
|
|
|
|
|
|
|
|
|
await add(_SpaceshipRampBackgroundRampSpriteComponent());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
|
|
|
|
@ -150,7 +156,80 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
|
|
|
|
|
this.sprite = sprite;
|
|
|
|
|
size = sprite.originalSize / 10;
|
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
position = Vector2(-11.7, -53.6);
|
|
|
|
|
position = Vector2(-10.7, -53.6);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Indicates the [SpaceshipRamp]'s arrow dashes current sprite state.
|
|
|
|
|
enum SpaceshipRampArrowSpriteState {
|
|
|
|
|
/// None dash lit up.
|
|
|
|
|
inactive,
|
|
|
|
|
|
|
|
|
|
/// Only 1 dash lit up.
|
|
|
|
|
active1,
|
|
|
|
|
|
|
|
|
|
/// Only 2 dashes lit up.
|
|
|
|
|
active2,
|
|
|
|
|
|
|
|
|
|
/// Only 3 dashes lit up.
|
|
|
|
|
active3,
|
|
|
|
|
|
|
|
|
|
/// Only 4 dashes lit up.
|
|
|
|
|
active4,
|
|
|
|
|
|
|
|
|
|
/// All arrow dashes lit up.
|
|
|
|
|
active5,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Helps obtaining the arrow asset corresponding to each enum
|
|
|
|
|
/// [SpaceshipRampArrowSpriteState].
|
|
|
|
|
extension SpaceshipRampArrowSpriteStateX on SpaceshipRampArrowSpriteState {
|
|
|
|
|
/// Gives path to the arrow asset, depending on its enum.
|
|
|
|
|
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.oneActive.keyName;
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active2:
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.twoActive.keyName;
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active3:
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.threeActive.keyName;
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active4:
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.fourActive.keyName;
|
|
|
|
|
case SpaceshipRampArrowSpriteState.active5:
|
|
|
|
|
return Assets.images.spaceship.ramp.arrow.fiveActive.keyName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Gives next sprite state
|
|
|
|
|
SpaceshipRampArrowSpriteState get next {
|
|
|
|
|
return SpaceshipRampArrowSpriteState
|
|
|
|
|
.values[(index + 1) % SpaceshipRampArrowSpriteState.values.length];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SpaceshipRampArrowSpriteComponent
|
|
|
|
|
extends SpriteGroupComponent<SpaceshipRampArrowSpriteState>
|
|
|
|
|
with HasGameRef {
|
|
|
|
|
_SpaceshipRampArrowSpriteComponent()
|
|
|
|
|
: super(priority: RenderPriority.spaceshipRampBackgroundRailing);
|
|
|
|
|
|
|
|
|
|
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] = await gameRef.loadSprite(spriteState.path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current = SpaceshipRampArrowSpriteState.inactive;
|
|
|
|
|
size = sprites[current]!.originalSize / 10;
|
|
|
|
|
anchor = Anchor.center;
|
|
|
|
|
position = Vector2(-3.9, -56.5);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|