@ -1,4 +1,4 @@
/ / ignore_for_file: avoid_renaming_method_parameters , comment_references
/ / ignore_for_file: avoid_renaming_method_parameters
import ' dart:math ' as math ;
import ' dart:math ' as math ;
@ -8,13 +8,13 @@ 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 ;
/ / / { @ template spaceship_ramp }
/ / / { @ template spaceship_ramp }
/ / / A [ Blueprint ] which creates the [ _ SpaceshipRampBackground ] .
/ / / A [ Blueprint ] which creates the ramp leading into the [ Spaceship] .
/ / / { @ endtemplate }
/ / / { @ endtemplate }
class SpaceshipRamp extends Forge2DBlueprint {
class SpaceshipRamp extends Forge2DBlueprint {
/ / / { @ macro spaceship_ramp }
/ / / { @ macro spaceship_ramp }
SpaceshipRamp ( ) ;
SpaceshipRamp ( ) ;
/ / / Base priority for wall while be in the ramp .
/ / / Base priority for the [ Ball ] while inside the ramp .
static const int ballPriorityInsideRamp = 4 ;
static const int ballPriorityInsideRamp = 4 ;
@ override
@ override
@ -28,23 +28,28 @@ class SpaceshipRamp extends Forge2DBlueprint {
outsidePriority: 1 ,
outsidePriority: 1 ,
rotation: math . pi ,
rotation: math . pi ,
)
)
. . initialPosition = Vector2 ( 1.7 , 19 )
. . initialPosition = Vector2 ( 1.7 , 19 .8 )
. . layer = Layer . opening ;
. . layer = Layer . opening ;
final leftOpening = _SpaceshipRampOpening (
final leftOpening = _SpaceshipRampOpening (
outsideLayer: Layer . spaceship ,
outsideLayer: Layer . spaceship ,
outsidePriority: Spaceship . ballPriorityWhenOnSpaceship ,
outsidePriority: Spaceship . ballPriorityWhenOnSpaceship ,
rotation: math . pi ,
rotation: math . pi ,
)
)
. . initialPosition = Vector2 ( - 13.7 , 1 9 )
. . initialPosition = Vector2 ( - 13.7 , 1 8.6 )
. . layer = Layer . spaceshipEntranceRamp ;
. . layer = Layer . spaceshipEntranceRamp ;
final spaceshipRamp = _SpaceshipRampBackground ( ) ;
final spaceshipRamp = _SpaceshipRampBackground ( ) ;
final spaceshipRampBoardOpeningSprite =
_SpaceshipRampBoardOpeningSpriteComponent ( )
. . position = Vector2 ( 3.4 , - 39.5 ) ;
final spaceshipRampForegroundRailing = _SpaceshipRampForegroundRailing ( ) ;
final spaceshipRampForegroundRailing = _SpaceshipRampForegroundRailing ( ) ;
final baseRight = _SpaceshipRampBase ( ) . . initialPosition = Vector2 ( 1.7 , 20 ) ;
final baseRight = _SpaceshipRampBase ( ) . . initialPosition = Vector2 ( 1.7 , 20 ) ;
addAll ( [
addAll ( [
spaceshipRampBoardOpeningSprite ,
rightOpening ,
rightOpening ,
leftOpening ,
leftOpening ,
baseRight ,
baseRight ,
@ -54,8 +59,6 @@ class SpaceshipRamp extends Forge2DBlueprint {
}
}
}
}
/ / / Represents the upper left blue ramp of the [ Board ] with its background
/ / / railing .
class _SpaceshipRampBackground extends BodyComponent
class _SpaceshipRampBackground extends BodyComponent
with InitialPosition , Layered {
with InitialPosition , Layered {
_SpaceshipRampBackground ( )
_SpaceshipRampBackground ( )
@ -71,7 +74,7 @@ class _SpaceshipRampBackground extends BodyComponent
final outerLeftCurveShape = BezierCurveShape (
final outerLeftCurveShape = BezierCurveShape (
controlPoints: [
controlPoints: [
Vector2 ( - 30. 95, 38 ) ,
Vector2 ( - 30. 75, 37.3 ) ,
Vector2 ( - 32.5 , 71.25 ) ,
Vector2 ( - 32.5 , 71.25 ) ,
Vector2 ( - 14.2 , 71.25 ) ,
Vector2 ( - 14.2 , 71.25 ) ,
] ,
] ,
@ -83,14 +86,22 @@ class _SpaceshipRampBackground extends BodyComponent
final outerRightCurveShape = BezierCurveShape (
final outerRightCurveShape = BezierCurveShape (
controlPoints: [
controlPoints: [
outerLeftCurveShape . vertices . last ,
outerLeftCurveShape . vertices . last ,
Vector2 ( 4.7, 71.25 ) ,
Vector2 ( 2.5, 71.9 ) ,
Vector2 ( 6. 3, 40 ) ,
Vector2 ( 6. 1, 44.9 ) ,
] ,
] ,
) ;
) ;
final outerRightCurveFixtureDef = FixtureDef ( outerRightCurveShape ) ;
final outerRightCurveFixtureDef = FixtureDef ( outerRightCurveShape ) ;
fixturesDef . add ( outerRightCurveFixtureDef ) ;
fixturesDef . add ( outerRightCurveFixtureDef ) ;
final boardOpeningEdgeShape = EdgeShape ( )
. . set (
outerRightCurveShape . vertices . last ,
Vector2 ( 7.3 , 41.1 ) ,
) ;
final boardOpeningEdgeShapeFixtureDef = FixtureDef ( boardOpeningEdgeShape ) ;
fixturesDef . add ( boardOpeningEdgeShapeFixtureDef ) ;
return fixturesDef ;
return fixturesDef ;
}
}
@ -111,8 +122,8 @@ class _SpaceshipRampBackground extends BodyComponent
await super . onLoad ( ) ;
await super . onLoad ( ) ;
renderBody = false ;
renderBody = false ;
await add ( _SpaceshipRampBackgroundRailingSpriteComponent ( ) ) ;
await add ( _SpaceshipRampBackgroundRampSpriteComponent ( ) ) ;
await add ( _SpaceshipRampBackgroundRampSpriteComponent ( ) ) ;
await add ( _SpaceshipRampBackgroundRailingSpriteComponent ( ) ) ;
}
}
}
}
@ -125,9 +136,9 @@ class _SpaceshipRampBackgroundRailingSpriteComponent extends SpriteComponent
Assets . images . spaceship . ramp . railingBackground . keyName ,
Assets . images . spaceship . ramp . railingBackground . keyName ,
) ;
) ;
this . sprite = sprite ;
this . sprite = sprite ;
size = Vector2( 38.3 , 35.1 ) ;
size = sprite. originalSize / 10 ;
anchor = Anchor . center ;
anchor = Anchor . center ;
position = Vector2 ( - 1 2.2, - 54.5 ) ;
position = Vector2 ( - 1 1.7, - 54.3 ) ;
}
}
}
}
@ -142,11 +153,24 @@ class _SpaceshipRampBackgroundRampSpriteComponent extends SpriteComponent
this . sprite = sprite ;
this . sprite = sprite ;
size = sprite . originalSize / 10 ;
size = sprite . originalSize / 10 ;
anchor = Anchor . center ;
anchor = Anchor . center ;
position = Vector2 ( - 12.2 , - 53.5 ) ;
position = Vector2 ( - 11.7 , - 53.6 ) ;
}
}
class _SpaceshipRampBoardOpeningSpriteComponent extends SpriteComponent
with HasGameRef {
@ override
Future < void > onLoad ( ) async {
await super . onLoad ( ) ;
final sprite = await gameRef . loadSprite (
Assets . images . spaceship . ramp . boardOpening . keyName ,
) ;
this . sprite = sprite ;
size = sprite . originalSize / 10 ;
anchor = Anchor . center ;
}
}
}
}
/ / / Represents the foreground of the railing upper left blue ramp .
class _SpaceshipRampForegroundRailing extends BodyComponent
class _SpaceshipRampForegroundRailing extends BodyComponent
with InitialPosition , Layered {
with InitialPosition , Layered {
_SpaceshipRampForegroundRailing ( )
_SpaceshipRampForegroundRailing ( )
@ -171,14 +195,22 @@ class _SpaceshipRampForegroundRailing extends BodyComponent
final innerRightCurveShape = BezierCurveShape (
final innerRightCurveShape = BezierCurveShape (
controlPoints: [
controlPoints: [
innerLeftCurveShape . vertices . last ,
innerLeftCurveShape . vertices . last ,
Vector2 ( - 1, 64.5 ) ,
Vector2 ( - 2.5, 66.2 ) ,
Vector2 ( 0 .1, 39 .5) ,
Vector2 ( 0 , 44 .5) ,
] ,
] ,
) ;
) ;
final innerRightCurveFixtureDef = FixtureDef ( innerRightCurveShape ) ;
final innerRightCurveFixtureDef = FixtureDef ( innerRightCurveShape ) ;
fixturesDef . add ( innerRightCurveFixtureDef ) ;
fixturesDef . add ( innerRightCurveFixtureDef ) ;
final boardOpeningEdgeShape = EdgeShape ( )
. . set (
innerRightCurveShape . vertices . last ,
Vector2 ( - 0.85 , 40.8 ) ,
) ;
final boardOpeningEdgeShapeFixtureDef = FixtureDef ( boardOpeningEdgeShape ) ;
fixturesDef . add ( boardOpeningEdgeShapeFixtureDef ) ;
return fixturesDef ;
return fixturesDef ;
}
}
@ -212,13 +244,12 @@ class _SpaceshipRampForegroundRailingSpriteComponent extends SpriteComponent
Assets . images . spaceship . ramp . railingForeground . keyName ,
Assets . images . spaceship . ramp . railingForeground . keyName ,
) ;
) ;
this . sprite = sprite ;
this . sprite = sprite ;
size = Vector2( 26.1 , 28.3 ) ;
size = sprite. originalSize / 10 ;
anchor = Anchor . center ;
anchor = Anchor . center ;
position = Vector2 ( - 12. 2 , - 52.5 ) ;
position = Vector2 ( - 12. 3 , - 52.5 ) ;
}
}
}
}
/ / / Represents the ground right base of the [ SpaceshipRamp ] .
class _SpaceshipRampBase extends BodyComponent with InitialPosition , Layered {
class _SpaceshipRampBase extends BodyComponent with InitialPosition , Layered {
_SpaceshipRampBase ( ) {
_SpaceshipRampBase ( ) {
renderBody = false ;
renderBody = false ;
@ -227,14 +258,14 @@ class _SpaceshipRampBase extends BodyComponent with InitialPosition, Layered {
@ override
@ override
Body createBody ( ) {
Body createBody ( ) {
const baseWidth = 6 ;
const baseWidth = 9 ;
final baseShape = BezierCurveShape (
final baseShape = BezierCurveShape (
controlPoints: [
controlPoints: [
Vector2 ( initialPosition . x - baseWidth / 2 , initialPosition . y ) ,
Vector2 ( initialPosition . x - baseWidth / 2 , initialPosition . y ) ,
Vector2 ( initialPosition . x - baseWidth / 2 , initialPosition . y ) +
Vector2 ( initialPosition . x - baseWidth / 2 , initialPosition . y ) +
Vector2 ( 2 , 2 ) ,
Vector2 ( 2 , 5 ) ,
Vector2 ( initialPosition . x + baseWidth / 2 , initialPosition . y ) +
Vector2 ( initialPosition . x + baseWidth / 2 , initialPosition . y ) +
Vector2 ( - 2 , 2 ) ,
Vector2 ( - 2 , 5 ) ,
Vector2 ( initialPosition . x + baseWidth / 2 , initialPosition . y )
Vector2 ( initialPosition . x + baseWidth / 2 , initialPosition . y )
] ,
] ,
) ;
) ;
@ -271,7 +302,7 @@ class _SpaceshipRampOpening extends RampOpening {
final double _rotation ;
final double _rotation ;
static final Vector2 _size = Vector2 ( _SpaceshipRampBackground . width / 4 , . 1 ) ;
static final Vector2 _size = Vector2 ( _SpaceshipRampBackground . width / 3 , . 1 ) ;
@ override
@ override
Shape get shape {
Shape get shape {