refactor: placed drop ramp below spaceship, fixed position and layers

pull/79/head
RuiAlonso 4 years ago
parent 87ccdf9aed
commit 1284acfdfb

@ -31,7 +31,9 @@ class Spaceship extends Forge2DBlueprint {
SpaceshipEntrance()..initialPosition = position, SpaceshipEntrance()..initialPosition = position,
SpaceshipBridge()..initialPosition = position, SpaceshipBridge()..initialPosition = position,
SpaceshipBridgeTop()..initialPosition = position + Vector2(0, 5.5), SpaceshipBridgeTop()..initialPosition = position + Vector2(0, 5.5),
SpaceshipHole()..initialPosition = position - Vector2(5, 4), SpaceshipHole(
onExitLayer: Layer.spaceship_drop,
)..initialPosition = position - Vector2(5, 4),
SpaceshipHole()..initialPosition = position - Vector2(-5, 4), SpaceshipHole()..initialPosition = position - Vector2(-5, 4),
SpaceshipWall()..initialPosition = position, SpaceshipWall()..initialPosition = position,
]); ]);
@ -211,26 +213,20 @@ class SpaceshipEntrance extends RampOpening {
/// A sensor [BodyComponent] responsible for sending the [Ball] /// A sensor [BodyComponent] responsible for sending the [Ball]
/// back to the board. /// back to the board.
/// {@endtemplate} /// {@endtemplate}
class SpaceshipHole extends BodyComponent with InitialPosition, Layered { class SpaceshipHole extends RampOpening {
/// {@macro spaceship_hole} /// {@macro spaceship_hole}
SpaceshipHole() { SpaceshipHole({Layer? onExitLayer})
: super(
pathwayLayer: Layer.spaceship,
outsideLayer: onExitLayer,
orientation: RampOrientation.up,
) {
layer = Layer.spaceship; layer = Layer.spaceship;
} }
@override @override
Body createBody() { Shape get shape {
renderBody = false; return CircleShape()..radius = Spaceship.radius / 40;
final circleShape = CircleShape()..radius = Spaceship.radius / 40;
final bodyDef = BodyDef()
..userData = this
..position = initialPosition
..type = BodyType.static;
return world.createBody(bodyDef)
..createFixture(
FixtureDef(circleShape)..isSensor = true,
);
} }
} }
@ -321,6 +317,6 @@ class SpaceshipHoleBallContactCallback
ball ball
..priority = 1 ..priority = 1
..gameRef.reorderChildren() ..gameRef.reorderChildren()
..layer = Layer.board; ..layer = hole.outsideLayer;
} }
} }

@ -10,18 +10,17 @@ class SpaceshipDropRamp extends Forge2DBlueprint {
@override @override
void build() { void build() {
final position = Vector2( final position = Vector2(
PinballGame.boardBounds.left + 23, PinballGame.boardBounds.left + 22,
PinballGame.boardBounds.center.dy + 25, PinballGame.boardBounds.center.dy + 27,
); );
addAllContactCallback([ addAllContactCallback([
SpaceshipHoleBallContactCallback(), SpaceshipDropHoleBallContactCallback(),
SpaceshipEntranceBallContactCallback(),
]); ]);
final curvedPath = Pathway.bezierCurve( final curvedPath = Pathway.bezierCurve(
color: Color.fromARGB(255, 226, 226, 218), color: const Color.fromARGB(255, 226, 226, 218),
width: 5, width: 4,
rotation: 230 * math.pi / 180, rotation: 230 * math.pi / 180,
controlPoints: [ controlPoints: [
Vector2(0, 0), Vector2(0, 0),
@ -31,42 +30,67 @@ class SpaceshipDropRamp extends Forge2DBlueprint {
], ],
)..layer = Layer.spaceship_drop; )..layer = Layer.spaceship_drop;
final curvedEntrance = Pathway.arc(
color: const Color.fromARGB(255, 226, 226, 218),
center: position,
radius: 4,
angle: math.pi / 2,
width: 5,
rotation: 218 * math.pi / 180,
singleWall: true,
)..layer = Layer.spaceship_drop;
final curvedExit = Pathway.arc(
color: const Color.fromARGB(255, 226, 226, 218),
center: position,
radius: 4,
angle: math.pi / 2,
width: 5,
rotation: 36 * math.pi / 180,
singleWall: true,
)..layer = Layer.spaceship_drop;
addAll([ addAll([
curvedPath..initialPosition = position, curvedPath..initialPosition = position,
curvedEntrance..initialPosition = position + Vector2(26.5, -30),
curvedExit..initialPosition = position + Vector2(29, -66.5),
SpaceshipDropHole()..initialPosition = position + Vector2(0, -42),
]); ]);
} }
} }
class SpaceshipRampEntrance extends RampOpening { /// {@template spaceship_drop_hole}
/// {@macro spaceship_ramp_entrance} /// A sensor [BodyComponent] responsible for sending the [Ball]
SpaceshipRampEntrance() /// back to the board.
/// {@endtemplate}
class SpaceshipDropHole extends RampOpening {
/// {@macro spaceship_drop_hole}
SpaceshipDropHole()
: super( : super(
pathwayLayer: Layer.spaceship_drop, pathwayLayer: Layer.spaceship_drop,
orientation: RampOrientation.up, orientation: RampOrientation.down,
) { ) {
layer = Layer.spaceship_drop; layer = Layer.spaceship_drop;
} }
@override @override
Shape get shape { Shape get shape {
const radius = Spaceship.radius * 2; return CircleShape()..radius = Spaceship.radius / 40;
return PolygonShape();
} }
} }
class SpaceshipRampExit extends RampOpening { /// [ContactCallback] that handles the contact between the [Ball]
/// {@macro spaceship_ramp_entrance} /// and a [SpaceshipDropHole].
SpaceshipRampExit() ///
: super( /// It resets the [Ball] priority and filter data so it will "be back" on the
pathwayLayer: Layer.spaceship_drop, /// board.
orientation: RampOrientation.down, class SpaceshipDropHoleBallContactCallback
) { extends ContactCallback<SpaceshipDropHole, Ball> {
layer = Layer.spaceship_drop;
}
@override @override
Shape get shape { void begin(SpaceshipDropHole hole, Ball ball, _) {
const radius = Spaceship.radius * 2; ball
return PolygonShape(); ..priority = 1
..gameRef.reorderChildren()
..layer = hole.outsideLayer;
} }
} }

Loading…
Cancel
Save