mirror of https://github.com/flutter/pinball.git
fix: physics are FPS depended (#316)
* fix: physics are FPS depended * fix: physics are FPS dependedpull/328/head
parent
7c05ad096c
commit
5af198a9a0
@ -0,0 +1,44 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_forge2d/world_contact_listener.dart';
|
||||||
|
|
||||||
|
// NOTE(wolfen): This should be removed when https://github.com/flame-engine/flame/pull/1597 is solved.
|
||||||
|
/// {@template pinball_forge2d_game}
|
||||||
|
/// A [Game] that uses the Forge2D physics engine.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class PinballForge2DGame extends FlameGame implements Forge2DGame {
|
||||||
|
/// {@macro pinball_forge2d_game}
|
||||||
|
PinballForge2DGame({
|
||||||
|
required Vector2 gravity,
|
||||||
|
}) : world = World(gravity),
|
||||||
|
super(camera: Camera()) {
|
||||||
|
camera.zoom = Forge2DGame.defaultZoom;
|
||||||
|
world.setContactListener(WorldContactListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
final World world;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void update(double dt) {
|
||||||
|
super.update(dt);
|
||||||
|
world.stepDt(min(dt, 1 / 60));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Vector2 screenToFlameWorld(Vector2 position) {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Vector2 screenToWorld(Vector2 position) {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Vector2 worldToScreen(Vector2 position) {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame/extensions.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_flame/pinball_flame.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
final flameTester = FlameTester(
|
||||||
|
() => PinballForge2DGame(gravity: Vector2.zero()),
|
||||||
|
);
|
||||||
|
|
||||||
|
group('PinballForge2DGame', () {
|
||||||
|
test('can instantiate', () {
|
||||||
|
expect(
|
||||||
|
() => PinballForge2DGame(gravity: Vector2.zero()),
|
||||||
|
returnsNormally,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'screenToFlameWorld throws UnimpelementedError',
|
||||||
|
(game) async {
|
||||||
|
expect(
|
||||||
|
() => game.screenToFlameWorld(Vector2.zero()),
|
||||||
|
throwsUnimplementedError,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'screenToWorld throws UnimpelementedError',
|
||||||
|
(game) async {
|
||||||
|
expect(
|
||||||
|
() => game.screenToWorld(Vector2.zero()),
|
||||||
|
throwsUnimplementedError,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'worldToScreen throws UnimpelementedError',
|
||||||
|
(game) async {
|
||||||
|
expect(
|
||||||
|
() => game.worldToScreen(Vector2.zero()),
|
||||||
|
throwsUnimplementedError,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue