refactor: improving ramp bonus

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

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

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

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

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

Loading…
Cancel
Save