refactor: changed spaceship ramp logic

feat/spaceship-ramp-logic
RuiAlonso 3 years ago
parent 7349d04217
commit 86cecb6b40

@ -20,8 +20,6 @@ class ControlledSpaceshipRamp extends Component
controller = SpaceshipRampController(this);
}
// TODO(ruimiguel): check Blueprint contact callbacks bug and then change
// this class to extends from SpaceshipRamp.
late final SpaceshipRamp _spaceshipRamp;
@override
@ -53,7 +51,6 @@ class SpaceshipRampController
: super(controlledSpaceshipRamp);
final int _oneMillionPointsTarget = 10;
final int _scoreMultiplierTarget = 6;
int _hitsCounter = 0;
@ -62,15 +59,13 @@ class SpaceshipRampController
component._spaceshipRamp.progress();
// TODO(ruimiguel): increase score multiplier x1 .
print('Multiplier x1');
gameRef.read<GameBloc>().add(const Scored(points: 100));
// TODO(ruimiguel): Ramp shot
gameRef.read<GameBloc>().add(const Scored(points: 5000));
// TODO(ruimiguel): increase score multiplier at GameBloc.
if (_hitsCounter % _scoreMultiplierTarget == 0) {
// TODO(ruimiguel): reset score multiplier and multiply score x6 .
print('Reset multiplier and multiply score x6');
}
if (_hitsCounter % _oneMillionPointsTarget == 0) {
// TODO(ruimiguel): One million by bonus??
const oneMillion = 1000000;
gameRef.read<GameBloc>().add(const Scored(points: oneMillion));
gameRef.add(
@ -83,6 +78,47 @@ class SpaceshipRampController
}
}
enum SpaceshipRampSensorType {
door,
inside,
}
/// {@template spaceship_ramp_sensor}
/// Small sensor body used to detect when a ball has entered the
/// [SpaceshipRamp].
/// {@endtemplate}
class SpaceshipRampSensor extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_ramp_sensor}
SpaceshipRampSensor({required this.type}) : super() {
layer = Layer.spaceshipEntranceRamp;
renderBody = false;
}
final SpaceshipRampSensorType type;
@override
Body createBody() {
final shape = PolygonShape()
..setAsBox(
2,
2,
initialPosition,
-5 * math.pi / 180,
);
final fixtureDef = FixtureDef(
shape,
isSensor: true,
);
final bodyDef = BodyDef(
position: initialPosition,
userData: this,
);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}
/// {@template spaceship_ramp_sensor_ball_contact_callback}
/// Turbo charges the [Ball] on contact with [SpaceshipRampSensor].
/// {@endtemplate}

@ -382,46 +382,3 @@ class _SpaceshipRampOpening extends LayerSensor {
);
}
}
enum SpaceshipRampSensorType {
door,
inside,
}
/// {@template spaceship_ramp_opening}
/// [LayerSensor] with [Layer.spaceshipEntranceRamp] to filter [Ball] collisions
/// inside [_SpaceshipRampBackground].
/// {@endtemplate}
class SpaceshipRampSensor extends BodyComponent with InitialPosition, Layered {
/// {@macro spaceship_ramp_opening}
SpaceshipRampSensor({required this.type}) : super() {
layer = Layer.spaceshipEntranceRamp;
renderBody = false;
}
final SpaceshipRampSensorType type;
static final Vector2 _size = Vector2(_SpaceshipRampBackground.width / 3, .1);
@override
Body createBody() {
final shape = PolygonShape()
..setAsBox(
_size.x,
_size.y,
initialPosition,
-5 * math.pi / 180,
);
final fixtureDef = FixtureDef(
shape,
isSensor: true,
);
final bodyDef = BodyDef(
position: initialPosition,
userData: this,
);
return world.createBody(bodyDef)..createFixture(fixtureDef);
}
}

Loading…
Cancel
Save