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,
SpaceshipBridge()..initialPosition = position,
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),
SpaceshipWall()..initialPosition = position,
]);
@ -211,26 +213,20 @@ class SpaceshipEntrance extends RampOpening {
/// A sensor [BodyComponent] responsible for sending the [Ball]
/// back to the board.
/// {@endtemplate}
class SpaceshipHole extends BodyComponent with InitialPosition, Layered {
class SpaceshipHole extends RampOpening {
/// {@macro spaceship_hole}
SpaceshipHole() {
SpaceshipHole({Layer? onExitLayer})
: super(
pathwayLayer: Layer.spaceship,
outsideLayer: onExitLayer,
orientation: RampOrientation.up,
) {
layer = Layer.spaceship;
}
@override
Body createBody() {
renderBody = false;
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,
);
Shape get shape {
return CircleShape()..radius = Spaceship.radius / 40;
}
}
@ -321,6 +317,6 @@ class SpaceshipHoleBallContactCallback
ball
..priority = 1
..gameRef.reorderChildren()
..layer = Layer.board;
..layer = hole.outsideLayer;
}
}

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

Loading…
Cancel
Save