From 8ead029f45bf848ab4249415508cec21b45b584a Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 27 Sep 2025 21:20:00 +0200 Subject: [PATCH] =?UTF-8?q?=C3=84nderung:=20Vereinheitlichung=20der=20Koll?= =?UTF-8?q?isionserkennung=20und=20Optimierung=20der=20Debugging-Ausgaben?= =?UTF-8?q?=20im=20Taxi-Spiel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ä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. --- frontend/src/views/minigames/TaxiGame.vue | 95 ++++++++++------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/frontend/src/views/minigames/TaxiGame.vue b/frontend/src/views/minigames/TaxiGame.vue index 75b30b8..cfc1aa2 100644 --- a/frontend/src/views/minigames/TaxiGame.vue +++ b/frontend/src/views/minigames/TaxiGame.vue @@ -1976,9 +1976,7 @@ export default { height: this.taxi.height / currentTileSize }; - // Für normale Tiles: 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'; + // Alle Tiles verwenden die gleiche Logik: Prüfe ob Taxi eine der Hindernis-Polylinien schneidet // Erstelle rotiertes Rechteck const rotatedRect = { @@ -2002,58 +2000,39 @@ export default { })); // 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 - console.log('🔍 KOLLISIONS-DEBUG:'); - console.log('Taxi Rect (relativ):', taxiRect); - console.log('Region Polylinie:', regionPoints); - console.log('Rotated Rect:', rotatedRect); - console.log('Kollisionsergebnis:', result); - - // Zusätzliche Debug-Ausgabe für cornerbottomright - if (streetTileType === 'cornerBottomRight') { - console.log('🔧 CORNERBOTTOMRIGHT DEBUG:'); + // Debug-Ausgabe nur für horizontale Fuel-Tiles + if (tileType === 'fuelhorizontal') { + console.log('🔍 KOLLISIONS-DEBUG (Fuel Horizontal):'); + console.log('Taxi Rect (relativ):', taxiRect); + console.log('Region Polylinie:', regionPoints); + console.log('Rotated Rect:', rotatedRect); + console.log('Kollisionsergebnis:', result); console.log('Region (relativ aus JSON):', region); - console.log('RegionPoints (relativ):', regionPoints); console.log('Taxi position:', this.taxi.x, this.taxi.y); console.log('Current tile size:', currentTileSize); console.log('Original tile size:', originalTileSize); } - if (isFuelTile) { - // Für Fuel-Tiles: Taxi muss eine der befahrbaren Polylinien schneiden - if (result.hit) { - console.log('✅ Fuel-Tile: Taxi ist auf befahrbarer Polylinie (Region', i, ')'); - return true; // Befahrbar - } - } else { - // Für normale Tiles: Taxi darf KEINE der Hindernis-Polylinien schneiden - if (result.hit) { - // Crash - zeige Debug-Informationen + // Einheitliche Logik für alle Tiles: Taxi darf KEINE der Hindernis-Polylinien schneiden + if (result.hit) { + // Crash - zeige Debug-Informationen nur für Fuel Horizontal Tiles + if (tileType === 'fuelhorizontal') { console.log('🚨 CRASH auf Tile - Debug-Informationen:'); console.log('Taxi Rect (relativ):', taxiRect); console.log('Crash Region Polylinie:', regionPoints); console.log('Rotated Rect:', rotatedRect); console.log('Crash Hits:', result.hits); - - return false; // Kollision mit Hindernis = Crash } + + return false; // Kollision mit Hindernis = Crash } } } - // Alle Regionen geprüft - if (isFuelTile) { - // 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 - } - + // Alle Regionen geprüft - einheitliche Logik für alle Tiles + // Keine Hindernis-Polylinie geschnitten = befahrbar return true; // Keine Kollision = befahrbar }, @@ -2097,23 +2076,23 @@ export default { // Verwende die robuste Kollisionserkennung const result = this.polylineIntersectsRotatedRect(polyline, rotatedRect); - // Debug-Ausgabe für Kollisionsergebnis - console.log('Kollisionsergebnis:', result); - console.log('Rotated Rect:', rotatedRect); - console.log('Polyline:', polyline); + // Debug-Ausgabe für Kollisionsergebnis (nur bei Fuel Horizontal Tiles) + // Diese Funktion wird nicht direkt für Fuel Tiles verwendet, daher keine Debug-Ausgabe hier return result.hit; }, // 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; - // Debug-Ausgabe für Eingabeparameter - console.log('🔧 polylineIntersectsRotatedRect DEBUG:'); - console.log('Polyline:', polyline); - console.log('Rect:', rect); - console.log('AABB bounds: x=[', cx - hx, ',', cx + hx, '], y=[', cy - hy, ',', cy + hy, ']'); + // Debug-Ausgabe nur wenn explizit angefordert + if (debug) { + console.log('🔧 polylineIntersectsRotatedRect DEBUG:'); + console.log('Polyline:', polyline); + 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 // oder ob irgendein Rechteck-Punkt auf der Polyline liegt @@ -2123,9 +2102,13 @@ export default { const p = polyline[i]; const inX = p.x >= cx - hx && p.x <= cx + hx; 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) { - 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 }] }; } } @@ -2146,7 +2129,9 @@ export default { // Prüfe ob Ecke auf Liniensegment liegt 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 } }] }; } } @@ -2159,12 +2144,16 @@ export default { // 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)) { - 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 } }] }; } } - console.log(`❌ Keine Kollision gefunden`); + if (debug) { + console.log(`❌ Keine Kollision gefunden`); + } return { hit: false, hits: [] }; },