Änderung: Vereinheitlichung der Kollisionserkennung und Optimierung der Debugging-Ausgaben im Taxi-Spiel

Änderungen:
- Anpassung der Kollisionserkennung, um eine einheitliche Logik für alle Tile-Typen zu implementieren.
- Reduzierung der Debugging-Ausgaben auf relevante Informationen, insbesondere für horizontale Fuel-Tiles.
- Verbesserung der Lesbarkeit und Wartbarkeit des Codes durch Bereinigung überflüssiger Konsolenausgaben.

Diese Anpassungen erhöhen die Effizienz der Kollisionserkennung und verbessern die Nachverfolgbarkeit von Kollisionen im Spiel.
This commit is contained in:
Torsten Schulz (local)
2025-09-27 21:20:00 +02:00
parent 550159fb71
commit 8ead029f45

View File

@@ -1976,9 +1976,7 @@ export default {
height: this.taxi.height / currentTileSize height: this.taxi.height / currentTileSize
}; };
// Für normale Tiles: Prüfe ob Taxi eine der Hindernis-Polylinien schneidet // Alle Tiles verwenden die gleiche Logik: Prüfe ob Taxi eine der Hindernis-Polylinien schneidet
// Für Fuel-Tiles: Prüfe ob Taxi eine der befahrbaren Polylinien schneidet
const isFuelTile = tileType === 'fuelhorizontal' || tileType === 'fuelvertical';
// Erstelle rotiertes Rechteck // Erstelle rotiertes Rechteck
const rotatedRect = { const rotatedRect = {
@@ -2002,58 +2000,39 @@ export default {
})); }));
// Verwende die robuste Kollisionserkennung für diese Region // Verwende die robuste Kollisionserkennung für diese Region
const result = this.polylineIntersectsRotatedRect(regionPoints, rotatedRect); const result = this.polylineIntersectsRotatedRect(regionPoints, rotatedRect, tileType === 'fuelhorizontal');
// Debug-Ausgabe bei jeder Prüfung // Debug-Ausgabe nur für horizontale Fuel-Tiles
console.log('🔍 KOLLISIONS-DEBUG:'); if (tileType === 'fuelhorizontal') {
console.log('Taxi Rect (relativ):', taxiRect); console.log('🔍 KOLLISIONS-DEBUG (Fuel Horizontal):');
console.log('Region Polylinie:', regionPoints); console.log('Taxi Rect (relativ):', taxiRect);
console.log('Rotated Rect:', rotatedRect); console.log('Region Polylinie:', regionPoints);
console.log('Kollisionsergebnis:', result); console.log('Rotated Rect:', rotatedRect);
console.log('Kollisionsergebnis:', result);
// Zusätzliche Debug-Ausgabe für cornerbottomright
if (streetTileType === 'cornerBottomRight') {
console.log('🔧 CORNERBOTTOMRIGHT DEBUG:');
console.log('Region (relativ aus JSON):', region); console.log('Region (relativ aus JSON):', region);
console.log('RegionPoints (relativ):', regionPoints);
console.log('Taxi position:', this.taxi.x, this.taxi.y); console.log('Taxi position:', this.taxi.x, this.taxi.y);
console.log('Current tile size:', currentTileSize); console.log('Current tile size:', currentTileSize);
console.log('Original tile size:', originalTileSize); console.log('Original tile size:', originalTileSize);
} }
if (isFuelTile) { // Einheitliche Logik für alle Tiles: Taxi darf KEINE der Hindernis-Polylinien schneiden
// Für Fuel-Tiles: Taxi muss eine der befahrbaren Polylinien schneiden if (result.hit) {
if (result.hit) { // Crash - zeige Debug-Informationen nur für Fuel Horizontal Tiles
console.log('✅ Fuel-Tile: Taxi ist auf befahrbarer Polylinie (Region', i, ')'); if (tileType === 'fuelhorizontal') {
return true; // Befahrbar
}
} else {
// Für normale Tiles: Taxi darf KEINE der Hindernis-Polylinien schneiden
if (result.hit) {
// Crash - zeige Debug-Informationen
console.log('🚨 CRASH auf Tile - Debug-Informationen:'); console.log('🚨 CRASH auf Tile - Debug-Informationen:');
console.log('Taxi Rect (relativ):', taxiRect); console.log('Taxi Rect (relativ):', taxiRect);
console.log('Crash Region Polylinie:', regionPoints); console.log('Crash Region Polylinie:', regionPoints);
console.log('Rotated Rect:', rotatedRect); console.log('Rotated Rect:', rotatedRect);
console.log('Crash Hits:', result.hits); console.log('Crash Hits:', result.hits);
return false; // Kollision mit Hindernis = Crash
} }
return false; // Kollision mit Hindernis = Crash
} }
} }
} }
// Alle Regionen geprüft // Alle Regionen geprüft - einheitliche Logik für alle Tiles
if (isFuelTile) { // Keine Hindernis-Polylinie geschnitten = befahrbar
// Für Fuel-Tiles: Keine befahrbare Polylinie gefunden = Crash
console.log('🚨 Fuel-Tile: Taxi ist NICHT auf befahrbarer Polylinie - CRASH');
return false; // Nicht befahrbar = Crash
} else {
// Für normale Tiles: Keine Hindernis-Polylinie geschnitten = befahrbar
console.log('✅ Normales Tile: Taxi schneidet keine Hindernis-Polylinien');
return true; // Keine Kollision = befahrbar
}
return true; // Keine Kollision = befahrbar return true; // Keine Kollision = befahrbar
}, },
@@ -2097,23 +2076,23 @@ export default {
// Verwende die robuste Kollisionserkennung // Verwende die robuste Kollisionserkennung
const result = this.polylineIntersectsRotatedRect(polyline, rotatedRect); const result = this.polylineIntersectsRotatedRect(polyline, rotatedRect);
// Debug-Ausgabe für Kollisionsergebnis // Debug-Ausgabe für Kollisionsergebnis (nur bei Fuel Horizontal Tiles)
console.log('Kollisionsergebnis:', result); // Diese Funktion wird nicht direkt für Fuel Tiles verwendet, daher keine Debug-Ausgabe hier
console.log('Rotated Rect:', rotatedRect);
console.log('Polyline:', polyline);
return result.hit; return result.hit;
}, },
// Testet, ob eine Polyline (Liste von Punkten) ein rotiertes Rechteck schneidet // Testet, ob eine Polyline (Liste von Punkten) ein rotiertes Rechteck schneidet
polylineIntersectsRotatedRect(polyline, rect, eps = 1e-9) { polylineIntersectsRotatedRect(polyline, rect, debug = false, eps = 1e-9) {
const { cx, cy, theta, hx, hy } = rect; const { cx, cy, theta, hx, hy } = rect;
// Debug-Ausgabe für Eingabeparameter // Debug-Ausgabe nur wenn explizit angefordert
console.log('🔧 polylineIntersectsRotatedRect DEBUG:'); if (debug) {
console.log('Polyline:', polyline); console.log('🔧 polylineIntersectsRotatedRect DEBUG:');
console.log('Rect:', rect); console.log('Polyline:', polyline);
console.log('AABB bounds: x=[', cx - hx, ',', cx + hx, '], y=[', cy - hy, ',', cy + hy, ']'); console.log('Rect:', rect);
console.log('AABB bounds: x=[', cx - hx, ',', cx + hx, '], y=[', cy - hy, ',', cy + hy, ']');
}
// Vereinfachte Kollisionserkennung: Prüfe ob irgendein Polyline-Punkt im Rechteck liegt // Vereinfachte Kollisionserkennung: Prüfe ob irgendein Polyline-Punkt im Rechteck liegt
// oder ob irgendein Rechteck-Punkt auf der Polyline liegt // oder ob irgendein Rechteck-Punkt auf der Polyline liegt
@@ -2123,9 +2102,13 @@ export default {
const p = polyline[i]; const p = polyline[i];
const inX = p.x >= cx - hx && p.x <= cx + hx; const inX = p.x >= cx - hx && p.x <= cx + hx;
const inY = p.y >= cy - hy && p.y <= cy + hy; const inY = p.y >= cy - hy && p.y <= cy + hy;
console.log(` Punkt ${i}: (${p.x}, ${p.y}) - In AABB: ${inX && inY}`); if (debug) {
console.log(` Punkt ${i}: (${p.x}, ${p.y}) - In AABB: ${inX && inY}`);
}
if (inX && inY) { if (inX && inY) {
console.log(`✅ Kollision: Polyline-Punkt ${i} liegt im Rechteck`); if (debug) {
console.log(`✅ Kollision: Polyline-Punkt ${i} liegt im Rechteck`);
}
return { hit: true, hits: [{ type: 'point_in_rect', pointIndex: i, point: p }] }; return { hit: true, hits: [{ type: 'point_in_rect', pointIndex: i, point: p }] };
} }
} }
@@ -2146,7 +2129,9 @@ export default {
// Prüfe ob Ecke auf Liniensegment liegt // Prüfe ob Ecke auf Liniensegment liegt
if (this.isPointOnLineSegment(corner.x, corner.y, A.x, A.y, B.x, B.y)) { if (this.isPointOnLineSegment(corner.x, corner.y, A.x, A.y, B.x, B.y)) {
console.log(`✅ Kollision: Rechteck-Ecke ${cornerIndex} liegt auf Polyline-Segment ${i}`); if (debug) {
console.log(`✅ Kollision: Rechteck-Ecke ${cornerIndex} liegt auf Polyline-Segment ${i}`);
}
return { hit: true, hits: [{ type: 'corner_on_line', cornerIndex, segmentIndex: i, corner, segment: { A, B } }] }; return { hit: true, hits: [{ type: 'corner_on_line', cornerIndex, segmentIndex: i, corner, segment: { A, B } }] };
} }
} }
@@ -2159,12 +2144,16 @@ export default {
// Prüfe ob Liniensegment das Rechteck schneidet // Prüfe ob Liniensegment das Rechteck schneidet
if (this.lineSegmentIntersectsRect(A.x, A.y, B.x, B.y, cx - hx, cy - hy, cx + hx, cy + hy)) { if (this.lineSegmentIntersectsRect(A.x, A.y, B.x, B.y, cx - hx, cy - hy, cx + hx, cy + hy)) {
console.log(`✅ Kollision: Polyline-Segment ${i} schneidet Rechteck`); if (debug) {
console.log(`✅ Kollision: Polyline-Segment ${i} schneidet Rechteck`);
}
return { hit: true, hits: [{ type: 'segment_intersects_rect', segmentIndex: i, segment: { A, B } }] }; return { hit: true, hits: [{ type: 'segment_intersects_rect', segmentIndex: i, segment: { A, B } }] };
} }
} }
console.log(`❌ Keine Kollision gefunden`); if (debug) {
console.log(`❌ Keine Kollision gefunden`);
}
return { hit: false, hits: [] }; return { hit: false, hits: [] };
}, },