2021-09-16 21:15:32 +00:00
|
|
|
import 'package:firo_runner/holder.dart';
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/platform.dart';
|
2021-10-05 23:19:58 +00:00
|
|
|
import 'package:flame/components.dart';
|
2021-09-04 22:56:08 +00:00
|
|
|
|
2021-09-08 21:44:12 +00:00
|
|
|
import 'package:firo_runner/wire.dart';
|
|
|
|
import 'package:firo_runner/main.dart';
|
2021-09-04 22:56:08 +00:00
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
class WireHolder extends Holder {
|
2021-10-05 23:19:58 +00:00
|
|
|
late List<Sprite> wire;
|
2021-09-04 22:56:08 +00:00
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
@override
|
|
|
|
Future load() async {
|
2021-10-05 23:19:58 +00:00
|
|
|
wire = await loadListSprites("wire", "wire", 12);
|
2021-09-05 22:36:36 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 23:19:58 +00:00
|
|
|
List<Sprite> getWire() {
|
2021-09-04 22:56:08 +00:00
|
|
|
return wire;
|
|
|
|
}
|
|
|
|
|
2021-09-17 03:26:57 +00:00
|
|
|
bool generateWire(MyGame gameRef, int level,
|
|
|
|
{bool force = false, double xPosition = 0}) {
|
2021-10-05 23:19:58 +00:00
|
|
|
if (objects[level].isNotEmpty) {
|
2021-09-04 22:56:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (random.nextInt(100) > 100) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2021-09-16 21:15:32 +00:00
|
|
|
int nearestPlatform = getNearestPlatform(level);
|
2021-09-04 22:56:08 +00:00
|
|
|
|
|
|
|
Platform? platform =
|
|
|
|
gameRef.platformHolder.getPlatformOffScreen(nearestPlatform);
|
2021-09-13 19:21:52 +00:00
|
|
|
if (platform != null && platform.prohibitObstacles) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-04 22:56:08 +00:00
|
|
|
double xCoordinate = -100;
|
|
|
|
|
|
|
|
if (level == 0) {
|
|
|
|
xCoordinate = gameRef.size.x;
|
|
|
|
} else if (platform != null) {
|
|
|
|
xCoordinate = platform.sprite.x;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Wire wire = Wire(gameRef);
|
2021-09-05 22:36:36 +00:00
|
|
|
wire.sprite.renderFlipX = true;
|
2021-09-04 22:56:08 +00:00
|
|
|
if (level % 3 == 0) {
|
|
|
|
wire.sprite.renderFlipY = true;
|
|
|
|
wire.setPosition(
|
2021-09-08 19:27:06 +00:00
|
|
|
xCoordinate, gameRef.blockSize * level - 2 * gameRef.blockSize / 7);
|
2021-09-04 22:56:08 +00:00
|
|
|
} else {
|
|
|
|
wire.setPosition(
|
|
|
|
xCoordinate, gameRef.blockSize * level + gameRef.blockSize / 10);
|
|
|
|
}
|
2021-09-05 00:36:14 +00:00
|
|
|
|
|
|
|
if (gameRef.isTooNearOtherObstacles(wire.sprite.toRect())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:15:32 +00:00
|
|
|
objects[level].add(wire);
|
2021-09-04 22:56:08 +00:00
|
|
|
gameRef.add(wire.sprite);
|
|
|
|
if (platform != null) {
|
2021-09-05 00:18:37 +00:00
|
|
|
platform.removeChildren.add(() {
|
2021-09-16 21:15:32 +00:00
|
|
|
objects[level].remove(wire);
|
2021-09-04 22:56:08 +00:00
|
|
|
wire.remove();
|
2021-09-05 00:18:37 +00:00
|
|
|
});
|
2021-09-04 22:56:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|