shitman/lib/game/components/target_house.dart
zeyus 67aaa9589f
All checks were successful
/ build-web (push) Successful in 4m5s
updated level...player can now "complete" (no ui)
2025-07-27 17:41:51 +02:00

61 lines
1.6 KiB
Dart

import 'package:flame/components.dart';
import 'package:shitman/game/components/base.dart';
import 'package:shitman/game/components/neighborhood.dart';
class TargetHouse extends ShitComponent {
House? currentTarget;
bool missionActive = false;
@override
Future<void> onLoad() async {
await super.onLoad();
selectNewTarget();
}
void selectNewTarget() {
// Find the neighborhood component
final neighborhood = parent?.children.whereType<Neighborhood>().firstOrNull;
if (neighborhood == null) return;
// Clear previous target
if (currentTarget != null) {
currentTarget!.isTarget = false;
}
// Select random house as new target
currentTarget = neighborhood.getRandomHouse();
if (currentTarget != null) {
currentTarget!.isTarget = true;
missionActive = true;
appLog.finest('New target selected at ${currentTarget!.position}');
}
}
void completeMission() {
if (currentTarget != null) {
currentTarget!.isTarget = false;
currentTarget = null;
}
missionActive = false;
}
bool isPlayerNearTarget(Vector2 playerPosition, {double threshold = 50.0}) {
if (currentTarget?.doorPosition == null) return false;
final distance = (playerPosition - currentTarget!.doorPosition!).length;
return distance < threshold;
}
Vector2? getTargetPosition() {
return currentTarget?.doorPosition;
}
@override
Future<void> reset() async {
// Reset target house state
currentTarget?.isTarget = false;
currentTarget = null;
missionActive = false;
appLog.finest('Target house reset');
}
}