@ -0,0 +1,21 @@
|
|||||||
|
name: spell_check
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Spell Check
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Check spelling
|
||||||
|
uses: zwaldowski/cspell-action@v1
|
||||||
|
with:
|
||||||
|
paths: '**/*.{dart,arb,md}'
|
||||||
|
config: .vscode/cspell.json
|
@ -1,7 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="development" type="FlutterRunConfigurationType" factoryName="Flutter">
|
|
||||||
<option name="buildFlavor" value="development" />
|
|
||||||
<option name="filePath" value="$PROJECT_DIR$/lib/main_development.dart" />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
@ -0,0 +1,6 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="main" type="FlutterRunConfigurationType" factoryName="Flutter">
|
||||||
|
<option name="filePath" value="$PROJECT_DIR$/lib/main.dart" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
@ -1,7 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="production" type="FlutterRunConfigurationType" factoryName="Flutter">
|
|
||||||
<option name="buildFlavor" value="production" />
|
|
||||||
<option name="filePath" value="$PROJECT_DIR$/lib/main_production.dart" />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
@ -1,7 +0,0 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
|
||||||
<configuration default="false" name="staging" type="FlutterRunConfigurationType" factoryName="Flutter">
|
|
||||||
<option name="buildFlavor" value="staging" />
|
|
||||||
<option name="filePath" value="$PROJECT_DIR$/lib/main_staging.dart" />
|
|
||||||
<method v="2" />
|
|
||||||
</configuration>
|
|
||||||
</component>
|
|
@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2",
|
||||||
|
"enabled": true,
|
||||||
|
"language": "en",
|
||||||
|
"words": [
|
||||||
|
"animatronic",
|
||||||
|
"argb",
|
||||||
|
"audioplayers",
|
||||||
|
"backbox",
|
||||||
|
"bezier",
|
||||||
|
"contador",
|
||||||
|
"cupertino",
|
||||||
|
"dashbook",
|
||||||
|
"deserialization",
|
||||||
|
"dpad",
|
||||||
|
"endtemplate",
|
||||||
|
"firestore",
|
||||||
|
"gapless",
|
||||||
|
"genhtml",
|
||||||
|
"goldens",
|
||||||
|
"lcov",
|
||||||
|
"leaderboard",
|
||||||
|
"loadables",
|
||||||
|
"localizable",
|
||||||
|
"mixins",
|
||||||
|
"mocktail",
|
||||||
|
"mostrado",
|
||||||
|
"multiball",
|
||||||
|
"multiballs",
|
||||||
|
"occluder",
|
||||||
|
"página",
|
||||||
|
"pixelated",
|
||||||
|
"pixeloid",
|
||||||
|
"rects",
|
||||||
|
"rrect",
|
||||||
|
"serializable",
|
||||||
|
"sparky's",
|
||||||
|
"tappable",
|
||||||
|
"tappables",
|
||||||
|
"texto",
|
||||||
|
"theming",
|
||||||
|
"unawaited",
|
||||||
|
"unfocus",
|
||||||
|
"unlayered",
|
||||||
|
"vsync"
|
||||||
|
],
|
||||||
|
"ignorePaths": [
|
||||||
|
".github/workflows/**"
|
||||||
|
]
|
||||||
|
}
|
After Width: | Height: | Size: 1.3 MiB |
After Width: | Height: | Size: 7.8 KiB |
@ -1,27 +1,39 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball/select_character/select_character.dart';
|
||||||
|
import 'package:pinball_audio/pinball_audio.dart';
|
||||||
|
|
||||||
part 'assets_manager_state.dart';
|
part 'assets_manager_state.dart';
|
||||||
|
|
||||||
/// {@template assets_manager_cubit}
|
|
||||||
/// Cubit responsable for pre loading any game assets
|
|
||||||
/// {@endtemplate}
|
|
||||||
class AssetsManagerCubit extends Cubit<AssetsManagerState> {
|
class AssetsManagerCubit extends Cubit<AssetsManagerState> {
|
||||||
/// {@macro assets_manager_cubit}
|
AssetsManagerCubit(this._game, this._audioPlayer)
|
||||||
AssetsManagerCubit(List<Future> loadables)
|
: super(const AssetsManagerState.initial());
|
||||||
: super(
|
|
||||||
AssetsManagerState.initial(
|
final PinballGame _game;
|
||||||
loadables: loadables,
|
final PinballAudioPlayer _audioPlayer;
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
/// Loads the assets
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
|
/// Assigning loadables is a very expensive operation. With this purposeful
|
||||||
|
/// delay here, which is a bit random in duration but enough to let the UI
|
||||||
|
/// do its job without adding too much delay for the user, we are letting
|
||||||
|
/// the UI paint first, and then we start loading the assets.
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 300));
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
loadables: [
|
||||||
|
_game.preFetchLeaderboard(),
|
||||||
|
..._game.preLoadAssets(),
|
||||||
|
..._audioPlayer.load(),
|
||||||
|
...BonusAnimation.loadAssets(),
|
||||||
|
...SelectedCharacter.loadAssets(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
final all = state.loadables.map((loadable) async {
|
final all = state.loadables.map((loadable) async {
|
||||||
await loadable;
|
await loadable;
|
||||||
emit(state.copyWith(loaded: [...state.loaded, loadable]));
|
emit(state.copyWith(loaded: [...state.loaded, loadable]));
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
await Future.wait(all);
|
await Future.wait(all);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:pinball/select_character/select_character.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// {@template bonus_ball_spawning_behavior}
|
||||||
|
/// After a duration, spawns a bonus ball from the [DinoWalls] and boosts it
|
||||||
|
/// into the middle of the board.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class BonusBallSpawningBehavior extends TimerComponent with HasGameRef {
|
||||||
|
/// {@macro bonus_ball_spawning_behavior}
|
||||||
|
BonusBallSpawningBehavior()
|
||||||
|
: super(
|
||||||
|
period: 5,
|
||||||
|
removeOnFinish: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onTick() {
|
||||||
|
final characterTheme = readBloc<CharacterThemeCubit, CharacterThemeState>()
|
||||||
|
.state
|
||||||
|
.characterTheme;
|
||||||
|
gameRef.descendants().whereType<ZCanvasComponent>().single.add(
|
||||||
|
Ball(assetPath: characterTheme.ball.keyName)
|
||||||
|
..add(BallImpulsingBehavior(impulse: Vector2(-40, 0)))
|
||||||
|
..initialPosition = Vector2(29.2, -24.5)
|
||||||
|
..zIndex = ZIndexes.ballOnBoard,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
|
export 'game_over_info_display.dart';
|
||||||
export 'initials_input_display.dart';
|
export 'initials_input_display.dart';
|
||||||
export 'initials_submission_failure_display.dart';
|
export 'initials_submission_failure_display.dart';
|
||||||
export 'initials_submission_success_display.dart';
|
export 'initials_submission_success_display.dart';
|
||||||
export 'leaderboard_display.dart';
|
export 'leaderboard_display.dart';
|
||||||
|
export 'leaderboard_failure_display.dart';
|
||||||
export 'loading_display.dart';
|
export 'loading_display.dart';
|
||||||
export 'share_display.dart';
|
export 'share_display.dart';
|
||||||
|
@ -0,0 +1,311 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame/input.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
import 'package:share_repository/share_repository.dart';
|
||||||
|
|
||||||
|
/// Signature for the callback called when the user tries to share their score
|
||||||
|
/// from the [GameOverInfoDisplay].
|
||||||
|
typedef OnShareTap = void Function();
|
||||||
|
|
||||||
|
final _titleTextPaint = TextPaint(
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 1.6,
|
||||||
|
color: PinballColors.white,
|
||||||
|
fontFamily: PinballFonts.pixeloidSans,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final _titleBoldTextPaint = TextPaint(
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 1.4,
|
||||||
|
color: PinballColors.white,
|
||||||
|
fontFamily: PinballFonts.pixeloidSans,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final _linkTextPaint = TextPaint(
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 1.7,
|
||||||
|
color: PinballColors.orange,
|
||||||
|
fontFamily: PinballFonts.pixeloidSans,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final _descriptionTextPaint = TextPaint(
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 1.6,
|
||||||
|
color: PinballColors.white,
|
||||||
|
fontFamily: PinballFonts.pixeloidSans,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/// {@template game_over_info_display}
|
||||||
|
/// Display with links to share your score or go to the IO webpage.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class GameOverInfoDisplay extends Component with HasGameRef {
|
||||||
|
/// {@macro game_over_info_display}
|
||||||
|
GameOverInfoDisplay({
|
||||||
|
OnShareTap? onShare,
|
||||||
|
}) : super(
|
||||||
|
children: [
|
||||||
|
_InstructionsComponent(
|
||||||
|
onShare: onShare,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
gameRef.overlays.add(PinballGame.playButtonOverlay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InstructionsComponent extends PositionComponent with HasGameRef {
|
||||||
|
_InstructionsComponent({
|
||||||
|
OnShareTap? onShare,
|
||||||
|
}) : super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, -25),
|
||||||
|
children: [
|
||||||
|
_TitleComponent(),
|
||||||
|
_LinksComponent(
|
||||||
|
onShare: onShare,
|
||||||
|
),
|
||||||
|
_DescriptionComponent(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TitleComponent extends PositionComponent with HasGameRef {
|
||||||
|
_TitleComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, 3),
|
||||||
|
children: [
|
||||||
|
_TitleBackgroundSpriteComponent(),
|
||||||
|
_ShareScoreTextComponent(),
|
||||||
|
_ChallengeFriendsTextComponent(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ShareScoreTextComponent extends TextComponent with HasGameRef {
|
||||||
|
_ShareScoreTextComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, -1.5),
|
||||||
|
textRenderer: _titleTextPaint,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
text = readProvider<AppLocalizations>().shareYourScore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChallengeFriendsTextComponent extends TextComponent with HasGameRef {
|
||||||
|
_ChallengeFriendsTextComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, 1.5),
|
||||||
|
textRenderer: _titleBoldTextPaint,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
text = readProvider<AppLocalizations>().andChallengeYourFriends;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TitleBackgroundSpriteComponent extends SpriteComponent with HasGameRef {
|
||||||
|
_TitleBackgroundSpriteComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2.zero(),
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
final sprite = Sprite(
|
||||||
|
gameRef.images
|
||||||
|
.fromCache(Assets.images.backbox.displayTitleDecoration.keyName),
|
||||||
|
);
|
||||||
|
this.sprite = sprite;
|
||||||
|
size = sprite.originalSize / 22;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LinksComponent extends PositionComponent with HasGameRef {
|
||||||
|
_LinksComponent({
|
||||||
|
OnShareTap? onShare,
|
||||||
|
}) : super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, 9.2),
|
||||||
|
children: [
|
||||||
|
ShareLinkComponent(onTap: onShare),
|
||||||
|
GoogleIOLinkComponent(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template share_link_component}
|
||||||
|
/// Link button to navigate to sharing score display.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class ShareLinkComponent extends TextComponent with HasGameRef, Tappable {
|
||||||
|
/// {@macro share_link_component}
|
||||||
|
ShareLinkComponent({
|
||||||
|
OnShareTap? onTap,
|
||||||
|
}) : _onTap = onTap,
|
||||||
|
super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(-7, 0),
|
||||||
|
textRenderer: _linkTextPaint,
|
||||||
|
);
|
||||||
|
|
||||||
|
final OnShareTap? _onTap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool onTapDown(TapDownInfo info) {
|
||||||
|
_onTap?.call();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
await add(
|
||||||
|
RectangleComponent(
|
||||||
|
size: Vector2(6.4, 0.2),
|
||||||
|
paint: Paint()..color = PinballColors.orange,
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(3.2, 2.3),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
text = readProvider<AppLocalizations>().share;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template google_io_link_component}
|
||||||
|
/// Link button to navigate to Google I/O site.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class GoogleIOLinkComponent extends TextComponent with HasGameRef, Tappable {
|
||||||
|
/// {@macro google_io_link_component}
|
||||||
|
GoogleIOLinkComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(6, 0),
|
||||||
|
textRenderer: _linkTextPaint,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool onTapDown(TapDownInfo info) {
|
||||||
|
openLink(ShareRepository.googleIOEvent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
await add(
|
||||||
|
RectangleComponent(
|
||||||
|
size: Vector2(10.2, 0.2),
|
||||||
|
paint: Paint()..color = PinballColors.orange,
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(5.1, 2.3),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
text = readProvider<AppLocalizations>().gotoIO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DescriptionComponent extends PositionComponent with HasGameRef {
|
||||||
|
_DescriptionComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, 13),
|
||||||
|
children: [
|
||||||
|
_LearnMoreTextComponent(),
|
||||||
|
_FirebaseTextComponent(),
|
||||||
|
OpenSourceTextComponent(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LearnMoreTextComponent extends TextComponent with HasGameRef {
|
||||||
|
_LearnMoreTextComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2.zero(),
|
||||||
|
textRenderer: _descriptionTextPaint,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
text = readProvider<AppLocalizations>().learnMore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FirebaseTextComponent extends TextComponent with HasGameRef {
|
||||||
|
_FirebaseTextComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(-8.5, 2.5),
|
||||||
|
textRenderer: _descriptionTextPaint,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
text = readProvider<AppLocalizations>().firebaseOr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template open_source_link_component}
|
||||||
|
/// Link text to navigate to Open Source site.
|
||||||
|
/// {@endtemplate}
|
||||||
|
@visibleForTesting
|
||||||
|
class OpenSourceTextComponent extends TextComponent with HasGameRef, Tappable {
|
||||||
|
/// {@macro open_source_link_component}
|
||||||
|
OpenSourceTextComponent()
|
||||||
|
: super(
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(13.5, 2.5),
|
||||||
|
textRenderer: _descriptionTextPaint,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool onTapDown(TapDownInfo info) {
|
||||||
|
openLink(ShareRepository.openSourceCode);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
await add(
|
||||||
|
RectangleComponent(
|
||||||
|
size: Vector2(16, 0.2),
|
||||||
|
paint: Paint()..color = PinballColors.white,
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(8, 2.3),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
text = readProvider<AppLocalizations>().openSourceCode;
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,47 @@
|
|||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pinball/game/game.dart';
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
import 'package:pinball_ui/pinball_ui.dart';
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
final _bodyTextPaint = TextPaint(
|
final _bodyTextPaint = TextPaint(
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 3,
|
fontSize: 1.8,
|
||||||
color: PinballColors.white,
|
color: PinballColors.white,
|
||||||
fontFamily: PinballFonts.pixeloidSans,
|
fontFamily: PinballFonts.pixeloidSans,
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/// {@template initials_submission_failure_display}
|
/// {@template initials_submission_failure_display}
|
||||||
/// [Backbox] display for when a failure occurs during initials submission.
|
/// [Backbox] display for when a failure occurs during initials submission.
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
class InitialsSubmissionFailureDisplay extends TextComponent {
|
class InitialsSubmissionFailureDisplay extends Component {
|
||||||
|
/// {@macro initials_submission_failure_display}
|
||||||
|
InitialsSubmissionFailureDisplay({
|
||||||
|
required this.onDismissed,
|
||||||
|
});
|
||||||
|
|
||||||
|
final VoidCallback onDismissed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onLoad() async {
|
Future<void> onLoad() async {
|
||||||
await super.onLoad();
|
final l10n = readProvider<AppLocalizations>();
|
||||||
position = Vector2(0, -10);
|
|
||||||
anchor = Anchor.center;
|
await addAll([
|
||||||
text = 'Failure!';
|
ErrorComponent.bold(
|
||||||
textRenderer = _bodyTextPaint;
|
label: l10n.initialsErrorTitle,
|
||||||
|
position: Vector2(0, -20),
|
||||||
|
),
|
||||||
|
TextComponent(
|
||||||
|
text: l10n.initialsErrorMessage,
|
||||||
|
anchor: Anchor.center,
|
||||||
|
position: Vector2(0, -12),
|
||||||
|
textRenderer: _bodyTextPaint,
|
||||||
|
),
|
||||||
|
TimerComponent(period: 4, onTick: onDismissed),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// {@template leaderboard_failure_display}
|
||||||
|
/// Display showing an error message when the leaderboard couldn't be loaded
|
||||||
|
/// {@endtemplate}
|
||||||
|
class LeaderboardFailureDisplay extends Component {
|
||||||
|
/// {@macro leaderboard_failure_display}
|
||||||
|
LeaderboardFailureDisplay();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
final l10n = readProvider<AppLocalizations>();
|
||||||
|
await add(
|
||||||
|
ErrorComponent(
|
||||||
|
label: l10n.leaderboardErrorMessage,
|
||||||
|
position: Vector2(0, -18),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
|
/// {@template mobile_controls}
|
||||||
|
/// Widget with the controls used to enable the user initials input on mobile.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class MobileControls extends StatelessWidget {
|
||||||
|
/// {@macro mobile_controls}
|
||||||
|
const MobileControls({
|
||||||
|
Key? key,
|
||||||
|
required this.game,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
/// Game instance
|
||||||
|
final PinballGame game;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final l10n = AppLocalizations.of(context);
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
MobileDpad(
|
||||||
|
onTapUp: () => game.triggerVirtualKeyUp(LogicalKeyboardKey.arrowUp),
|
||||||
|
onTapDown: () => game.triggerVirtualKeyUp(
|
||||||
|
LogicalKeyboardKey.arrowDown,
|
||||||
|
),
|
||||||
|
onTapLeft: () => game.triggerVirtualKeyUp(
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
),
|
||||||
|
onTapRight: () => game.triggerVirtualKeyUp(
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
PinballButton(
|
||||||
|
text: l10n.enter,
|
||||||
|
onTap: () => game.triggerVirtualKeyUp(LogicalKeyboardKey.enter),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
|
/// {@template mobile_dpad}
|
||||||
|
/// Widget rendering 4 directional input arrows.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class MobileDpad extends StatelessWidget {
|
||||||
|
/// {@template mobile_dpad}
|
||||||
|
const MobileDpad({
|
||||||
|
Key? key,
|
||||||
|
required this.onTapUp,
|
||||||
|
required this.onTapDown,
|
||||||
|
required this.onTapLeft,
|
||||||
|
required this.onTapRight,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
static const _size = 180.0;
|
||||||
|
|
||||||
|
/// Called when dpad up is pressed
|
||||||
|
final VoidCallback onTapUp;
|
||||||
|
|
||||||
|
/// Called when dpad down is pressed
|
||||||
|
final VoidCallback onTapDown;
|
||||||
|
|
||||||
|
/// Called when dpad left is pressed
|
||||||
|
final VoidCallback onTapLeft;
|
||||||
|
|
||||||
|
/// Called when dpad right is pressed
|
||||||
|
final VoidCallback onTapRight;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: _size,
|
||||||
|
height: _size,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Spacer(),
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.up,
|
||||||
|
onTap: onTapUp,
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.left,
|
||||||
|
onTap: onTapLeft,
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.right,
|
||||||
|
onTap: onTapRight,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Spacer(),
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.down,
|
||||||
|
onTap: onTapDown,
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball/start_game/start_game.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
|
/// {@template replay_button_overlay}
|
||||||
|
/// [Widget] that renders the button responsible for restarting the game.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class ReplayButtonOverlay extends StatelessWidget {
|
||||||
|
/// {@macro replay_button_overlay}
|
||||||
|
const ReplayButtonOverlay({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final l10n = context.l10n;
|
||||||
|
|
||||||
|
return PinballButton(
|
||||||
|
text: l10n.replay,
|
||||||
|
onTap: () {
|
||||||
|
context.read<StartGameBloc>().add(const ReplayTapped());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
export 'bonus_animation.dart';
|
export 'bonus_animation.dart';
|
||||||
export 'game_hud.dart';
|
export 'game_hud.dart';
|
||||||
|
export 'mobile_controls.dart';
|
||||||
|
export 'mobile_dpad.dart';
|
||||||
export 'play_button_overlay.dart';
|
export 'play_button_overlay.dart';
|
||||||
|
export 'replay_button_overlay.dart';
|
||||||
export 'round_count_display.dart';
|
export 'round_count_display.dart';
|
||||||
export 'score_view.dart';
|
export 'score_view.dart';
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:authentication_repository/authentication_repository.dart';
|
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
|
||||||
import 'package:leaderboard_repository/leaderboard_repository.dart';
|
|
||||||
import 'package:pinball/app/app.dart';
|
|
||||||
import 'package:pinball/bootstrap.dart';
|
|
||||||
import 'package:pinball_audio/pinball_audio.dart';
|
|
||||||
import 'package:share_repository/share_repository.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
bootstrap((firestore, firebaseAuth) async {
|
|
||||||
final leaderboardRepository = LeaderboardRepository(firestore);
|
|
||||||
const shareRepository =
|
|
||||||
ShareRepository(appUrl: ShareRepository.googleIOEvent);
|
|
||||||
final authenticationRepository = AuthenticationRepository(firebaseAuth);
|
|
||||||
final pinballPlayer = PinballPlayer();
|
|
||||||
unawaited(
|
|
||||||
Firebase.initializeApp().then(
|
|
||||||
(_) => authenticationRepository.authenticateAnonymously(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return App(
|
|
||||||
authenticationRepository: authenticationRepository,
|
|
||||||
leaderboardRepository: leaderboardRepository,
|
|
||||||
shareRepository: shareRepository,
|
|
||||||
pinballPlayer: pinballPlayer,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:authentication_repository/authentication_repository.dart';
|
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
|
||||||
import 'package:leaderboard_repository/leaderboard_repository.dart';
|
|
||||||
import 'package:pinball/app/app.dart';
|
|
||||||
import 'package:pinball/bootstrap.dart';
|
|
||||||
import 'package:pinball_audio/pinball_audio.dart';
|
|
||||||
import 'package:share_repository/share_repository.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
bootstrap((firestore, firebaseAuth) async {
|
|
||||||
final leaderboardRepository = LeaderboardRepository(firestore);
|
|
||||||
const shareRepository =
|
|
||||||
ShareRepository(appUrl: ShareRepository.googleIOEvent);
|
|
||||||
final authenticationRepository = AuthenticationRepository(firebaseAuth);
|
|
||||||
final pinballPlayer = PinballPlayer();
|
|
||||||
unawaited(
|
|
||||||
Firebase.initializeApp().then(
|
|
||||||
(_) => authenticationRepository.authenticateAnonymously(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return App(
|
|
||||||
authenticationRepository: authenticationRepository,
|
|
||||||
leaderboardRepository: leaderboardRepository,
|
|
||||||
shareRepository: shareRepository,
|
|
||||||
pinballPlayer: pinballPlayer,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 270 KiB After Width: | Height: | Size: 266 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 29 KiB |
@ -1,14 +1,18 @@
|
|||||||
|
// ignore_for_file: public_member_api_docs
|
||||||
|
|
||||||
|
import 'package:flame_bloc/flame_bloc.dart';
|
||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
import 'package:pinball_flame/pinball_flame.dart';
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
class AndroidSpaceshipEntranceBallContactBehavior
|
class AndroidSpaceshipEntranceBallContactBehavior
|
||||||
extends ContactBehavior<AndroidSpaceshipEntrance> {
|
extends ContactBehavior<AndroidSpaceshipEntrance>
|
||||||
|
with FlameBlocReader<AndroidSpaceshipCubit, AndroidSpaceshipState> {
|
||||||
@override
|
@override
|
||||||
void beginContact(Object other, Contact contact) {
|
void beginContact(Object other, Contact contact) {
|
||||||
super.beginContact(other, contact);
|
super.beginContact(other, contact);
|
||||||
if (other is! Ball) return;
|
if (other is! Ball) return;
|
||||||
|
|
||||||
parent.parent.bloc.onBallEntered();
|
bloc.onBallEntered();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// {@template ball_impulsing_behavior}
|
||||||
|
/// Impulses the [Ball] in a given direction.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class BallImpulsingBehavior extends Component with ParentIsA<Ball> {
|
||||||
|
/// {@macro ball_impulsing_behavior}
|
||||||
|
BallImpulsingBehavior({
|
||||||
|
required Vector2 impulse,
|
||||||
|
}) : _impulse = impulse;
|
||||||
|
|
||||||
|
final Vector2 _impulse;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
parent.body.linearVelocity = _impulse;
|
||||||
|
shouldRemove = true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,4 @@
|
|||||||
export 'ball_gravitating_behavior.dart';
|
export 'ball_gravitating_behavior.dart';
|
||||||
|
export 'ball_impulsing_behavior.dart';
|
||||||
export 'ball_scaling_behavior.dart';
|
export 'ball_scaling_behavior.dart';
|
||||||
export 'ball_turbo_charging_behavior.dart';
|
export 'ball_turbo_charging_behavior.dart';
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
export 'dash_bumper_ball_contact_behavior.dart';
|
@ -0,0 +1,17 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
|
||||||
|
part 'dash_bumper_state.dart';
|
||||||
|
|
||||||
|
class DashBumperCubit extends Cubit<DashBumperState> {
|
||||||
|
DashBumperCubit() : super(DashBumperState.inactive);
|
||||||
|
|
||||||
|
/// Event added when the bumper contacts with a ball.
|
||||||
|
void onBallContacted() {
|
||||||
|
emit(DashBumperState.active);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Event added when the bumper should return to its initial configuration.
|
||||||
|
void onReset() {
|
||||||
|
emit(DashBumperState.inactive);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
part of 'dash_bumper_cubit.dart';
|
||||||
|
|
||||||
|
/// Indicates the [DashBumperCubit]'s current state.
|
||||||
|
enum DashBumperState {
|
||||||
|
/// A lit up bumper.
|
||||||
|
active,
|
||||||
|
|
||||||
|
/// A dimmed bumper.
|
||||||
|
inactive,
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
export 'dash_nest_bumper_contact_behavior.dart';
|
|
@ -1,17 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
|
|
||||||
part 'dash_nest_bumper_state.dart';
|
|
||||||
|
|
||||||
class DashNestBumperCubit extends Cubit<DashNestBumperState> {
|
|
||||||
DashNestBumperCubit() : super(DashNestBumperState.inactive);
|
|
||||||
|
|
||||||
/// Event added when the bumper contacts with a ball.
|
|
||||||
void onBallContacted() {
|
|
||||||
emit(DashNestBumperState.active);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Event added when the bumper should return to its initial configuration.
|
|
||||||
void onReset() {
|
|
||||||
emit(DashNestBumperState.inactive);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
part of 'dash_nest_bumper_cubit.dart';
|
|
||||||
|
|
||||||
/// Indicates the [DashNestBumperCubit]'s current state.
|
|
||||||
enum DashNestBumperState {
|
|
||||||
/// A lit up bumper.
|
|
||||||
active,
|
|
||||||
|
|
||||||
/// A dimmed bumper.
|
|
||||||
inactive,
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
import 'dart:math' as math;
|
|
||||||
|
|
||||||
import 'package:flame/components.dart';
|
|
||||||
import 'package:flame/extensions.dart';
|
|
||||||
import 'package:flame/particles.dart';
|
|
||||||
import 'package:flame_forge2d/flame_forge2d.dart' hide Particle;
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
const _particleRadius = 0.25;
|
|
||||||
|
|
||||||
/// {@template fire_effect}
|
|
||||||
/// A [BodyComponent] which creates a fire trail effect using the given
|
|
||||||
/// parameters
|
|
||||||
/// {@endtemplate}
|
|
||||||
class FireEffect extends ParticleSystemComponent {
|
|
||||||
/// {@macro fire_effect}
|
|
||||||
FireEffect({
|
|
||||||
required this.burstPower,
|
|
||||||
required this.direction,
|
|
||||||
Vector2? position,
|
|
||||||
}) : super(
|
|
||||||
position: position,
|
|
||||||
);
|
|
||||||
|
|
||||||
/// A [double] value that will define how "strong" the burst of particles
|
|
||||||
/// will be.
|
|
||||||
final double burstPower;
|
|
||||||
|
|
||||||
/// Which direction the burst will aim.
|
|
||||||
final Vector2 direction;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> onLoad() async {
|
|
||||||
await super.onLoad();
|
|
||||||
|
|
||||||
final children = [
|
|
||||||
...List.generate(4, (index) {
|
|
||||||
return CircleParticle(
|
|
||||||
radius: _particleRadius,
|
|
||||||
paint: Paint()..color = Colors.yellow.darken((index + 1) / 4),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
...List.generate(4, (index) {
|
|
||||||
return CircleParticle(
|
|
||||||
radius: _particleRadius,
|
|
||||||
paint: Paint()..color = Colors.red.darken((index + 1) / 4),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
...List.generate(4, (index) {
|
|
||||||
return CircleParticle(
|
|
||||||
radius: _particleRadius,
|
|
||||||
paint: Paint()..color = Colors.orange.darken((index + 1) / 4),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
final random = math.Random();
|
|
||||||
final spreadTween = Tween<double>(begin: -0.2, end: 0.2);
|
|
||||||
|
|
||||||
particle = Particle.generate(
|
|
||||||
count: math.max((random.nextDouble() * (burstPower * 10)).toInt(), 1),
|
|
||||||
generator: (_) {
|
|
||||||
final spread = Vector2(
|
|
||||||
spreadTween.transform(random.nextDouble()),
|
|
||||||
spreadTween.transform(random.nextDouble()),
|
|
||||||
);
|
|
||||||
final finalDirection = Vector2(direction.x, direction.y) + spread;
|
|
||||||
final speed = finalDirection * (burstPower * 20);
|
|
||||||
|
|
||||||
return AcceleratedParticle(
|
|
||||||
lifespan: 5 / burstPower,
|
|
||||||
position: Vector2.zero(),
|
|
||||||
speed: speed,
|
|
||||||
child: children[random.nextInt(children.length)],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,2 @@
|
|||||||
|
export 'flipper_jointing_behavior.dart';
|
||||||
|
export 'flipper_key_controlling_behavior.dart';
|
@ -0,0 +1,62 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// Joints the [Flipper] to allow pivoting around one end.
|
||||||
|
class FlipperJointingBehavior extends Component
|
||||||
|
with ParentIsA<Flipper>, HasGameRef {
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
final anchor = _FlipperAnchor(flipper: parent);
|
||||||
|
await add(anchor);
|
||||||
|
|
||||||
|
final jointDef = _FlipperAnchorRevoluteJointDef(
|
||||||
|
flipper: parent,
|
||||||
|
anchor: anchor,
|
||||||
|
);
|
||||||
|
parent.world.createJoint(RevoluteJoint(jointDef));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template flipper_anchor}
|
||||||
|
/// [JointAnchor] positioned at the end of a [Flipper].
|
||||||
|
///
|
||||||
|
/// The end of a [Flipper] depends on its [Flipper.side].
|
||||||
|
/// {@endtemplate}
|
||||||
|
class _FlipperAnchor extends JointAnchor {
|
||||||
|
/// {@macro flipper_anchor}
|
||||||
|
_FlipperAnchor({
|
||||||
|
required Flipper flipper,
|
||||||
|
}) {
|
||||||
|
initialPosition = Vector2(
|
||||||
|
(Flipper.size.x * flipper.side.direction) / 2 -
|
||||||
|
(1.65 * flipper.side.direction),
|
||||||
|
-0.15,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template flipper_anchor_revolute_joint_def}
|
||||||
|
/// Hinges one end of [Flipper] to a [_FlipperAnchor] to achieve a pivoting
|
||||||
|
/// motion.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class _FlipperAnchorRevoluteJointDef extends RevoluteJointDef {
|
||||||
|
/// {@macro flipper_anchor_revolute_joint_def}
|
||||||
|
_FlipperAnchorRevoluteJointDef({
|
||||||
|
required Flipper flipper,
|
||||||
|
required _FlipperAnchor anchor,
|
||||||
|
}) {
|
||||||
|
initialize(
|
||||||
|
flipper.body,
|
||||||
|
anchor.body,
|
||||||
|
flipper.body.position + anchor.body.position,
|
||||||
|
);
|
||||||
|
|
||||||
|
enableLimit = true;
|
||||||
|
upperAngle = 0.611;
|
||||||
|
lowerAngle = -upperAngle;
|
||||||
|
}
|
||||||
|
}
|
@ -1,49 +1,33 @@
|
|||||||
import 'package:flame/components.dart';
|
import 'package:flame/components.dart';
|
||||||
import 'package:flame_bloc/flame_bloc.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
import 'package:pinball_flame/pinball_flame.dart';
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
/// {@template controlled_flipper}
|
/// Allows controlling the [Flipper]'s movement with keyboard input.
|
||||||
/// A [Flipper] with a [FlipperController] attached.
|
class FlipperKeyControllingBehavior extends Component
|
||||||
/// {@endtemplate}
|
with KeyboardHandler, ParentIsA<Flipper> {
|
||||||
class ControlledFlipper extends Flipper with Controls<FlipperController> {
|
|
||||||
/// {@macro controlled_flipper}
|
|
||||||
ControlledFlipper({
|
|
||||||
required BoardSide side,
|
|
||||||
}) : super(side: side) {
|
|
||||||
controller = FlipperController(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// {@template flipper_controller}
|
|
||||||
/// A [ComponentController] that controls a [Flipper]s movement.
|
|
||||||
/// {@endtemplate}
|
|
||||||
class FlipperController extends ComponentController<Flipper>
|
|
||||||
with KeyboardHandler, FlameBlocReader<GameBloc, GameState> {
|
|
||||||
/// {@macro flipper_controller}
|
|
||||||
FlipperController(Flipper flipper)
|
|
||||||
: _keys = flipper.side.flipperKeys,
|
|
||||||
super(flipper);
|
|
||||||
|
|
||||||
/// The [LogicalKeyboardKey]s that will control the [Flipper].
|
/// The [LogicalKeyboardKey]s that will control the [Flipper].
|
||||||
///
|
///
|
||||||
/// [onKeyEvent] method listens to when one of these keys is pressed.
|
/// [onKeyEvent] method listens to when one of these keys is pressed.
|
||||||
final List<LogicalKeyboardKey> _keys;
|
late final List<LogicalKeyboardKey> _keys;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
_keys = parent.side.flipperKeys;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool onKeyEvent(
|
bool onKeyEvent(
|
||||||
RawKeyEvent event,
|
RawKeyEvent event,
|
||||||
Set<LogicalKeyboardKey> keysPressed,
|
Set<LogicalKeyboardKey> keysPressed,
|
||||||
) {
|
) {
|
||||||
if (!bloc.state.status.isPlaying) return true;
|
|
||||||
if (!_keys.contains(event.logicalKey)) return true;
|
if (!_keys.contains(event.logicalKey)) return true;
|
||||||
|
|
||||||
if (event is RawKeyDownEvent) {
|
if (event is RawKeyDownEvent) {
|
||||||
component.moveUp();
|
parent.moveUp();
|
||||||
} else if (event is RawKeyUpEvent) {
|
} else if (event is RawKeyUpEvent) {
|
||||||
component.moveDown();
|
parent.moveDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
@ -0,0 +1 @@
|
|||||||
|
export 'score_component_scaling_behavior.dart';
|
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
/// Scales a [ScoreComponent] according to its position on the board.
|
||||||
|
class ScoreComponentScalingBehavior extends Component
|
||||||
|
with ParentIsA<SpriteComponent> {
|
||||||
|
@override
|
||||||
|
void update(double dt) {
|
||||||
|
super.update(dt);
|
||||||
|
final boardHeight = BoardDimensions.bounds.height;
|
||||||
|
const maxShrinkValue = 0.83;
|
||||||
|
|
||||||
|
final augmentedPosition = parent.position.y * 3;
|
||||||
|
final standardizedYPosition = augmentedPosition + (boardHeight / 2);
|
||||||
|
final scaleFactor = maxShrinkValue +
|
||||||
|
((standardizedYPosition / boardHeight) * (1 - maxShrinkValue));
|
||||||
|
|
||||||
|
parent.scale.setValues(
|
||||||
|
scaleFactor,
|
||||||
|
scaleFactor,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|