Skip to content

Commit

Permalink
fix: Fixes (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
luanpotter authored Jul 5, 2023
1 parent 83ed801 commit 06d8193
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/end_game/view/end_game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,26 @@ class _EndGamePageState extends State<EndGamePage> {
late StreamSubscription<GamepadEvent> _gamepadSubscription;
late GamepadNavigator _gamepadNavigator;

// TODO(any): display loading indicator on screen
bool updatingFirebase = true;
bool minDurationElapsed = false;

bool get canMoveOn => !updatingFirebase && minDurationElapsed;

@override
void initState() {
super.initState();
_updateFirebase();
_gamepadNavigator = GamepadNavigator(
onAny: () {
if (updatingFirebase) {
return;
if (canMoveOn) {
Navigator.of(context).pushReplacement(TitlePage.route());
}
Navigator.of(context).pushReplacement(TitlePage.route());
},
);
_gamepadSubscription = Gamepads.events.listen(_gamepadNavigator.handle);
Future.delayed(const Duration(seconds: 10), () {
setState(() => minDurationElapsed = true);
});
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/game/components/ship.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Ship extends SpriteComponent
double engineStrength = 125.0;
double bulletSpeed = 400.0;
double weightFactor = 1.0;
double dragFactor = 5.0;
double dragFactor = 7.0;
final double maxVelocity = 1500;

final Vector2 velocity = Vector2.zero();
Expand Down
11 changes: 9 additions & 2 deletions lib/game/components/spotlight.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Spotlight extends CircleComponent

final List<Ship> currentShips = [];
Ship? get activeShip => currentShips.length == 1 ? currentShips.first : null;

late final TimerComponent _scoreTimer;
late final Rect _visibleArea;

Expand All @@ -36,13 +37,19 @@ class Spotlight extends CircleComponent
radius / 10,
);
_scoreTimer = TimerComponent(
period: 1.0,
period: 0.5,
repeat: true,
autoStart: false,
onTick: () => currentShips.firstOrNull?.score++,
);
_visibleArea = game.playArea.deflate(_spotlightRadius);
addAll([CircleHitbox(isSolid: true), _scoreTimer]);
addAll([
CircleHitbox(
isSolid: true,
collisionType: CollisionType.passive,
),
_scoreTimer
]);
_updateRandomTarget();
_updateColor();
}
Expand Down
1 change: 1 addition & 0 deletions lib/lobby/view/lobby_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class _LobbyPageState extends State<LobbyPage> {
_gamepadSubscription = Gamepads.events.listen((GamepadEvent event) {
setState(() {
if (startButton.matches(event) &&
_players.isNotEmpty &&
!_players.any((p) => p.playerId == null)) {
Navigator.of(context)
.pushReplacement(GamePage.route(players: _players));
Expand Down

0 comments on commit 06d8193

Please sign in to comment.