Move doors to door manager

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-14 00:34:09 +01:00
parent 09c28028ad
commit 5c9dafbbdf
4 changed files with 126 additions and 37 deletions

View File

@@ -0,0 +1,56 @@
import 'dart:math' as math;
import 'package:wolf_dart/features/map/door.dart';
class DoorManager {
// Key is '$x,$y'
final Map<String, Door> doors = {};
void initDoors(List<List<int>> wallGrid) {
doors.clear();
for (int y = 0; y < wallGrid.length; y++) {
for (int x = 0; x < wallGrid[y].length; x++) {
int id = wallGrid[y][x];
if (id >= 90) {
// Assuming 90+ are doors based on your previous code
doors['$x,$y'] = Door(x: x, y: y, mapId: id);
}
}
}
}
void update(Duration elapsed) {
for (final door in doors.values) {
door.update(elapsed.inMilliseconds);
}
}
void handleInteraction(double playerX, double playerY, double playerAngle) {
int targetX = (playerX + math.cos(playerAngle)).toInt();
int targetY = (playerY + math.sin(playerAngle)).toInt();
String key = '$targetX,$targetY';
if (doors.containsKey(key)) {
doors[key]!.interact();
}
}
// Helper method for the raycaster
Map<String, double> getOffsetsForRenderer() {
Map<String, double> offsets = {};
for (var entry in doors.entries) {
if (entry.value.offset > 0.0) {
offsets[entry.key] = entry.value.offset;
}
}
return offsets;
}
bool isDoorOpenEnough(int x, int y) {
String key = '$x,$y';
if (doors.containsKey(key)) {
return doors[key]!.offset > 0.7;
}
return false; // Not a door we manage
}
}