refactor: improving ramp bonus

feat/spaceship-ramp-logic
RuiAlonso 3 years ago
parent 536c34484f
commit 8737139f04

@ -5,7 +5,6 @@ import 'dart:math' as math;
import 'package:flame/components.dart';
import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart';
import 'package:pinball/game/components/components.dart';
import 'package:pinball/game/components/spaceship_ramp/behaviors/behaviors.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_components/pinball_components.dart';

@ -59,7 +59,7 @@ class AndroidRampBonusBehavior extends Component
_balls.remove(ball);
print("removed $_balls");
_previousHits++;
shot(_previousHits);
shot(_previousHits, ball.body.position);
}
}
@ -67,12 +67,18 @@ class AndroidRampBonusBehavior extends Component
/// When a [Ball] shot the [SpaceshipRamp] it achieve improvements for the
/// current game, like multipliers or score.
void shot(int currentHits) {
void shot(int currentHits, Vector2 position) {
parent.spaceshipRamp.progress();
print("SHOT $currentHits");
print("Score $_shotPoints");
gameRef.read<GameBloc>().add(Scored(points: _shotPoints));
gameRef.add(
ScoreText(
text: _shotPoints.toString(),
position: position,
),
);
final multiplier = gameRef.read<GameBloc>().state.multiplier;
gameRef.read<GameBloc>().add(const MultiplierIncreased());
@ -84,7 +90,7 @@ class AndroidRampBonusBehavior extends Component
gameRef.add(
ScoreText(
text: _bonusPoints.toString(),
position: Vector2(1.7, -20),
position: position + Vector2(-2, -5),
),
);
}

@ -1,2 +1,2 @@
export 'ramp_multiplier_bonus_behavior.dart';
export 'android_ramp_bonus_behavior.dart';
export 'ramp_shot_behavior.dart';

@ -19,9 +19,11 @@ class AndroidRampSensorCubit extends Cubit<AndroidRampSensorState> {
}
void onInside(Ball ball) {
emit(state.copyWith(
type: AndroidRampSensorType.inside,
ball: ball,
));
emit(
state.copyWith(
type: AndroidRampSensorType.inside,
ball: ball,
),
);
}
}

@ -11,13 +11,14 @@ enum AndroidRampSensorType {
}
class AndroidRampSensorState extends Equatable {
AndroidRampSensorState({
const AndroidRampSensorState({
required this.type,
this.ball,
});
/// {@macro assets_manager_state}
AndroidRampSensorState.initial() : this(type: AndroidRampSensorType.door);
const AndroidRampSensorState.initial()
: this(type: AndroidRampSensorType.door);
final AndroidRampSensorType type;
final Ball? ball;

Loading…
Cancel
Save