fix: fixed merge conflicts on plunger

pull/200/head
RuiAlonso 3 years ago
parent 895da6c0e1
commit 8e8cfdef46

@ -16,8 +16,8 @@ class Launcher extends Forge2DBlueprint {
@override @override
void build(Forge2DGame gameRef) { void build(Forge2DGame gameRef) {
plunger = ControlledPlunger(compressionDistance: 20) //12.3 plunger = ControlledPlunger(compressionDistance: 12.3)
..initialPosition = Vector2(38.5, -20); ..initialPosition = Vector2(40.1, 38);
final _rocket = RocketSpriteComponent()..position = Vector2(43, 62); final _rocket = RocketSpriteComponent()..position = Vector2(43, 62);

@ -21,18 +21,39 @@ class Plunger extends BodyComponent with InitialPosition, Layered {
/// Distance the plunger can lower. /// Distance the plunger can lower.
final double compressionDistance; final double compressionDistance;
List<FixtureDef> _createFixtureDefs() {
final fixturesDef = <FixtureDef>[];
final leftShapeVertices = [
Vector2(0, 0),
Vector2(-1.4, 0),
Vector2(-1.4, -1.2),
Vector2(0, -0.3),
]..map((vector) => vector.rotate(BoardDimensions.perspectiveAngle))
.toList();
final leftTriangleShape = PolygonShape()..set(leftShapeVertices);
final leftTriangleFixtureDef = FixtureDef(leftTriangleShape)..density = 80;
fixturesDef.add(leftTriangleFixtureDef);
final rightShapeVertices = [
Vector2(0, 0),
Vector2(1.4, 0),
Vector2(1.4, -1.2),
Vector2(0, -0.3),
]..map((vector) => vector.rotate(BoardDimensions.perspectiveAngle))
.toList();
final rightTriangleShape = PolygonShape()..set(rightShapeVertices);
final rightTriangleFixtureDef = FixtureDef(rightTriangleShape)
..density = 80;
fixturesDef.add(rightTriangleFixtureDef);
return fixturesDef;
}
@override @override
Body createBody() { Body createBody() {
final shape = PolygonShape()
..setAsBox(
1.35,
0.5,
Vector2.zero(),
BoardDimensions.perspectiveAngle,
);
final fixtureDef = FixtureDef(shape)..density = 80;
final bodyDef = BodyDef( final bodyDef = BodyDef(
position: initialPosition, position: initialPosition,
userData: this, userData: this,
@ -40,7 +61,9 @@ class Plunger extends BodyComponent with InitialPosition, Layered {
gravityScale: Vector2.zero(), gravityScale: Vector2.zero(),
); );
return world.createBody(bodyDef)..createFixture(fixtureDef); final body = world.createBody(bodyDef);
_createFixtureDefs().forEach(body.createFixture);
return body;
} }
/// Set a constant downward velocity on the [Plunger]. /// Set a constant downward velocity on the [Plunger].
@ -77,12 +100,35 @@ class Plunger extends BodyComponent with InitialPosition, Layered {
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await _anchorToJoint(); await _anchorToJoint();
renderBody = false; renderBody = true;
await add(_PlungerSpriteComponent()); await add(_PlungerSpriteComponent());
} }
} }
class _PlungerSpriteComponent extends SpriteComponent with HasGameRef { class _PlungerSpriteComponent extends SpriteComponent with HasGameRef {
/*
late final SpriteAnimation _pullAnimation;
late final SpriteAnimation _releaseAnimation;
void pull() {
print('PLAYING pullAnimation');
if (animation != _pullAnimation) {
print('set animation to _pullAnimation');
animation = _pullAnimation;
}
//playing = true;
}
void release() {
print('PLAYING releaseAnimation');
if (animation != _releaseAnimation) {
print('set animation to _releaseAnimation');
animation = _releaseAnimation;
//playing = true;
}
}
*/
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();

Loading…
Cancel
Save