mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
* Added Component.childrenFactory * fix some of the lint warnings * more lint warnings * remove changelog entry * more analyzer warnings * one more warning * one more warning * remove more unused imports * fix more warnings * another warning * one more warning * a lot more warnings * some more warnings * fix warnings in flame_svg * fix warnings in flame_bloc * Remove OrderedSet override feature * Remove testRandom change * Remove unnecessary type checks * Re-remove deprecated argument in random_test Co-authored-by: Pasha Stetsenko <stpasha@google.com>
42 lines
1.1 KiB
Dart
42 lines
1.1 KiB
Dart
import 'package:flame_forge2d/body_component.dart';
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
import 'package:flame_forge2d/forge2d_game.dart';
|
|
import 'package:forge2d/forge2d.dart';
|
|
|
|
List<Wall> createBoundaries(Forge2DGame game) {
|
|
final topLeft = Vector2.zero();
|
|
final bottomRight = game.screenToWorld(game.camera.viewport.effectiveSize);
|
|
final topRight = Vector2(bottomRight.x, topLeft.y);
|
|
final bottomLeft = Vector2(topLeft.x, bottomRight.y);
|
|
|
|
return [
|
|
Wall(topLeft, topRight),
|
|
Wall(topRight, bottomRight),
|
|
Wall(bottomRight, bottomLeft),
|
|
Wall(bottomLeft, topLeft),
|
|
];
|
|
}
|
|
|
|
class Wall extends BodyComponent {
|
|
final Vector2 start;
|
|
final Vector2 end;
|
|
|
|
Wall(this.start, this.end);
|
|
|
|
@override
|
|
Body createBody() {
|
|
final shape = EdgeShape()..set(start, end);
|
|
|
|
final fixtureDef = FixtureDef(shape)
|
|
..restitution = 0.0
|
|
..friction = 0.3;
|
|
|
|
final bodyDef = BodyDef()
|
|
..userData = this // To be able to determine object in collision
|
|
..position = Vector2.zero()
|
|
..type = BodyType.static;
|
|
|
|
return world.createBody(bodyDef)..createFixture(fixtureDef);
|
|
}
|
|
}
|