You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pinball/lib/game/pinball_game.dart

331 lines
10 KiB

import 'dart:async';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
feat: Flipper (#15) * feat: explicitely imported Anchor * feat: implemented Flipper * feat: implemented Flipper in PinballGame * feat: implemented calculateRequiredSpeed * feat: included right and left constructors * feat: used right and left constructors * refactor: cleaned calcualteSpeed method * refactor: used width and height instead of size * feat: implemented FlipperAnchor * feat: implemented BoardSide enum * docs: used prose in doc comment * feat: implemented BoardSideX * refactor: used isLeft instead of isRight * refactor: implemented unlock method * refactor: same line assignment Co-authored-by: Erick <erickzanardoo@gmail.com> * feat: add themes * feat: add theme cubit * test: character themes * test: remove grouping * refactor: move themes to package * chore: add workflow * fix: workflow * docs: character themes update * refactor: one theme for entire game * chore: add to props * fix: changing ball spawning point to avoid context errors * refactor: modified unlock method due to invalid cast * feat: included test for BoardSide * refactor: removed sweepingAnimationDuration * feat: tested flipper.dart * refactor: included flippersPosition * refactor: implemented _addFlippers method * feat: centered vertices * feat: modified test to match new center * refactor: removed unecessary parenthesis * refactor: removed unecessary calculation * fix: changing ball spawning point to avoid context errors * chore: rebasing * docs: included FIXME comment * feat: moved key listening to Flipper * docs: include TOOD comment * feat: including test and refactor * docs: fixed doc comment typo Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * docs: fixed do comment template name Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: removed unnecessary verbose multiplication Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: removed unnecessary verbose multiplication * refactor: used ensureAddAll instead of ensureAdd Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * docs: fixed doc comment typo * refactor: used bigCircleShape.radius * refactor: reorganized methods * docs: improved doc comment * refactor: removed unecessary class variables * docs: fix doc comment typo * refactor: removed unused helper * fix: simplified keyEvents * fix: corrected erroneous key tests * refactor: modified component tests * refactor: capitalized Flipper test description * refactor: changed angle calculations * fix: tests * refactor: removed exta line Co-authored-by: Erick <erickzanardoo@gmail.com> Co-authored-by: Allison Ryan <allisonryan0002@gmail.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
import 'package:flame/input.dart';
import 'package:flame_bloc/flame_bloc.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:leaderboard_repository/leaderboard_repository.dart';
import 'package:pinball/game/behaviors/behaviors.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/select_character/select_character.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_flame/pinball_flame.dart';
import 'package:platform_helper/platform_helper.dart';
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
import 'package:share_repository/share_repository.dart';
class PinballGame extends PinballForge2DGame
feat: `GameOverInfoDisplay` on game over `Backbox` (#359) * feat: info screen ui * feat: info screen ui * feat: replay button * feat: added replay button and game flow * feat: game over info display flow at backbox * test: fixed tests and coverage * test: fix tests and coverage * chore: info display doc" * refactor: text component name * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/info_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/start_game/widgets/start_game_listener_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/start_game/widgets/start_game_listener_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/view/widgets/replay_button_overlay_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/info_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/view/widgets/replay_button_overlay.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/l10n/arb/app_en.arb Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/bloc/backbox_bloc_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/l10n/arb/app_en.arb Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: changed names and removed replaying * refactor: removed restart logic changes for another pr * feat: link underscore * chore: test fixed, names changed * chore: unused import * feat: add replayButtonOverlay at GameOverInfoDisplay * feat: added open source url url launcher * feat: launch url and test * chore: removed comments * fix: remove overlay for Replay to merge info screen * chore: unused import * test: load images bug fix * Update lib/game/components/backbox/displays/game_over_info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: removed props from state for sharing only score * feat: moved open links to info display and added link to OS * test: fixed merge tests * chore: unused imports and annotation missed * Update lib/game/components/backbox/bloc/backbox_state.dart * chore: tappables added to cspell Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> Co-authored-by: Tom Arra <tarra3@gmail.com>
3 years ago
with HasKeyboardHandlerComponents, MultiTouchTapDetector, HasTappables {
PinballGame({
required CharacterThemeCubit characterThemeBloc,
required this.leaderboardRepository,
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
required this.shareRepository,
required GameBloc gameBloc,
required AppLocalizations l10n,
required PinballAudioPlayer audioPlayer,
required this.platformHelper,
}) : focusNode = FocusNode(),
_gameBloc = gameBloc,
_audioPlayer = audioPlayer,
_characterThemeBloc = characterThemeBloc,
_l10n = l10n,
super(
gravity: Vector2(0, 30),
) {
images.prefix = '';
}
/// Identifier of the play button overlay.
static const playButtonOverlay = 'play_button';
/// Identifier of the replay button overlay.
static const replayButtonOverlay = 'replay_button';
/// Identifier of the mobile controls overlay.
static const mobileControlsOverlay = 'mobile_controls';
@override
Color backgroundColor() => Colors.transparent;
final FocusNode focusNode;
final CharacterThemeCubit _characterThemeBloc;
final PinballAudioPlayer _audioPlayer;
final LeaderboardRepository leaderboardRepository;
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
final ShareRepository shareRepository;
final AppLocalizations _l10n;
final PlatformHelper platformHelper;
final GameBloc _gameBloc;
List<LeaderboardEntryData>? _entries;
Future<void> preFetchLeaderboard() async {
try {
_entries = await leaderboardRepository.fetchTop10Leaderboard();
} catch (_) {
// An initial null leaderboard means that we couldn't fetch
// the entries for the [Backbox] and it will show the relevant display.
_entries = null;
}
}
@override
Future<void> onLoad() async {
await add(
FlameMultiBlocProvider(
providers: [
FlameBlocProvider<GameBloc, GameState>.value(
value: _gameBloc,
),
FlameBlocProvider<CharacterThemeCubit, CharacterThemeState>.value(
value: _characterThemeBloc,
),
],
children: [
MultiFlameProvider(
providers: [
FlameProvider<PinballAudioPlayer>.value(_audioPlayer),
FlameProvider<LeaderboardRepository>.value(leaderboardRepository),
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
FlameProvider<ShareRepository>.value(shareRepository),
FlameProvider<AppLocalizations>.value(_l10n),
FlameProvider<PlatformHelper>.value(platformHelper),
],
children: [
BonusNoiseBehavior(),
GameBlocStatusListener(),
BallSpawningBehavior(),
CharacterSelectionBehavior(),
CameraFocusingBehavior(),
CanvasComponent(
onSpritePainted: (paint) {
if (paint.filterQuality != FilterQuality.medium) {
paint.filterQuality = FilterQuality.medium;
}
},
children: [
ZCanvasComponent(
children: [
if (!platformHelper.isMobile) ArcadeBackground(),
BoardBackgroundSpriteComponent(),
Boundaries(),
Backbox(
leaderboardRepository: leaderboardRepository,
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
shareRepository: shareRepository,
entries: _entries,
),
GoogleGallery(),
Multipliers(),
Multiballs(),
SkillShot(
children: [
ScoringContactBehavior(points: Points.oneMillion),
RolloverNoiseBehavior(),
],
),
AndroidAcres(),
DinoDesert(),
FlutterForest(),
SparkyScorch(),
Drain(),
BottomGroup(),
Launcher(),
],
),
],
),
],
),
],
),
);
feat: migration to new `ContactCallbacks` (#234) * feat: migrated to new ContactCallbacks * refactor: moved renderBody to super call * feat: defined AlienBumper behaviours * feat: included ParentIsA mixin * refactor: modified ContactCallbacksGroup * feat: resolved missing ContactCallbacks with Behaviors * refactor: removed unused ParentIsA * refactor: moved tests * fix: invalid export * refactor: renamed behaviours * test: tested pinball_components * refactor: removed "Behaviour" typo * docs: included TODO comment for generics * docs: included flame_bloc TODO comments * refactor: renamed ContacCallbacksGroup variable * docs: included doc comments where possible * docs: rephrased ContactBehaviour doc comment * test: included ContactBehavior tests * feat: implemented FlutterForestBonusBehavior * refactor: fixed analyser warnings * test: tested DashNestBumper * refactor: moved children to last arguement * test: included closing test * refactor: used barrel files as imports * docs: included flutter_bloc TODO * test: correctly tested GoogleWordBonusBehavior * refactor: moved flutter_forest_test.dart * test: fixed AlienZone typo * feat: removed FlutterForestCubit * test: closed streams * refactor: removed optional bloc parameter * refactor: added flame_bloc TODO comment * docs: included .test constructor docs * feat: included GoogleLetter.test * test: made blink test pass * fix: renamed theme to CharacterTheme * refactor: moved timer.stop(); * refactor: renamed hasBonus to achievedBonus * refactor: ignore public_member_api_docs for cubits * test: removed beginContact group * refactor: typos correction * docs: used correct AlienBumper reference * docs: removed TODO comment from ContactBehavior subclasses * docs: includes ScoringBehavior doc * feat: adjusted FlutterForest priorities Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
await super.onLoad();
}
final focusedBoardSide = <int, BoardSide>{};
@override
void onTapDown(int pointerId, TapDownInfo info) {
if (info.raw.kind == PointerDeviceKind.touch &&
_gameBloc.state.status.isPlaying) {
final rocket = descendants().whereType<RocketSpriteComponent>().first;
final bounds = rocket.topLeftPosition & rocket.size;
final tappedRocket = bounds.contains(info.eventPosition.game.toOffset());
if (tappedRocket) {
descendants()
.whereType<FlameBlocProvider<PlungerCubit, PlungerState>>()
.first
.bloc
.autoPulled();
} else {
final tappedLeftSide = info.eventPosition.widget.x < canvasSize.x / 2;
focusedBoardSide[pointerId] =
tappedLeftSide ? BoardSide.left : BoardSide.right;
final flippers = descendants()
.whereType<Flipper>()
.where((flipper) => flipper.side == focusedBoardSide[pointerId]);
for (final flipper in flippers) {
flipper
.descendants()
.whereType<FlameBlocProvider<FlipperCubit, FlipperState>>()
.forEach((provider) => provider.bloc.moveUp());
}
}
}
super.onTapDown(pointerId, info);
}
@override
void onTapUp(int pointerId, TapUpInfo info) {
_moveFlippersDown(pointerId);
super.onTapUp(pointerId, info);
}
@override
void onTapCancel(int pointerId) {
_moveFlippersDown(pointerId);
super.onTapCancel(pointerId);
}
void _moveFlippersDown(int pointerId) {
if (focusedBoardSide[pointerId] != null) {
final flippers = descendants()
.whereType<Flipper>()
.where((flipper) => flipper.side == focusedBoardSide[pointerId]);
for (final flipper in flippers) {
flipper
.descendants()
.whereType<FlameBlocProvider<FlipperCubit, FlipperState>>()
.forEach((provider) => provider.bloc.moveDown());
}
}
}
}
class DebugPinballGame extends PinballGame with FPSCounter, PanDetector {
DebugPinballGame({
required CharacterThemeCubit characterThemeBloc,
required LeaderboardRepository leaderboardRepository,
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
required ShareRepository shareRepository,
required AppLocalizations l10n,
required PinballAudioPlayer audioPlayer,
required PlatformHelper platformHelper,
required GameBloc gameBloc,
}) : super(
characterThemeBloc: characterThemeBloc,
audioPlayer: audioPlayer,
leaderboardRepository: leaderboardRepository,
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
shareRepository: shareRepository,
l10n: l10n,
platformHelper: platformHelper,
gameBloc: gameBloc,
);
Vector2? lineStart;
Vector2? lineEnd;
@override
Future<void> onLoad() async {
await super.onLoad();
await addAll([PreviewLine(), _DebugInformation()]);
}
@override
void onTapUp(int pointerId, TapUpInfo info) {
super.onTapUp(pointerId, info);
if (info.raw.kind == PointerDeviceKind.mouse) {
final canvas = descendants().whereType<ZCanvasComponent>().single;
final ball = Ball()..initialPosition = info.eventPosition.game;
canvas.add(ball);
}
}
@override
void onPanStart(DragStartInfo info) => lineStart = info.eventPosition.game;
@override
void onPanUpdate(DragUpdateInfo info) => lineEnd = info.eventPosition.game;
@override
void onPanEnd(DragEndInfo info) {
if (lineEnd != null) {
final line = lineEnd! - lineStart!;
_turboChargeBall(line);
lineEnd = null;
lineStart = null;
}
}
void _turboChargeBall(Vector2 line) {
final canvas = descendants().whereType<ZCanvasComponent>().single;
final ball = Ball()..initialPosition = lineStart!;
final impulse = line * -1 * 10;
ball.add(BallTurboChargingBehavior(impulse: impulse));
canvas.add(ball);
}
}
// coverage:ignore-start
class PreviewLine extends PositionComponent with HasGameRef<DebugPinballGame> {
static final _previewLinePaint = Paint()
..color = Colors.pink
..strokeWidth = 0.4
..style = PaintingStyle.stroke;
@override
void render(Canvas canvas) {
super.render(canvas);
if (gameRef.lineEnd != null) {
canvas.drawLine(
gameRef.lineStart!.toOffset(),
gameRef.lineEnd!.toOffset(),
_previewLinePaint,
);
}
}
}
class _DebugInformation extends Component with HasGameRef<DebugPinballGame> {
@override
PositionType get positionType => PositionType.widget;
final _debugTextPaint = TextPaint(
style: const TextStyle(
color: Colors.green,
fontSize: 10,
),
);
final _debugBackgroundPaint = Paint()..color = Colors.white;
@override
void render(Canvas canvas) {
final debugText = [
'FPS: ${gameRef.fps().toStringAsFixed(1)}',
'BALLS: ${gameRef.descendants().whereType<Ball>().length}',
].join(' | ');
final height = _debugTextPaint.measureTextHeight(debugText);
final position = Vector2(0, gameRef.camera.canvasSize.y - height);
canvas.drawRect(
position & Vector2(gameRef.camera.canvasSize.x, height),
_debugBackgroundPaint,
);
_debugTextPaint.render(canvas, debugText, position);
}
}
// coverage:ignore-end