Made the wires collision box smaller.
This commit is contained in:
parent
a4269c43c5
commit
c7469ec558
@ -1,6 +1,7 @@
|
||||
import 'package:firo_runner/moving_object.dart';
|
||||
import 'package:firo_runner/main.dart';
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum WireState { normal }
|
||||
|
||||
@ -38,4 +39,34 @@ class Wire extends MovingObject {
|
||||
void remove() {
|
||||
sprite.remove();
|
||||
}
|
||||
|
||||
@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";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user