@ -1,63 +1,66 @@
/ / ignore_for_file: public_member_api_docs, avoid_renaming_method_parameters
/ / ignore_for_file: avoid_renaming_method_parameters, comment_references
import ' dart:math ' as math ;
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:pinball/game/game.dart ' ;
import ' package:pinball_components/gen/assets.gen.dart ' ;
import ' package:pinball/gen/assets.gen.dart ' ;
import ' package:pinball_components/pinball_components.dart ' hide Assets ;
import ' package:pinball_components/pinball_components.dart ' hide Assets ;
/ / / A [ Blueprint ] which creates the [ JetpackRamp ] .
/ / / { @ template spaceship_ramp }
class Jetpack extends Forge2DBlueprint {
/ / / A [ Blueprint ] which creates the [ _SpaceshipRampBackground ] .
/ / / { @ macro spaceship }
/ / / { @ endtemplate }
Jetpack ( ) ;
class SpaceshipRamp extends Forge2DBlueprint {
/ / / { @ macro spaceship_ramp }
SpaceshipRamp ( ) ;
/ / / Base priority for wall while be in the ramp .
static const int ballPriorityInsideRamp = 4 ;
static const int ballPriorityInsideRamp = 4 ;
@ override
@ override
void build ( _ ) {
void build ( _ ) {
addAllContactCallback ( [
addAllContactCallback ( [
RampOpeningBallContactCallback < _ Jetpack RampOpening> ( ) ,
RampOpeningBallContactCallback < _ Spaceship RampOpening> ( ) ,
] ) ;
] ) ;
final rightOpening = _ Jetpack RampOpening(
final rightOpening = _ Spaceship RampOpening(
/ / TODO ( ruimiguel ) : set Board priority when defined .
/ / TODO ( ruimiguel ) : set Board priority when defined .
outsidePriority: 1 ,
outsidePriority: 1 ,
rotation: math . pi ,
rotation: math . pi ,
)
)
. . initialPosition = Vector2 ( 1.7 , 19 )
. . initialPosition = Vector2 ( 1.7 , 19 )
. . layer = Layer . opening ;
. . layer = Layer . opening ;
final leftOpening = _ Jetpack RampOpening(
final leftOpening = _ Spaceship RampOpening(
outsideLayer: Layer . spaceship ,
outsideLayer: Layer . spaceship ,
outsidePriority: Spaceship . ballPriorityWhenOnSpaceship ,
outsidePriority: Spaceship . ballPriorityWhenOnSpaceship ,
rotation: math . pi ,
rotation: math . pi ,
)
)
. . initialPosition = Vector2 ( - 13.7 , 19 )
. . initialPosition = Vector2 ( - 13.7 , 19 )
. . layer = Layer . jetpack ;
. . layer = Layer . spaceshipEntranceRamp ;
final jetpackRamp = JetpackRamp ( ) ;
final spaceshipRamp = _SpaceshipRampBackground ( ) ;
final jetpackRampWallFg = _Jetpack RampForegroundRailing( ) ;
final spaceshipRampForegroundRailing = _Spaceship RampForegroundRailing( ) ;
final baseRight = _ Jetpack Base( ) . . initialPosition = Vector2 ( 1.7 , 20 ) ;
final baseRight = _ SpaceshipRamp Base( ) . . initialPosition = Vector2 ( 1.7 , 20 ) ;
addAll ( [
addAll ( [
rightOpening ,
rightOpening ,
leftOpening ,
leftOpening ,
baseRight ,
baseRight ,
jetpack Ramp,
spaceship Ramp,
jetpackRampWallF g,
spaceshipRampForegroundRailin g,
] ) ;
] ) ;
}
}
}
}
/ / / { @ template jetpack_ramp }
/ / / Represents the upper left blue ramp of the [ Board ] with its background
/ / / Represents the upper left blue ramp of the [ Board ] .
/ / / railing .
/ / / { @ endtemplate }
class _SpaceshipRampBackground extends BodyComponent
class JetpackRamp extends BodyComponent with InitialPosition , Layered {
with InitialPosition , Layered {
JetpackRamp ( ) : super ( priority: Jetpack . ballPriorityInsideRamp - 1 ) {
_SpaceshipRampBackground ( )
layer = Layer . jetpack ;
: super ( priority: SpaceshipRamp . ballPriorityInsideRamp - 1 ) {
layer = Layer . spaceshipEntranceRamp ;
}
}
/ / / Width between walls of the ramp .
/ / / Width between walls of the ramp .
@ -113,7 +116,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
Future < void > _loadSprites ( ) async {
Future < void > _loadSprites ( ) async {
final spriteRamp = await gameRef . loadSprite (
final spriteRamp = await gameRef . loadSprite (
Assets . images . components. spaceshipRamp . path ,
Assets . images . spaceshipRamp. spaceshipRamp . keyName ,
) ;
) ;
final spriteRampComponent = SpriteComponent (
final spriteRampComponent = SpriteComponent (
@ -124,7 +127,7 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
) ;
) ;
final spriteRailingBg = await gameRef . loadSprite (
final spriteRailingBg = await gameRef . loadSprite (
Assets . images . components. spaceshipRailingBg . path ,
Assets . images . spaceshipRamp. spaceshipRailingBg . keyName ,
) ;
) ;
final spriteRailingBgComponent = SpriteComponent (
final spriteRailingBgComponent = SpriteComponent (
sprite: spriteRailingBg ,
sprite: spriteRailingBg ,
@ -140,11 +143,12 @@ class JetpackRamp extends BodyComponent with InitialPosition, Layered {
}
}
}
}
class _JetpackRampForegroundRailing extends BodyComponent
/ / / Represents the foreground of the railing upper left blue ramp .
class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition , Layered {
with InitialPosition , Layered {
_ Jetpack RampForegroundRailing( )
_ Spaceship RampForegroundRailing( )
: super ( priority: Jetpack . ballPriorityInsideRamp + 1 ) {
: super ( priority: SpaceshipRamp . ballPriorityInsideRamp + 1 ) {
layer = Layer . jetpack ;
layer = Layer . spaceshipEntranceRamp ;
}
}
List < FixtureDef > _createFixtureDefs ( ) {
List < FixtureDef > _createFixtureDefs ( ) {
@ -197,7 +201,7 @@ class _JetpackRampForegroundRailing extends BodyComponent
Future < void > _loadSprites ( ) async {
Future < void > _loadSprites ( ) async {
final spriteRailingFg = await gameRef . loadSprite (
final spriteRailingFg = await gameRef . loadSprite (
Assets . images . components. spaceshipRailingFg . path ,
Assets . images . spaceshipRamp. spaceshipRailingFg . keyName ,
) ;
) ;
final spriteRailingFgComponent = SpriteComponent (
final spriteRailingFgComponent = SpriteComponent (
sprite: spriteRailingFg ,
sprite: spriteRailingFg ,
@ -210,8 +214,9 @@ class _JetpackRampForegroundRailing extends BodyComponent
}
}
}
}
class _JetpackBase extends BodyComponent with InitialPosition , Layered {
/ / / Represents the ground right base of the [ SpaceshipRamp ] .
_JetpackBase ( ) {
class _SpaceshipRampBase extends BodyComponent with InitialPosition , Layered {
_SpaceshipRampBase ( ) {
layer = Layer . board ;
layer = Layer . board ;
}
}
@ -240,28 +245,28 @@ class _JetpackBase extends BodyComponent with InitialPosition, Layered {
}
}
}
}
/ / / { @ template jetpack _ramp_opening}
/ / / { @ template spaceship _ramp_opening}
/ / / [ RampOpening ] with [ Layer . jetpack ] to filter [ Ball ] collisions
/ / / [ RampOpening ] with [ Layer . spaceshipEntranceRamp ] to filter [ Ball ] collisions
/ / / inside [ JetpackRamp ] .
/ / / inside [ _SpaceshipRampBackground ] .
/ / / { @ endtemplate }
/ / / { @ endtemplate }
class _ Jetpack RampOpening extends RampOpening {
class _ Spaceship RampOpening extends RampOpening {
/ / / { @ macro jetpack _ramp_opening}
/ / / { @ macro spaceship _ramp_opening}
_ Jetpack RampOpening( {
_ Spaceship RampOpening( {
Layer ? outsideLayer ,
Layer ? outsideLayer ,
int ? outsidePriority ,
int ? outsidePriority ,
required double rotation ,
required double rotation ,
} ) : _rotation = rotation ,
} ) : _rotation = rotation ,
super (
super (
insideLayer: Layer . jetpack ,
insideLayer: Layer . spaceshipEntranceRamp ,
outsideLayer: outsideLayer ,
outsideLayer: outsideLayer ,
orientation: RampOrientation . down ,
orientation: RampOrientation . down ,
insidePriority: Jetpack . ballPriorityInsideRamp ,
insidePriority: SpaceshipRamp . ballPriorityInsideRamp ,
outsidePriority: outsidePriority ,
outsidePriority: outsidePriority ,
) ;
) ;
final double _rotation ;
final double _rotation ;
static final Vector2 _size = Vector2 ( JetpackRamp . width / 4 , . 1 ) ;
static final Vector2 _size = Vector2 ( _SpaceshipRampBackground . width / 4 , . 1 ) ;
@ override
@ override
Shape get shape {
Shape get shape {