refactor: modified ball assets for sandbox

pull/279/head
RuiAlonso 3 years ago
parent 0fbb4b4fc5
commit ccf9b33d67

@ -24,6 +24,14 @@ abstract class AssetsGame extends Forge2DGame {
} }
abstract class LineGame extends AssetsGame with PanDetector { abstract class LineGame extends AssetsGame with PanDetector {
LineGame({
List<String>? imagesFileNames,
}) : super(
imagesFileNames: [
if (imagesFileNames != null) ...imagesFileNames,
],
);
Vector2? _lineEnd; Vector2? _lineEnd;
@override @override

@ -4,6 +4,18 @@ import 'package:pinball_components/pinball_components.dart';
import 'package:sandbox/common/common.dart'; import 'package:sandbox/common/common.dart';
class BallBoosterGame extends LineGame { class BallBoosterGame extends LineGame {
BallBoosterGame()
: super(
imagesFileNames: [
Assets.images.ball.ball.keyName,
Assets.images.ball.androidBall.keyName,
Assets.images.ball.dashBall.keyName,
Assets.images.ball.dinoBall.keyName,
Assets.images.ball.sparkyBall.keyName,
Assets.images.ball.flameEffect.keyName,
],
);
static const description = ''' static const description = '''
Shows how a Ball with a boost works. Shows how a Ball with a boost works.

@ -8,10 +8,15 @@ class BallGame extends AssetsGame with TapDetector, Traceable {
this.color = Colors.blue, this.color = Colors.blue,
this.ballPriority = 0, this.ballPriority = 0,
this.ballLayer = Layer.all, this.ballLayer = Layer.all,
this.character,
List<String>? imagesFileNames, List<String>? imagesFileNames,
}) : super( }) : super(
imagesFileNames: [ imagesFileNames: [
Assets.images.ball.ball.keyName, Assets.images.ball.ball.keyName,
Assets.images.ball.androidBall.keyName,
Assets.images.ball.dashBall.keyName,
Assets.images.ball.dinoBall.keyName,
Assets.images.ball.sparkyBall.keyName,
if (imagesFileNames != null) ...imagesFileNames, if (imagesFileNames != null) ...imagesFileNames,
], ],
); );
@ -22,14 +27,25 @@ class BallGame extends AssetsGame with TapDetector, Traceable {
- Tap anywhere on the screen to spawn a ball into the game. - Tap anywhere on the screen to spawn a ball into the game.
'''; ''';
static final characterBallPaths = <String, String>{
'Dash': Assets.images.ball.dashBall.keyName,
'Sparky': Assets.images.ball.sparkyBall.keyName,
'Android': Assets.images.ball.androidBall.keyName,
'Dino': Assets.images.ball.dinoBall.keyName,
};
final Color color; final Color color;
final int ballPriority; final int ballPriority;
final Layer ballLayer; final Layer ballLayer;
final String? character;
@override @override
void onTapUp(TapUpInfo info) { void onTapUp(TapUpInfo info) {
add( add(
Ball(baseColor: color) Ball(
baseColor: color,
spriteAsset: characterBallPaths[character],
)
..initialPosition = info.eventPosition.game ..initialPosition = info.eventPosition.game
..layer = ballLayer ..layer = ballLayer
..priority = ballPriority, ..priority = ballPriority,

@ -11,6 +11,11 @@ void addBallStories(Dashbook dashbook) {
description: BallGame.description, description: BallGame.description,
gameBuilder: (context) => BallGame( gameBuilder: (context) => BallGame(
color: context.colorProperty('color', Colors.blue), color: context.colorProperty('color', Colors.blue),
character: context.listProperty(
'Character',
BallGame.characterBallPaths.keys.first,
BallGame.characterBallPaths.keys.toList(),
),
), ),
) )
..addGame( ..addGame(

Loading…
Cancel
Save