feat: adjusting game physics

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

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

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

@ -5,6 +5,7 @@ import 'package:flame_forge2d/flame_forge2d.dart';
import 'package:flutter/material.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/bumping_behavior.dart';
import 'package:pinball_flame/pinball_flame.dart';
export 'cubit/android_bumper_cubit.dart';
@ -47,7 +48,10 @@ class AndroidBumper extends BodyComponent with InitialPosition {
litAssetPath: Assets.images.androidBumper.a.lit.keyName,
dimmedAssetPath: Assets.images.androidBumper.a.dimmed.keyName,
bloc: AndroidBumperCubit(),
children: children,
children: [
...?children,
BumpingBehavior(strength: 20),
],
);
/// {@macro android_bumper}
@ -59,7 +63,10 @@ class AndroidBumper extends BodyComponent with InitialPosition {
litAssetPath: Assets.images.androidBumper.b.lit.keyName,
dimmedAssetPath: Assets.images.androidBumper.b.dimmed.keyName,
bloc: AndroidBumperCubit(),
children: children,
children: [
...?children,
BumpingBehavior(strength: 20),
],
);
/// Creates an [AndroidBumper] without any children.
@ -95,15 +102,11 @@ class AndroidBumper extends BodyComponent with InitialPosition {
majorRadius: _majorRadius,
minorRadius: _minorRadius,
)..rotate(1.29);
final fixtureDef = FixtureDef(
shape,
restitution: 4,
);
final bodyDef = BodyDef(
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:flutter/material.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_flame/pinball_flame.dart';
@ -47,8 +48,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.main.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.main.inactive.keyName,
spritePosition: Vector2(0, -0.3),
children: children,
bloc: DashNestBumperCubit(),
children: [
...?children,
BumpingBehavior(strength: 20),
],
);
/// {@macro dash_nest_bumper}
@ -60,8 +64,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.a.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.a.inactive.keyName,
spritePosition: Vector2(0.35, -1.2),
children: children,
bloc: DashNestBumperCubit(),
children: [
...?children,
BumpingBehavior(strength: 20),
],
);
/// {@macro dash_nest_bumper}
@ -73,8 +80,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
activeAssetPath: Assets.images.dash.bumper.b.active.keyName,
inactiveAssetPath: Assets.images.dash.bumper.b.inactive.keyName,
spritePosition: Vector2(0.35, -1.2),
children: children,
bloc: DashNestBumperCubit(),
children: [
...?children,
BumpingBehavior(strength: 20),
],
);
/// Creates an [DashNestBumper] without any children.
@ -108,13 +118,11 @@ class DashNestBumper extends BodyComponent with InitialPosition {
majorRadius: _majorRadius,
minorRadius: _minorRadius,
)..rotate(math.pi / 1.9);
final fixtureDef = FixtureDef(shape, restitution: 4);
final bodyDef = BodyDef(
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);
_createFixtureDefs().forEach(
(fixture) => body.createFixture(
fixture
..restitution = 0.1
..friction = 0,
),
);
_createFixtureDefs().forEach(body.createFixture);
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 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.
///

@ -90,8 +90,7 @@ class Kicker extends BodyComponent with InitialPosition {
final bouncyFixtureDef = FixtureDef(
bouncyEdge,
// TODO(alestiago): Play with restitution value once game is bundled.
restitution: 10,
userData: 'bouncy_fixture',
);
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
/// from its original [initialPosition].
void release() {
final velocity = (initialPosition.y - body.position.y) * 5;
final velocity = (initialPosition.y - body.position.y) * 20;
body.linearVelocity = Vector2(0, velocity);
_spriteComponent.release();
}

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

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

Loading…
Cancel
Save