@ -0,0 +1,20 @@
|
||||
name: pinball_flame
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- "packages/pinball_flame/**"
|
||||
- ".github/workflows/pinball_flame.yaml"
|
||||
|
||||
pull_request:
|
||||
paths:
|
||||
- "packages/pinball_flame/**"
|
||||
- ".github/workflows/pinball_flame.yaml"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
|
||||
with:
|
||||
working_directory: packages/pinball_flame
|
||||
coverage_excludes: "lib/gen/*.dart"
|
||||
test_optimization: false
|
Before Width: | Height: | Size: 9.7 MiB After Width: | Height: | Size: 3.2 MiB |
@ -1 +0,0 @@
|
||||
export 'component_controller.dart';
|
@ -1,208 +0,0 @@
|
||||
// ignore_for_file: avoid_renaming_method_parameters
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/effects.dart';
|
||||
import 'package:flame_bloc/flame_bloc.dart';
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
|
||||
/// {@template bonus_word}
|
||||
/// Loads all [BonusLetter]s to compose a [BonusWord].
|
||||
/// {@endtemplate}
|
||||
class BonusWord extends Component
|
||||
with BlocComponent<GameBloc, GameState>, HasGameRef<PinballGame> {
|
||||
/// {@macro bonus_word}
|
||||
BonusWord({required Vector2 position}) : _position = position;
|
||||
|
||||
final Vector2 _position;
|
||||
|
||||
@override
|
||||
bool listenWhen(GameState? previousState, GameState newState) {
|
||||
return (previousState?.bonusHistory.length ?? 0) <
|
||||
newState.bonusHistory.length &&
|
||||
newState.bonusHistory.last == GameBonus.word;
|
||||
}
|
||||
|
||||
@override
|
||||
void onNewState(GameState state) {
|
||||
if (state.bonusHistory.last == GameBonus.word) {
|
||||
gameRef.audio.googleBonus();
|
||||
|
||||
final letters = children.whereType<BonusLetter>().toList();
|
||||
|
||||
for (var i = 0; i < letters.length; i++) {
|
||||
final letter = letters[i];
|
||||
letter
|
||||
..isEnabled = false
|
||||
..add(
|
||||
SequenceEffect(
|
||||
[
|
||||
ColorEffect(
|
||||
i.isOdd
|
||||
? BonusLetter._activeColor
|
||||
: BonusLetter._disableColor,
|
||||
const Offset(0, 1),
|
||||
EffectController(duration: 0.25),
|
||||
),
|
||||
ColorEffect(
|
||||
i.isOdd
|
||||
? BonusLetter._disableColor
|
||||
: BonusLetter._activeColor,
|
||||
const Offset(0, 1),
|
||||
EffectController(duration: 0.25),
|
||||
),
|
||||
],
|
||||
repeatCount: 4,
|
||||
)..onFinishCallback = () {
|
||||
letter
|
||||
..isEnabled = true
|
||||
..add(
|
||||
ColorEffect(
|
||||
BonusLetter._disableColor,
|
||||
const Offset(0, 1),
|
||||
EffectController(duration: 0.25),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
|
||||
final offsets = [
|
||||
Vector2(-12.92, -1.82),
|
||||
Vector2(-8.33, 0.65),
|
||||
Vector2(-2.88, 1.75),
|
||||
];
|
||||
offsets.addAll(
|
||||
offsets.reversed
|
||||
.map(
|
||||
(offset) => Vector2(-offset.x, offset.y),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
assert(offsets.length == GameBloc.bonusWord.length, 'Invalid positions');
|
||||
|
||||
final letters = <BonusLetter>[];
|
||||
for (var i = 0; i < GameBloc.bonusWord.length; i++) {
|
||||
letters.add(
|
||||
BonusLetter(
|
||||
letter: GameBloc.bonusWord[i],
|
||||
index: i,
|
||||
)..initialPosition = _position + offsets[i],
|
||||
);
|
||||
}
|
||||
|
||||
await addAll(letters);
|
||||
}
|
||||
}
|
||||
|
||||
/// {@template bonus_letter}
|
||||
/// [BodyType.static] sensor component, part of a word bonus,
|
||||
/// which will activate its letter after contact with a [Ball].
|
||||
/// {@endtemplate}
|
||||
class BonusLetter extends BodyComponent<PinballGame>
|
||||
with BlocComponent<GameBloc, GameState>, InitialPosition {
|
||||
/// {@macro bonus_letter}
|
||||
BonusLetter({
|
||||
required String letter,
|
||||
required int index,
|
||||
}) : _letter = letter,
|
||||
_index = index {
|
||||
paint = Paint()..color = _disableColor;
|
||||
}
|
||||
|
||||
/// The size of the [BonusLetter].
|
||||
static final size = Vector2.all(3.7);
|
||||
|
||||
static const _activeColor = Colors.green;
|
||||
static const _disableColor = Colors.red;
|
||||
|
||||
final String _letter;
|
||||
final int _index;
|
||||
|
||||
/// Indicates if a [BonusLetter] can be activated on [Ball] contact.
|
||||
///
|
||||
/// It is disabled whilst animating and enabled again once the animation
|
||||
/// completes. The animation is triggered when [GameBonus.word] is
|
||||
/// awarded.
|
||||
bool isEnabled = true;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
|
||||
await add(
|
||||
TextComponent(
|
||||
position: Vector2(-1, -1),
|
||||
text: _letter,
|
||||
textRenderer: TextPaint(
|
||||
style: const TextStyle(fontSize: 2, color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Body createBody() {
|
||||
final shape = CircleShape()..radius = size.x / 2;
|
||||
|
||||
final fixtureDef = FixtureDef(shape)..isSensor = true;
|
||||
|
||||
final bodyDef = BodyDef()
|
||||
..position = initialPosition
|
||||
..userData = this
|
||||
..type = BodyType.static;
|
||||
|
||||
return world.createBody(bodyDef)..createFixture(fixtureDef);
|
||||
}
|
||||
|
||||
@override
|
||||
bool listenWhen(GameState? previousState, GameState newState) {
|
||||
final wasActive = previousState?.isLetterActivated(_index) ?? false;
|
||||
final isActive = newState.isLetterActivated(_index);
|
||||
|
||||
return wasActive != isActive;
|
||||
}
|
||||
|
||||
@override
|
||||
void onNewState(GameState state) {
|
||||
final isActive = state.isLetterActivated(_index);
|
||||
|
||||
add(
|
||||
ColorEffect(
|
||||
isActive ? _activeColor : _disableColor,
|
||||
const Offset(0, 1),
|
||||
EffectController(duration: 0.25),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Activates this [BonusLetter], if it's not already activated.
|
||||
void activate() {
|
||||
final isActive = state?.isLetterActivated(_index) ?? false;
|
||||
if (!isActive) {
|
||||
gameRef.read<GameBloc>().add(BonusLetterActivated(_index));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Triggers [BonusLetter.activate] method when a [BonusLetter] and a [Ball]
|
||||
/// come in contact.
|
||||
class BonusLetterBallContactCallback
|
||||
extends ContactCallback<Ball, BonusLetter> {
|
||||
@override
|
||||
void begin(Ball ball, BonusLetter bonusLetter, Contact contact) {
|
||||
if (bonusLetter.isEnabled) {
|
||||
bonusLetter.activate();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
// ignore_for_file: avoid_renaming_method_parameters
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
/// {@template google_word}
|
||||
/// Loads all [GoogleLetter]s to compose a [GoogleWord].
|
||||
/// {@endtemplate}
|
||||
class GoogleWord extends Component
|
||||
with HasGameRef<PinballGame>, Controls<_GoogleWordController> {
|
||||
/// {@macro google_word}
|
||||
GoogleWord({
|
||||
required Vector2 position,
|
||||
}) : _position = position {
|
||||
controller = _GoogleWordController(this);
|
||||
}
|
||||
|
||||
final Vector2 _position;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
gameRef.addContactCallback(_GoogleLetterBallContactCallback());
|
||||
|
||||
final offsets = [
|
||||
Vector2(-12.92, 1.82),
|
||||
Vector2(-8.33, -0.65),
|
||||
Vector2(-2.88, -1.75),
|
||||
Vector2(2.88, -1.75),
|
||||
Vector2(8.33, -0.65),
|
||||
Vector2(12.92, 1.82),
|
||||
];
|
||||
|
||||
final letters = <GoogleLetter>[];
|
||||
for (var index = 0; index < offsets.length; index++) {
|
||||
letters.add(
|
||||
GoogleLetter(index)..initialPosition = _position + offsets[index],
|
||||
);
|
||||
}
|
||||
|
||||
await addAll(letters);
|
||||
}
|
||||
}
|
||||
|
||||
class _GoogleWordController extends ComponentController<GoogleWord>
|
||||
with HasGameRef<PinballGame> {
|
||||
_GoogleWordController(GoogleWord googleWord) : super(googleWord);
|
||||
|
||||
final _activatedLetters = <GoogleLetter>{};
|
||||
|
||||
void activate(GoogleLetter googleLetter) {
|
||||
if (!_activatedLetters.add(googleLetter)) return;
|
||||
|
||||
googleLetter.activate();
|
||||
|
||||
final activatedBonus = _activatedLetters.length == 6;
|
||||
if (activatedBonus) {
|
||||
gameRef.audio.googleBonus();
|
||||
gameRef.read<GameBloc>().add(const BonusActivated(GameBonus.googleWord));
|
||||
component.children.whereType<GoogleLetter>().forEach(
|
||||
(letter) => letter.deactivate(),
|
||||
);
|
||||
_activatedLetters.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Activates a [GoogleLetter] when it contacts with a [Ball].
|
||||
class _GoogleLetterBallContactCallback
|
||||
extends ContactCallback<GoogleLetter, Ball> {
|
||||
@override
|
||||
void begin(GoogleLetter googleLetter, _, __) {
|
||||
final parent = googleLetter.parent;
|
||||
if (parent is GoogleWord) {
|
||||
parent.controller.activate(googleLetter);
|
||||
}
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
@ -1,40 +0,0 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
|
||||
/// {@template backboard}
|
||||
/// The [Backboard] of the pinball machine.
|
||||
/// {@endtemplate}
|
||||
class Backboard extends SpriteComponent with HasGameRef {
|
||||
/// {@macro backboard}
|
||||
Backboard({
|
||||
required Vector2 position,
|
||||
}) : super(
|
||||
// TODO(erickzanardo): remove multiply after
|
||||
// https://github.com/flame-engine/flame/pull/1506 is merged
|
||||
position: position..clone().multiply(Vector2(1, -1)),
|
||||
anchor: Anchor.bottomCenter,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await waitingMode();
|
||||
}
|
||||
|
||||
/// Puts the Backboard in waiting mode, where the scoreboard is shown.
|
||||
Future<void> waitingMode() async {
|
||||
final sprite = await gameRef.loadSprite(
|
||||
Assets.images.backboard.backboardScores.keyName,
|
||||
);
|
||||
size = sprite.originalSize / 10;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
/// Puts the Backboard in game over mode, where the score input is shown.
|
||||
Future<void> gameOverMode() async {
|
||||
final sprite = await gameRef.loadSprite(
|
||||
Assets.images.backboard.backboardGameOver.keyName,
|
||||
);
|
||||
size = sprite.originalSize / 10;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
|
||||
export 'backboard_game_over.dart';
|
||||
export 'backboard_letter_prompt.dart';
|
||||
export 'backboard_waiting.dart';
|
||||
|
||||
/// {@template backboard}
|
||||
/// The [Backboard] of the pinball machine.
|
||||
/// {@endtemplate}
|
||||
class Backboard extends PositionComponent with HasGameRef {
|
||||
/// {@macro backboard}
|
||||
Backboard({
|
||||
required Vector2 position,
|
||||
}) : super(
|
||||
position: position,
|
||||
anchor: Anchor.bottomCenter,
|
||||
);
|
||||
|
||||
/// {@macro backboard}
|
||||
///
|
||||
/// Returns a [Backboard] initialized in the waiting mode
|
||||
factory Backboard.waiting({
|
||||
required Vector2 position,
|
||||
}) {
|
||||
return Backboard(position: position)..waitingMode();
|
||||
}
|
||||
|
||||
/// {@macro backboard}
|
||||
///
|
||||
/// Returns a [Backboard] initialized in the game over mode
|
||||
factory Backboard.gameOver({
|
||||
required Vector2 position,
|
||||
required int score,
|
||||
required BackboardOnSubmit onSubmit,
|
||||
}) {
|
||||
return Backboard(position: position)
|
||||
..gameOverMode(
|
||||
score: score,
|
||||
onSubmit: onSubmit,
|
||||
);
|
||||
}
|
||||
|
||||
/// [TextPaint] used on the [Backboard]
|
||||
static final textPaint = TextPaint(
|
||||
style: TextStyle(
|
||||
fontSize: 6,
|
||||
color: Colors.white,
|
||||
fontFamily: PinballFonts.pixeloidSans,
|
||||
),
|
||||
);
|
||||
|
||||
/// Puts the Backboard in waiting mode, where the scoreboard is shown.
|
||||
Future<void> waitingMode() async {
|
||||
children.removeWhere((_) => true);
|
||||
await add(BackboardWaiting());
|
||||
}
|
||||
|
||||
/// Puts the Backboard in game over mode, where the score input is shown.
|
||||
Future<void> gameOverMode({
|
||||
required int score,
|
||||
BackboardOnSubmit? onSubmit,
|
||||
}) async {
|
||||
children.removeWhere((_) => true);
|
||||
await add(
|
||||
BackboardGameOver(
|
||||
score: score,
|
||||
onSubmit: onSubmit,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
/// Signature for the callback called when the used has
|
||||
/// submettied their initials on the [BackboardGameOver]
|
||||
typedef BackboardOnSubmit = void Function(String);
|
||||
|
||||
/// {@template backboard_game_over}
|
||||
/// [PositionComponent] that handles the user input on the
|
||||
/// game over display view.
|
||||
/// {@endtemplate}
|
||||
class BackboardGameOver extends PositionComponent with HasGameRef {
|
||||
/// {@macro backboard_game_over}
|
||||
BackboardGameOver({
|
||||
required int score,
|
||||
BackboardOnSubmit? onSubmit,
|
||||
}) : _score = score,
|
||||
_onSubmit = onSubmit;
|
||||
|
||||
final int _score;
|
||||
final BackboardOnSubmit? _onSubmit;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
final backgroundSprite = await gameRef.loadSprite(
|
||||
Assets.images.backboard.backboardGameOver.keyName,
|
||||
);
|
||||
|
||||
unawaited(
|
||||
add(
|
||||
SpriteComponent(
|
||||
sprite: backgroundSprite,
|
||||
size: backgroundSprite.originalSize / 10,
|
||||
anchor: Anchor.bottomCenter,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final displaySprite = await gameRef.loadSprite(
|
||||
Assets.images.backboard.display.keyName,
|
||||
);
|
||||
|
||||
unawaited(
|
||||
add(
|
||||
SpriteComponent(
|
||||
sprite: displaySprite,
|
||||
size: displaySprite.originalSize / 10,
|
||||
anchor: Anchor.bottomCenter,
|
||||
position: Vector2(0, -11.5),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
unawaited(
|
||||
add(
|
||||
TextComponent(
|
||||
text: _score.formatScore(),
|
||||
position: Vector2(-22, -46.5),
|
||||
anchor: Anchor.center,
|
||||
textRenderer: Backboard.textPaint,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
for (var i = 0; i < 3; i++) {
|
||||
unawaited(
|
||||
add(
|
||||
BackboardLetterPrompt(
|
||||
position: Vector2(
|
||||
20 + (6 * i).toDouble(),
|
||||
-46.5,
|
||||
),
|
||||
hasFocus: i == 0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
unawaited(
|
||||
add(
|
||||
KeyboardInputController(
|
||||
keyUp: {
|
||||
LogicalKeyboardKey.arrowLeft: () => _movePrompt(true),
|
||||
LogicalKeyboardKey.arrowRight: () => _movePrompt(false),
|
||||
LogicalKeyboardKey.enter: _submit,
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the current inputed initials
|
||||
String get initials => children
|
||||
.whereType<BackboardLetterPrompt>()
|
||||
.map((prompt) => prompt.char)
|
||||
.join();
|
||||
|
||||
bool _submit() {
|
||||
_onSubmit?.call(initials);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _movePrompt(bool left) {
|
||||
final prompts = children.whereType<BackboardLetterPrompt>().toList();
|
||||
|
||||
final current = prompts.firstWhere((prompt) => prompt.hasFocus)
|
||||
..hasFocus = false;
|
||||
var index = prompts.indexOf(current) + (left ? -1 : 1);
|
||||
index = min(max(0, index), prompts.length - 1);
|
||||
|
||||
prompts[index].hasFocus = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_flame/pinball_flame.dart';
|
||||
|
||||
/// {@template backboard_letter_prompt}
|
||||
/// A [PositionComponent] that renders a letter prompt used
|
||||
/// on the [BackboardGameOver]
|
||||
/// {@endtemplate}
|
||||
class BackboardLetterPrompt extends PositionComponent {
|
||||
/// {@macro backboard_letter_prompt}
|
||||
BackboardLetterPrompt({
|
||||
required Vector2 position,
|
||||
bool hasFocus = false,
|
||||
}) : _hasFocus = hasFocus,
|
||||
super(
|
||||
position: position,
|
||||
);
|
||||
|
||||
static const _alphabetCode = 65;
|
||||
static const _alphabetLength = 25;
|
||||
var _charIndex = 0;
|
||||
|
||||
bool _hasFocus;
|
||||
|
||||
late RectangleComponent _underscore;
|
||||
late TextComponent _input;
|
||||
late TimerComponent _underscoreBlinker;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
_underscore = RectangleComponent(
|
||||
size: Vector2(
|
||||
4,
|
||||
1.2,
|
||||
),
|
||||
anchor: Anchor.center,
|
||||
position: Vector2(0, 4),
|
||||
);
|
||||
|
||||
unawaited(add(_underscore));
|
||||
|
||||
_input = TextComponent(
|
||||
text: 'A',
|
||||
textRenderer: Backboard.textPaint,
|
||||
anchor: Anchor.center,
|
||||
);
|
||||
unawaited(add(_input));
|
||||
|
||||
_underscoreBlinker = TimerComponent(
|
||||
period: 0.6,
|
||||
repeat: true,
|
||||
autoStart: _hasFocus,
|
||||
onTick: () {
|
||||
_underscore.paint.color = (_underscore.paint.color == Colors.white)
|
||||
? Colors.transparent
|
||||
: Colors.white;
|
||||
},
|
||||
);
|
||||
|
||||
unawaited(add(_underscoreBlinker));
|
||||
|
||||
unawaited(
|
||||
add(
|
||||
KeyboardInputController(
|
||||
keyUp: {
|
||||
LogicalKeyboardKey.arrowUp: () => _cycle(true),
|
||||
LogicalKeyboardKey.arrowDown: () => _cycle(false),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns the current selected character
|
||||
String get char => String.fromCharCode(_alphabetCode + _charIndex);
|
||||
|
||||
bool _cycle(bool up) {
|
||||
if (_hasFocus) {
|
||||
final newCharCode =
|
||||
min(max(_charIndex + (up ? 1 : -1), 0), _alphabetLength);
|
||||
_input.text = String.fromCharCode(_alphabetCode + newCharCode);
|
||||
_charIndex = newCharCode;
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns if this prompt has focus on it
|
||||
bool get hasFocus => _hasFocus;
|
||||
|
||||
/// Updates this prompt focus
|
||||
set hasFocus(bool hasFocus) {
|
||||
if (hasFocus) {
|
||||
_underscoreBlinker.timer.resume();
|
||||
} else {
|
||||
_underscoreBlinker.timer.pause();
|
||||
}
|
||||
_underscore.paint.color = Colors.white;
|
||||
_hasFocus = hasFocus;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
|
||||
/// [PositionComponent] that shows the leaderboard while the player
|
||||
/// has not started the game yet.
|
||||
class BackboardWaiting extends SpriteComponent with HasGameRef {
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
final sprite = await gameRef.loadSprite(
|
||||
Assets.images.backboard.backboardScores.keyName,
|
||||
);
|
||||
|
||||
this.sprite = sprite;
|
||||
size = sprite.originalSize / 10;
|
||||
anchor = Anchor.bottomCenter;
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
export 'score.dart';
|
@ -0,0 +1,11 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
final _numberFormat = NumberFormat('#,###');
|
||||
|
||||
/// Adds score related extensions to int
|
||||
extension ScoreX on int {
|
||||
/// Formats this number as a score value
|
||||
String formatScore() {
|
||||
return _numberFormat.format(this);
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
export 'blueprint.dart';
|
||||
export 'priority.dart';
|
@ -1,2 +1,2 @@
|
||||
export 'components/components.dart';
|
||||
export 'flame/flame.dart';
|
||||
export 'extensions/extensions.dart';
|
||||
|
@ -0,0 +1,37 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
|
||||
class BackboardGameOverGame extends BasicKeyboardGame {
|
||||
BackboardGameOverGame(this.score);
|
||||
|
||||
static const info = '''
|
||||
Simple example showing the waiting mode of the backboard.
|
||||
''';
|
||||
|
||||
final int score;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
camera
|
||||
..followVector2(Vector2.zero())
|
||||
..zoom = 5;
|
||||
|
||||
await add(
|
||||
Backboard.gameOver(
|
||||
position: Vector2(0, 20),
|
||||
score: score,
|
||||
onSubmit: (initials) {
|
||||
add(
|
||||
ScoreText(
|
||||
text: 'User $initials made $score',
|
||||
position: Vector2(0, 50),
|
||||
color: Colors.pink,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
import 'package:dashbook/dashbook.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
import 'package:sandbox/stories/backboard/game_over.dart';
|
||||
import 'package:sandbox/stories/backboard/waiting.dart';
|
||||
|
||||
void addBackboardStories(Dashbook dashbook) {
|
||||
dashbook.storiesOf('Backboard')
|
||||
..add(
|
||||
'Waiting mode',
|
||||
(context) => GameWidget(
|
||||
game: BackboardWaitingGame(),
|
||||
),
|
||||
codeLink: buildSourceLink('backboard/waiting.dart'),
|
||||
info: BackboardWaitingGame.info,
|
||||
)
|
||||
..add(
|
||||
'Game over',
|
||||
(context) => GameWidget(
|
||||
game: BackboardGameOverGame(
|
||||
context.numberProperty('score', 9000000000).toInt(),
|
||||
),
|
||||
),
|
||||
codeLink: buildSourceLink('backboard/game_over.dart'),
|
||||
info: BackboardGameOverGame.info,
|
||||
);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:sandbox/common/common.dart';
|
||||
|
||||
class BackboardWaitingGame extends BasicGame {
|
||||
static const info = '''
|
||||
Simple example showing the waiting mode of the backboard.
|
||||
''';
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
camera
|
||||
..followVector2(Vector2.zero())
|
||||
..zoom = 5;
|
||||
|
||||
final backboard = Backboard.waiting(position: Vector2(0, 20));
|
||||
await add(backboard);
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 79 KiB |
Before Width: | Height: | Size: 913 KiB |
Before Width: | Height: | Size: 894 KiB |
Before Width: | Height: | Size: 844 KiB |
Before Width: | Height: | Size: 427 KiB |
After Width: | Height: | Size: 247 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 63 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |