chore: add google letter assets

pull/286/head
Allison Ryan 3 years ago
parent 36c1afe80d
commit 1d34d0105b

@ -53,7 +53,7 @@ class _GoogleWordController extends ComponentController<GoogleWord>
final _activatedLetters = <GoogleLetter>{}; final _activatedLetters = <GoogleLetter>{};
void activate(GoogleLetter googleLetter) { Future<void> activate(GoogleLetter googleLetter) async {
if (!_activatedLetters.add(googleLetter)) return; if (!_activatedLetters.add(googleLetter)) return;
googleLetter.activate(); googleLetter.activate();
@ -62,12 +62,30 @@ class _GoogleWordController extends ComponentController<GoogleWord>
if (activatedBonus) { if (activatedBonus) {
gameRef.audio.googleBonus(); gameRef.audio.googleBonus();
gameRef.read<GameBloc>().add(const BonusActivated(GameBonus.googleWord)); gameRef.read<GameBloc>().add(const BonusActivated(GameBonus.googleWord));
component.children.whereType<GoogleLetter>().forEach( await _bonusAnimation();
(letter) => letter.deactivate(),
);
_activatedLetters.clear(); _activatedLetters.clear();
} }
} }
Future<void> _bonusAnimation() async {
const blinkDuration = Duration(milliseconds: 300);
const blinkCount = 4;
final googleLetters = component.children.whereType<GoogleLetter>();
var shouldActivate = false;
await Future<void>.delayed(blinkDuration);
for (var i = 1; i < blinkCount * 2; i++) {
for (final letter in googleLetters) {
if (shouldActivate) {
letter.activate();
} else {
letter.deactivate();
}
}
shouldActivate = !shouldActivate;
await Future<void>.delayed(blinkDuration);
}
}
} }
/// Activates a [GoogleLetter] when it contacts with a [Ball]. /// Activates a [GoogleLetter] when it contacts with a [Ball].

@ -94,12 +94,18 @@ extension PinballGameAssetsX on PinballGame {
images.load(components.Assets.images.sparky.bumper.c.inactive.keyName), images.load(components.Assets.images.sparky.bumper.c.inactive.keyName),
images.load(components.Assets.images.backboard.backboardScores.keyName), images.load(components.Assets.images.backboard.backboardScores.keyName),
images.load(components.Assets.images.backboard.backboardGameOver.keyName), images.load(components.Assets.images.backboard.backboardGameOver.keyName),
images.load(components.Assets.images.googleWord.letter1.keyName), images.load(components.Assets.images.googleWord.letter1.active.keyName),
images.load(components.Assets.images.googleWord.letter2.keyName), images.load(components.Assets.images.googleWord.letter1.inactive.keyName),
images.load(components.Assets.images.googleWord.letter3.keyName), images.load(components.Assets.images.googleWord.letter2.active.keyName),
images.load(components.Assets.images.googleWord.letter4.keyName), images.load(components.Assets.images.googleWord.letter2.inactive.keyName),
images.load(components.Assets.images.googleWord.letter5.keyName), images.load(components.Assets.images.googleWord.letter3.active.keyName),
images.load(components.Assets.images.googleWord.letter6.keyName), images.load(components.Assets.images.googleWord.letter3.inactive.keyName),
images.load(components.Assets.images.googleWord.letter4.active.keyName),
images.load(components.Assets.images.googleWord.letter4.inactive.keyName),
images.load(components.Assets.images.googleWord.letter5.active.keyName),
images.load(components.Assets.images.googleWord.letter5.inactive.keyName),
images.load(components.Assets.images.googleWord.letter6.active.keyName),
images.load(components.Assets.images.googleWord.letter6.inactive.keyName),
images.load(components.Assets.images.backboard.display.keyName), images.load(components.Assets.images.backboard.display.keyName),
images.load(dashTheme.leaderboardIcon.keyName), images.load(dashTheme.leaderboardIcon.keyName),
images.load(sparkyTheme.leaderboardIcon.keyName), images.load(sparkyTheme.leaderboardIcon.keyName),

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

@ -144,29 +144,18 @@ class $AssetsImagesFlipperGen {
class $AssetsImagesGoogleWordGen { class $AssetsImagesGoogleWordGen {
const $AssetsImagesGoogleWordGen(); const $AssetsImagesGoogleWordGen();
/// File path: assets/images/google_word/letter1.png $AssetsImagesGoogleWordLetter1Gen get letter1 =>
AssetGenImage get letter1 => const $AssetsImagesGoogleWordLetter1Gen();
const AssetGenImage('assets/images/google_word/letter1.png'); $AssetsImagesGoogleWordLetter2Gen get letter2 =>
const $AssetsImagesGoogleWordLetter2Gen();
/// File path: assets/images/google_word/letter2.png $AssetsImagesGoogleWordLetter3Gen get letter3 =>
AssetGenImage get letter2 => const $AssetsImagesGoogleWordLetter3Gen();
const AssetGenImage('assets/images/google_word/letter2.png'); $AssetsImagesGoogleWordLetter4Gen get letter4 =>
const $AssetsImagesGoogleWordLetter4Gen();
/// File path: assets/images/google_word/letter3.png $AssetsImagesGoogleWordLetter5Gen get letter5 =>
AssetGenImage get letter3 => const $AssetsImagesGoogleWordLetter5Gen();
const AssetGenImage('assets/images/google_word/letter3.png'); $AssetsImagesGoogleWordLetter6Gen get letter6 =>
const $AssetsImagesGoogleWordLetter6Gen();
/// File path: assets/images/google_word/letter4.png
AssetGenImage get letter4 =>
const AssetGenImage('assets/images/google_word/letter4.png');
/// File path: assets/images/google_word/letter5.png
AssetGenImage get letter5 =>
const AssetGenImage('assets/images/google_word/letter5.png');
/// File path: assets/images/google_word/letter6.png
AssetGenImage get letter6 =>
const AssetGenImage('assets/images/google_word/letter6.png');
} }
class $AssetsImagesKickerGen { class $AssetsImagesKickerGen {
@ -302,6 +291,78 @@ class $AssetsImagesDashBumperGen {
const $AssetsImagesDashBumperMainGen(); const $AssetsImagesDashBumperMainGen();
} }
class $AssetsImagesGoogleWordLetter1Gen {
const $AssetsImagesGoogleWordLetter1Gen();
/// File path: assets/images/google_word/letter1/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/google_word/letter1/active.png');
/// File path: assets/images/google_word/letter1/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/google_word/letter1/inactive.png');
}
class $AssetsImagesGoogleWordLetter2Gen {
const $AssetsImagesGoogleWordLetter2Gen();
/// File path: assets/images/google_word/letter2/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/google_word/letter2/active.png');
/// File path: assets/images/google_word/letter2/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/google_word/letter2/inactive.png');
}
class $AssetsImagesGoogleWordLetter3Gen {
const $AssetsImagesGoogleWordLetter3Gen();
/// File path: assets/images/google_word/letter3/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/google_word/letter3/active.png');
/// File path: assets/images/google_word/letter3/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/google_word/letter3/inactive.png');
}
class $AssetsImagesGoogleWordLetter4Gen {
const $AssetsImagesGoogleWordLetter4Gen();
/// File path: assets/images/google_word/letter4/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/google_word/letter4/active.png');
/// File path: assets/images/google_word/letter4/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/google_word/letter4/inactive.png');
}
class $AssetsImagesGoogleWordLetter5Gen {
const $AssetsImagesGoogleWordLetter5Gen();
/// File path: assets/images/google_word/letter5/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/google_word/letter5/active.png');
/// File path: assets/images/google_word/letter5/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/google_word/letter5/inactive.png');
}
class $AssetsImagesGoogleWordLetter6Gen {
const $AssetsImagesGoogleWordLetter6Gen();
/// File path: assets/images/google_word/letter6/active.png
AssetGenImage get active =>
const AssetGenImage('assets/images/google_word/letter6/active.png');
/// File path: assets/images/google_word/letter6/inactive.png
AssetGenImage get inactive =>
const AssetGenImage('assets/images/google_word/letter6/inactive.png');
}
class $AssetsImagesSpaceshipRailGen { class $AssetsImagesSpaceshipRailGen {
const $AssetsImagesSpaceshipRailGen(); const $AssetsImagesSpaceshipRailGen();

@ -1,5 +1,4 @@
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pinball_components/pinball_components.dart'; import 'package:pinball_components/pinball_components.dart';
@ -10,19 +9,17 @@ import 'package:pinball_components/pinball_components.dart';
class GoogleLetter extends BodyComponent with InitialPosition { class GoogleLetter extends BodyComponent with InitialPosition {
/// {@macro google_letter} /// {@macro google_letter}
GoogleLetter(int index) GoogleLetter(int index)
: _sprite = _GoogleLetterSprite( : _sprite = _GoogleLetterSpriteGroupComponent(
_GoogleLetterSprite.spritePaths[index], _GoogleLetterSpriteGroupComponent.spritePaths[index],
); );
final _GoogleLetterSprite _sprite; final _GoogleLetterSpriteGroupComponent _sprite;
/// Activates this [GoogleLetter]. /// Displays active sprite for this [GoogleLetter].
// TODO(alestiago): Improve doc comment once activate and deactivate void activate() => _sprite.activate();
// are implemented with the actual assets.
Future<void> activate() => _sprite.activate();
/// Deactivates this [GoogleLetter]. /// Displays inactive sprite for this [GoogleLetter].
Future<void> deactivate() => _sprite.deactivate(); void deactivate() => _sprite.deactivate();
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
@ -46,53 +43,90 @@ class GoogleLetter extends BodyComponent with InitialPosition {
} }
} }
class _GoogleLetterSprite extends SpriteComponent with HasGameRef { /// Indicates the [GoogleLetter]'s current sprite state.
_GoogleLetterSprite(String path) : _path = path; @visibleForTesting
enum GoogleLetterSpriteState {
/// A lit up letter.
active,
static final spritePaths = [ /// A dimmed letter.
Assets.images.googleWord.letter1.keyName, inactive,
Assets.images.googleWord.letter2.keyName, }
Assets.images.googleWord.letter3.keyName,
Assets.images.googleWord.letter4.keyName, class _GoogleLetterSpriteGroupComponent
Assets.images.googleWord.letter5.keyName, extends SpriteGroupComponent<GoogleLetterSpriteState> with HasGameRef {
Assets.images.googleWord.letter6.keyName, _GoogleLetterSpriteGroupComponent(
Map<GoogleLetterSpriteState, String> statePaths,
) : _statePaths = statePaths,
super(anchor: Anchor.center);
static final spritePaths = <Map<GoogleLetterSpriteState, String>>[
{
GoogleLetterSpriteState.active:
Assets.images.googleWord.letter1.active.keyName,
GoogleLetterSpriteState.inactive:
Assets.images.googleWord.letter1.inactive.keyName,
},
{
GoogleLetterSpriteState.active:
Assets.images.googleWord.letter2.active.keyName,
GoogleLetterSpriteState.inactive:
Assets.images.googleWord.letter2.inactive.keyName,
},
{
GoogleLetterSpriteState.active:
Assets.images.googleWord.letter3.active.keyName,
GoogleLetterSpriteState.inactive:
Assets.images.googleWord.letter3.inactive.keyName,
},
{
GoogleLetterSpriteState.active:
Assets.images.googleWord.letter4.active.keyName,
GoogleLetterSpriteState.inactive:
Assets.images.googleWord.letter4.inactive.keyName,
},
{
GoogleLetterSpriteState.active:
Assets.images.googleWord.letter5.active.keyName,
GoogleLetterSpriteState.inactive:
Assets.images.googleWord.letter5.inactive.keyName,
},
{
GoogleLetterSpriteState.active:
Assets.images.googleWord.letter6.active.keyName,
GoogleLetterSpriteState.inactive:
Assets.images.googleWord.letter6.inactive.keyName,
},
]; ];
final String _path; final Map<GoogleLetterSpriteState, String> _statePaths;
// TODO(alestiago): Correctly implement activate and deactivate once the void activate() {
// assets are provided. current = GoogleLetterSpriteState.active;
Future<void> activate() async {
await add(
_GoogleLetterColorEffect(color: Colors.green),
);
} }
Future<void> deactivate() async { void deactivate() {
await add( current = GoogleLetterSpriteState.inactive;
_GoogleLetterColorEffect(color: Colors.red),
);
} }
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
// TODO(alestiago): Used cached assets. paint = Paint()..isAntiAlias = false;
final sprite = await gameRef.loadSprite(_path);
this.sprite = sprite;
// TODO(alestiago): Size correctly once the assets are provided.
size = sprite.originalSize / 5;
anchor = Anchor.center;
}
}
class _GoogleLetterColorEffect extends ColorEffect { final sprites = {
_GoogleLetterColorEffect({ GoogleLetterSpriteState.active: Sprite(
required Color color, gameRef.images.fromCache(_statePaths[GoogleLetterSpriteState.active]!),
}) : super( ),
color, GoogleLetterSpriteState.inactive: Sprite(
const Offset(0, 1), gameRef.images
EffectController(duration: 0.25), .fromCache(_statePaths[GoogleLetterSpriteState.inactive]!),
); ),
};
this.sprites = sprites;
current = GoogleLetterSpriteState.inactive;
size = sprites[current]!.originalSize / 10;
}
} }

@ -67,7 +67,12 @@ flutter:
- assets/images/sparky/bumper/b/ - assets/images/sparky/bumper/b/
- assets/images/sparky/bumper/c/ - assets/images/sparky/bumper/c/
- assets/images/backboard/ - assets/images/backboard/
- assets/images/google_word/ - assets/images/google_word/letter1/
- assets/images/google_word/letter2/
- assets/images/google_word/letter3/
- assets/images/google_word/letter4/
- assets/images/google_word/letter5/
- assets/images/google_word/letter6/
- assets/images/signpost/ - assets/images/signpost/
flutter_gen: flutter_gen:

Loading…
Cancel
Save