feat: adjusting game physics

pull/285/head
alestiago 3 years ago
parent 45cd89face
commit aac9ee2d5d

@ -35,7 +35,7 @@ class FlutterForest extends Component {
children: [ children: [
ScoringBehavior(points: 20), ScoringBehavior(points: 20),
], ],
)..initialPosition = Vector2(23.3, -46.75), )..initialPosition = Vector2(22.3, -46.75),
DashAnimatronic()..position = Vector2(20, -66), DashAnimatronic()..position = Vector2(20, -66),
FlutterForestBonusBehavior(), FlutterForestBonusBehavior(),
], ],

@ -24,7 +24,7 @@ class PinballGame extends Forge2DGame
PinballGame({ PinballGame({
required this.characterTheme, required this.characterTheme,
required this.audio, required this.audio,
}) { }) : super(gravity: Vector2(0, 35)) {
images.prefix = ''; images.prefix = '';
controller = _GameBallsController(this); controller = _GameBallsController(this);
} }

@ -5,6 +5,7 @@ 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';
import 'package:pinball_components/src/components/android_bumper/behaviors/behaviors.dart'; import 'package:pinball_components/src/components/android_bumper/behaviors/behaviors.dart';
import 'package:pinball_components/src/components/bumping_behavior.dart';
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
export 'cubit/android_bumper_cubit.dart'; export 'cubit/android_bumper_cubit.dart';
@ -47,7 +48,10 @@ class AndroidBumper extends BodyComponent with InitialPosition {
litAssetPath: Assets.images.androidBumper.a.lit.keyName, litAssetPath: Assets.images.androidBumper.a.lit.keyName,
dimmedAssetPath: Assets.images.androidBumper.a.dimmed.keyName, dimmedAssetPath: Assets.images.androidBumper.a.dimmed.keyName,
bloc: AndroidBumperCubit(), bloc: AndroidBumperCubit(),
children: children, children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// {@macro android_bumper} /// {@macro android_bumper}
@ -59,7 +63,10 @@ class AndroidBumper extends BodyComponent with InitialPosition {
litAssetPath: Assets.images.androidBumper.b.lit.keyName, litAssetPath: Assets.images.androidBumper.b.lit.keyName,
dimmedAssetPath: Assets.images.androidBumper.b.dimmed.keyName, dimmedAssetPath: Assets.images.androidBumper.b.dimmed.keyName,
bloc: AndroidBumperCubit(), bloc: AndroidBumperCubit(),
children: children, children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// Creates an [AndroidBumper] without any children. /// Creates an [AndroidBumper] without any children.
@ -95,15 +102,11 @@ class AndroidBumper extends BodyComponent with InitialPosition {
majorRadius: _majorRadius, majorRadius: _majorRadius,
minorRadius: _minorRadius, minorRadius: _minorRadius,
)..rotate(1.29); )..rotate(1.29);
final fixtureDef = FixtureDef(
shape,
restitution: 4,
);
final bodyDef = BodyDef( final bodyDef = BodyDef(
position: initialPosition, position: initialPosition,
); );
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixtureFromShape(shape);
} }
} }

@ -4,6 +4,7 @@ import 'package:flame/components.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';
import 'package:pinball_components/src/components/bumping_behavior.dart';
import 'package:pinball_components/src/components/dash_nest_bumper/behaviors/behaviors.dart'; import 'package:pinball_components/src/components/dash_nest_bumper/behaviors/behaviors.dart';
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
@ -47,8 +48,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.main.active.keyName, activeAssetPath: Assets.images.dash.bumper.main.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.main.inactive.keyName, inactiveAssetPath: Assets.images.dash.bumper.main.inactive.keyName,
spritePosition: Vector2(0, -0.3), spritePosition: Vector2(0, -0.3),
children: children,
bloc: DashNestBumperCubit(), bloc: DashNestBumperCubit(),
children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// {@macro dash_nest_bumper} /// {@macro dash_nest_bumper}
@ -60,8 +64,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.a.active.keyName, activeAssetPath: Assets.images.dash.bumper.a.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.a.inactive.keyName, inactiveAssetPath: Assets.images.dash.bumper.a.inactive.keyName,
spritePosition: Vector2(0.35, -1.2), spritePosition: Vector2(0.35, -1.2),
children: children,
bloc: DashNestBumperCubit(), bloc: DashNestBumperCubit(),
children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// {@macro dash_nest_bumper} /// {@macro dash_nest_bumper}
@ -73,8 +80,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.b.active.keyName, activeAssetPath: Assets.images.dash.bumper.b.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.b.inactive.keyName, inactiveAssetPath: Assets.images.dash.bumper.b.inactive.keyName,
spritePosition: Vector2(0.35, -1.2), spritePosition: Vector2(0.35, -1.2),
children: children,
bloc: DashNestBumperCubit(), bloc: DashNestBumperCubit(),
children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// Creates an [DashNestBumper] without any children. /// Creates an [DashNestBumper] without any children.
@ -108,13 +118,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
majorRadius: _majorRadius, majorRadius: _majorRadius,
minorRadius: _minorRadius, minorRadius: _minorRadius,
)..rotate(math.pi / 1.9); )..rotate(math.pi / 1.9);
final fixtureDef = FixtureDef(shape, restitution: 4);
final bodyDef = BodyDef( final bodyDef = BodyDef(
position: initialPosition, position: initialPosition,
userData: this,
); );
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixtureFromShape(shape);
} }
} }

@ -86,13 +86,7 @@ class _DinoTopWall extends BodyComponent with InitialPosition {
); );
final body = world.createBody(bodyDef); final body = world.createBody(bodyDef);
_createFixtureDefs().forEach( _createFixtureDefs().forEach(body.createFixture);
(fixture) => body.createFixture(
fixture
..restitution = 0.1
..friction = 0,
),
);
return body; return body;
} }

@ -24,7 +24,7 @@ class Flipper extends BodyComponent with KeyboardHandler, InitialPosition {
/// The speed required to move the [Flipper] to its highest position. /// The speed required to move the [Flipper] to its highest position.
/// ///
/// The higher the value, the faster the [Flipper] will move. /// The higher the value, the faster the [Flipper] will move.
static const double _speed = 60; static const double _speed = 90;
/// Whether the [Flipper] is on the left or right side of the board. /// Whether the [Flipper] is on the left or right side of the board.
/// ///

@ -90,8 +90,7 @@ class Kicker extends BodyComponent with InitialPosition {
final bouncyFixtureDef = FixtureDef( final bouncyFixtureDef = FixtureDef(
bouncyEdge, bouncyEdge,
// TODO(alestiago): Play with restitution value once game is bundled. userData: 'bouncy_fixture',
restitution: 10,
); );
fixturesDefs.add(bouncyFixtureDef); fixturesDefs.add(bouncyFixtureDef);

@ -82,7 +82,7 @@ class Plunger extends BodyComponent with InitialPosition, Layered {
/// The velocity's magnitude depends on how far the [Plunger] has been pulled /// The velocity's magnitude depends on how far the [Plunger] has been pulled
/// from its original [initialPosition]. /// from its original [initialPosition].
void release() { void release() {
final velocity = (initialPosition.y - body.position.y) * 5; final velocity = (initialPosition.y - body.position.y) * 20;
body.linearVelocity = Vector2(0, velocity); body.linearVelocity = Vector2(0, velocity);
_spriteComponent.release(); _spriteComponent.release();
} }

@ -1,6 +1,7 @@
import 'package:flame/components.dart'; import 'package:flame/components.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_components/src/components/bumping_behavior.dart';
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
/// {@template slingshots} /// {@template slingshots}
@ -39,7 +40,10 @@ class Slingshot extends BodyComponent with InitialPosition {
_angle = angle, _angle = angle,
super( super(
priority: RenderPriority.slingshot, priority: RenderPriority.slingshot,
children: [_SlinghsotSpriteComponent(spritePath, angle: angle)], children: [
_SlinghsotSpriteComponent(spritePath, angle: angle),
BumpingBehavior(strength: 10),
],
renderBody: false, renderBody: false,
); );

@ -4,6 +4,7 @@ import 'package:flame/components.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';
import 'package:pinball_components/src/components/bumping_behavior.dart';
import 'package:pinball_components/src/components/sparky_bumper/behaviors/behaviors.dart'; import 'package:pinball_components/src/components/sparky_bumper/behaviors/behaviors.dart';
import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_flame/pinball_flame.dart';
@ -50,7 +51,10 @@ class SparkyBumper extends BodyComponent with InitialPosition {
offAssetPath: Assets.images.sparky.bumper.a.inactive.keyName, offAssetPath: Assets.images.sparky.bumper.a.inactive.keyName,
spritePosition: Vector2(0, -0.25), spritePosition: Vector2(0, -0.25),
bloc: SparkyBumperCubit(), bloc: SparkyBumperCubit(),
children: children, children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// {@macro sparky_bumper} /// {@macro sparky_bumper}
@ -63,7 +67,10 @@ class SparkyBumper extends BodyComponent with InitialPosition {
offAssetPath: Assets.images.sparky.bumper.b.inactive.keyName, offAssetPath: Assets.images.sparky.bumper.b.inactive.keyName,
spritePosition: Vector2(0, -0.35), spritePosition: Vector2(0, -0.35),
bloc: SparkyBumperCubit(), bloc: SparkyBumperCubit(),
children: children, children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// {@macro sparky_bumper} /// {@macro sparky_bumper}
@ -76,7 +83,10 @@ class SparkyBumper extends BodyComponent with InitialPosition {
offAssetPath: Assets.images.sparky.bumper.c.inactive.keyName, offAssetPath: Assets.images.sparky.bumper.c.inactive.keyName,
spritePosition: Vector2(0, -0.4), spritePosition: Vector2(0, -0.4),
bloc: SparkyBumperCubit(), bloc: SparkyBumperCubit(),
children: children, children: [
...?children,
BumpingBehavior(strength: 20),
],
); );
/// Creates an [SparkyBumper] without any children. /// Creates an [SparkyBumper] without any children.
@ -111,15 +121,11 @@ class SparkyBumper extends BodyComponent with InitialPosition {
majorRadius: _majorRadius, majorRadius: _majorRadius,
minorRadius: _minorRadius, minorRadius: _minorRadius,
)..rotate(math.pi / 2.1); )..rotate(math.pi / 2.1);
final fixtureDef = FixtureDef( final bodyDef = BodyDef(
shape, position: initialPosition,
restitution: 4,
); );
final bodyDef = BodyDef()
..position = initialPosition
..userData = this;
return world.createBody(bodyDef)..createFixture(fixtureDef); return world.createBody(bodyDef)..createFixtureFromShape(shape);
} }
} }

Loading…
Cancel
Save