2021-10-09 03:59:38 +00:00
|
|
|
import 'package:firo_runner/moving_objects/moving_object.dart';
|
2021-09-04 22:56:08 +00:00
|
|
|
import 'package:firo_runner/main.dart';
|
|
|
|
import 'package:flame/components.dart';
|
2021-09-13 21:00:43 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-09-04 22:56:08 +00:00
|
|
|
|
|
|
|
enum WireState { normal }
|
|
|
|
|
|
|
|
class Wire extends MovingObject {
|
|
|
|
Wire(MyGame gameRef) : super(gameRef) {
|
2021-10-05 23:19:58 +00:00
|
|
|
List<Sprite> wire = gameRef.wireHolder.getWire();
|
|
|
|
SpriteAnimation normal = SpriteAnimation.spriteList(wire, stepTime: 0.05);
|
2021-09-04 22:56:08 +00:00
|
|
|
|
|
|
|
sprite = SpriteAnimationGroupComponent(
|
|
|
|
animations: {
|
|
|
|
WireState.normal: normal,
|
|
|
|
},
|
|
|
|
current: WireState.normal,
|
|
|
|
);
|
|
|
|
|
|
|
|
sprite.changePriorityWithoutResorting(WIRE_PRIORITY);
|
|
|
|
|
|
|
|
setSize(
|
|
|
|
gameRef.blockSize,
|
|
|
|
gameRef.blockSize,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-09 18:32:15 +00:00
|
|
|
// Override the intersect method so that the hitbox is smaller for the wires,
|
|
|
|
// this will be more fair to the player.
|
2021-09-13 21:00:43 +00:00
|
|
|
@override
|
|
|
|
String intersect(Rect other) {
|
|
|
|
Rect currentRect = sprite.toRect();
|
|
|
|
Rect wireRect = Rect.fromLTWH(
|
|
|
|
currentRect.left + 2 * currentRect.width / 5,
|
|
|
|
currentRect.top + 2 * currentRect.height / 7,
|
|
|
|
currentRect.width / 5,
|
|
|
|
currentRect.height / 5,
|
|
|
|
);
|
|
|
|
final collision = wireRect.intersect(other);
|
|
|
|
if (!collision.isEmpty) {
|
|
|
|
double yDistance = other.top - wireRect.top;
|
|
|
|
double xDistance = other.left - wireRect.left;
|
|
|
|
if (yDistance.abs() > xDistance.abs()) {
|
|
|
|
if (yDistance > 0) {
|
|
|
|
return "bottom";
|
|
|
|
} else {
|
|
|
|
return "top";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (xDistance > 0) {
|
|
|
|
return "right";
|
|
|
|
} else {
|
|
|
|
return "left";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "none";
|
|
|
|
}
|
2021-09-04 22:56:08 +00:00
|
|
|
}
|