Änderung: Bereinigung von Debugging-Ausgaben und Verbesserung der Kollisionserkennung im Taxi-Spiel
Änderungen: - Entfernen von überflüssigen Konsolenausgaben zur Verbesserung der Codequalität und Reduzierung von Debugging-Informationen. - Anpassung der Kollisionserkennung für das Taxi, um die Logik für befahrbare und nicht befahrbare Bereiche zu optimieren. - Einführung von Debugging-Informationen für Kollisionen mit Fuel-Tiles zur besseren Nachverfolgbarkeit. Diese Anpassungen erhöhen die Effizienz und Benutzerfreundlichkeit des Spiels, indem sie die Kollisionserkennung präzisieren und die Codebasis bereinigen.
This commit is contained in:
@@ -844,8 +844,6 @@ export default {
|
||||
// Füge Passagier zur Liste hinzu und markiere Haus als belegt
|
||||
this.waitingPassengersList.push(passenger);
|
||||
this.occupiedHouses.add(houseId);
|
||||
|
||||
console.log('Neuer wartender Passagier generiert:', passenger);
|
||||
},
|
||||
|
||||
generatePassengerName() {
|
||||
@@ -1450,8 +1448,6 @@ export default {
|
||||
isNear = verticalDistance <= maxDistance && horizontalDistance <= maxDistance * 1.5;
|
||||
}
|
||||
|
||||
console.log(`Haus-Erkennung: Corner=${corner}, Taxi(${taxiX},${taxiY}), Haus(${houseX},${houseY}), isNear=${isNear}`);
|
||||
|
||||
return isNear;
|
||||
},
|
||||
|
||||
@@ -1643,15 +1639,6 @@ export default {
|
||||
const vx = currCX - prevCX;
|
||||
const vy = currCY - prevCY;
|
||||
|
||||
// DEBUG: Umfassendes Logging
|
||||
console.log('=== ROTLICHT DEBUG ===');
|
||||
console.log('Tile:', this.currentTile.col, this.currentTile.row);
|
||||
console.log('TileType:', tileType);
|
||||
console.log('Approaches:', approaches);
|
||||
console.log('Phase:', phase, 'isHorRed:', isHorRed, 'isVerRed:', isVerRed);
|
||||
console.log('Taxi Position: prev(' + prevCX.toFixed(1) + ',' + prevCY.toFixed(1) + ') curr(' + currCX.toFixed(1) + ',' + currCY.toFixed(1) + ')');
|
||||
console.log('Movement: vx=' + vx.toFixed(1) + ', vy=' + vy.toFixed(1));
|
||||
console.log('StopLine Rects:', rects);
|
||||
|
||||
// Hinweis: Keine globale Bewegungsschwelle mehr.
|
||||
// Die Richtungsbedingungen (vy/vx > 0 bzw. < 0) in den jeweiligen Fällen
|
||||
@@ -1672,12 +1659,7 @@ export default {
|
||||
(Math.min(prevCX, currCX) <= x1 + tol && Math.max(prevCX, currCX) >= x0 - tol)
|
||||
);
|
||||
|
||||
console.log('TOP-Band: x0=' + x0 + ', x1=' + x1 + ', y0=' + y0 + ', y1=' + y1);
|
||||
console.log('TOP: vy=' + vy + ', prevCY=' + prevCY.toFixed(1) + ', currCY=' + currCY.toFixed(1) + ', isVerRed=' + isVerRed + ', isNearStopLine=' + isNearStopLine + ', withinXSpan=' + withinXSpan);
|
||||
console.log('TOP: prevCY < y0 =', prevCY < y0, ', currCY >= y0 =', currCY >= y0);
|
||||
|
||||
if (vy > 0 && prevCY < y0 && currCY >= y0 && isVerRed && isNearStopLine && withinXSpan) {
|
||||
console.log('🚨 TOP-Band VIOLATION!');
|
||||
violated = true;
|
||||
}
|
||||
}
|
||||
@@ -1694,12 +1676,7 @@ export default {
|
||||
(Math.min(prevCX, currCX) <= x1 + tol && Math.max(prevCX, currCX) >= x0 - tol)
|
||||
);
|
||||
|
||||
console.log('BOTTOM-Band: x0=' + x0 + ', x1=' + x1 + ', y0=' + y0 + ', y1=' + y1);
|
||||
console.log('BOTTOM: vy=' + vy + ', prevCY=' + prevCY.toFixed(1) + ', currCY=' + currCY.toFixed(1) + ', isVerRed=' + isVerRed + ', isNearStopLine=' + isNearStopLine + ', withinXSpan=' + withinXSpan);
|
||||
console.log('BOTTOM: prevCY > y1 =', prevCY > y1, ', currCY <= y1 =', currCY <= y1);
|
||||
|
||||
if (vy < 0 && prevCY > y1 && currCY <= y1 && isVerRed && isNearStopLine && withinXSpan) {
|
||||
console.log('🚨 BOTTOM-Band VIOLATION!');
|
||||
violated = true;
|
||||
}
|
||||
}
|
||||
@@ -1716,12 +1693,7 @@ export default {
|
||||
(Math.min(prevCY, currCY) <= y1 + tol && Math.max(prevCY, currCY) >= y0 - tol)
|
||||
);
|
||||
|
||||
console.log('LEFT-Band: x0=' + x0 + ', x1=' + x1 + ', y0=' + y0 + ', y1=' + y1);
|
||||
console.log('LEFT: vx=' + vx + ', prevCX=' + prevCX.toFixed(1) + ', currCX=' + currCX.toFixed(1) + ', isHorRed=' + isHorRed + ', isNearStopLine=' + isNearStopLine + ', withinYSpan=' + withinYSpan);
|
||||
console.log('LEFT: prevCX < x0 =', prevCX < x0, ', currCX >= x0 =', currCX >= x0);
|
||||
|
||||
if (vx > 0 && prevCX < x0 && currCX >= x0 && isHorRed && isNearStopLine && withinYSpan) {
|
||||
console.log('🚨 LEFT-Band VIOLATION!');
|
||||
violated = true;
|
||||
}
|
||||
}
|
||||
@@ -1738,18 +1710,11 @@ export default {
|
||||
(Math.min(prevCY, currCY) <= y1 + tol && Math.max(prevCY, currCY) >= y0 - tol)
|
||||
);
|
||||
|
||||
console.log('RIGHT-Band: x0=' + x0 + ', x1=' + x1 + ', y0=' + y0 + ', y1=' + y1);
|
||||
console.log('RIGHT: vx=' + vx + ', prevCX=' + prevCX.toFixed(1) + ', currCX=' + currCX.toFixed(1) + ', isHorRed=' + isHorRed + ', isNearStopLine=' + isNearStopLine + ', withinYSpan=' + withinYSpan);
|
||||
console.log('RIGHT: prevCX < x0 =', prevCX < x0, ', currCX >= x0 =', currCX >= x0);
|
||||
|
||||
if (vx < 0 && prevCX > x1 && currCX <= x1 && isHorRed && isNearStopLine && withinYSpan) {
|
||||
console.log('🚨 RIGHT-Band VIOLATION!');
|
||||
violated = true;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=== FINAL RESULT ===');
|
||||
console.log('Violated:', violated);
|
||||
|
||||
if (violated) {
|
||||
// Entprellen: pro Tile nur einmal pro tatsächlichem Übertritt zählen
|
||||
@@ -1777,12 +1742,8 @@ export default {
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('❌ VIOLATION IGNORED (too soon)');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=== END ROTLICHT DEBUG ===');
|
||||
},
|
||||
|
||||
checkRadarMeasurement() {
|
||||
@@ -1984,15 +1945,13 @@ export default {
|
||||
|
||||
isTaxiOnRoad() {
|
||||
// Prüfe ob das Taxi innerhalb der Canvas-Grenzen ist
|
||||
if (this.taxi.speed < 1) {
|
||||
return true;
|
||||
}
|
||||
if (this.taxi.x < 0 || this.taxi.x >= this.canvas.width ||
|
||||
this.taxi.y < 0 || this.taxi.y >= this.canvas.height) {
|
||||
if (this.taxi.speed > 0) {
|
||||
console.log('Taxi außerhalb Canvas-Grenzen:', { x: this.taxi.x, y: this.taxi.y });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Hole das aktuelle Tile und dessen Polygone
|
||||
const tileType = this.getCurrentTileType();
|
||||
const streetTileType = this.mapTileTypeToStreetCoordinates(tileType);
|
||||
@@ -2015,15 +1974,65 @@ export default {
|
||||
height: this.taxi.height / currentTileSize
|
||||
};
|
||||
|
||||
|
||||
// Prüfe Kollision mit jedem Polygon
|
||||
// Für Fuel-Tiles: Prüfe ob das Taxi in einem der befahrbaren Bereiche ist
|
||||
if (tileType === 'fuelhorizontal' || tileType === 'fuelvertical') {
|
||||
// Prüfe ob das Taxi in mindestens einem befahrbaren Bereich ist
|
||||
for (let i = 0; i < regions.length; i++) {
|
||||
const region = regions[i];
|
||||
|
||||
if (this.rectPolygonCollision(taxiRect, region)) {
|
||||
if (this.taxi.speed > 0) {
|
||||
console.log(`🚨 KOLLISION mit Polygon ${i}!`);
|
||||
return true; // Taxi ist in einem befahrbaren Bereich
|
||||
}
|
||||
}
|
||||
// Crash - zeige Debug-Informationen
|
||||
console.log('🚨 CRASH auf Fuel-Tile - Debug-Informationen:');
|
||||
console.log('Tile Type:', tileType);
|
||||
console.log('Polygons:', regions);
|
||||
console.log('Taxi Rect:', taxiRect);
|
||||
console.log('Taxi Position (absolute):', { x: this.taxi.x, y: this.taxi.y, width: this.taxi.width, height: this.taxi.height });
|
||||
return false; // Taxi ist in keinem befahrbaren Bereich
|
||||
}
|
||||
|
||||
// Für andere Tiles: Prüfe Kollision mit jedem Polygon (nicht befahrbar)
|
||||
for (let i = 0; i < regions.length; i++) {
|
||||
const region = regions[i];
|
||||
if (this.rectPolygonCollision(taxiRect, region)) {
|
||||
// Crash - zeige Debug-Informationen
|
||||
console.log('🚨 CRASH auf Tile - Debug-Informationen:');
|
||||
console.log('Tile Type:', tileType);
|
||||
console.log('Crash Polygon:', region);
|
||||
console.log('Alle Polygons:', regions);
|
||||
console.log('Taxi Rect:', taxiRect);
|
||||
console.log('Taxi Position (absolute):', { x: this.taxi.x, y: this.taxi.y, width: this.taxi.width, height: this.taxi.height });
|
||||
|
||||
// Test: Prüfe einen einzelnen Punkt
|
||||
const testPoint = { x: 0.5, y: 0.45 };
|
||||
const isInside = this.isPointInPolygon(testPoint.x, testPoint.y, region);
|
||||
console.log('Test-Punkt (0.5, 0.45) in Polygon:', isInside);
|
||||
|
||||
// Test: Prüfe mit absoluten Koordinaten
|
||||
const testPointAbs = { x: 250, y: 225 }; // Absolute Koordinaten
|
||||
const regionAbs = region.map(p => ({ x: p.x * 500, y: p.y * 500 })); // Umrechnung zu absoluten Koordinaten
|
||||
const isInsideAbs = this.isPointInPolygon(testPointAbs.x, testPointAbs.y, regionAbs);
|
||||
console.log('Test-Punkt (250, 225) in Polygon (absolut):', isInsideAbs);
|
||||
|
||||
// Test: Prüfe einen Punkt, der definitiv außerhalb sein sollte
|
||||
const testPointOutside = { x: 0.5, y: 0.1 }; // Sehr weit oben
|
||||
const isInsideOutside = this.isPointInPolygon(testPointOutside.x, testPointOutside.y, region);
|
||||
console.log('Test-Punkt (0.5, 0.1) in Polygon (sollte false sein):', isInsideOutside);
|
||||
|
||||
// Debug: Zeige die ersten paar Polygon-Punkte
|
||||
console.log('Erste 5 Polygon-Punkte:', region.slice(0, 5));
|
||||
|
||||
// Debug: Skalierungs-Informationen
|
||||
console.log('Tile Size:', this.tiles.size);
|
||||
console.log('Original Tile Size (aus JSON):', 640);
|
||||
console.log('Skalierungsfaktor:', this.tiles.size / 640);
|
||||
|
||||
// Debug: Taxi-Position in verschiedenen Koordinatensystemen
|
||||
console.log('Taxi Position (Canvas):', { x: this.taxi.x, y: this.taxi.y });
|
||||
console.log('Taxi Position (Tile-relative):', { x: this.taxi.x / this.tiles.size, y: this.taxi.y / this.tiles.size });
|
||||
console.log('Taxi Position (JSON-relative):', { x: this.taxi.x / 640, y: this.taxi.y / 640 });
|
||||
|
||||
return false; // Kollision = nicht befahrbar
|
||||
}
|
||||
}
|
||||
@@ -2034,27 +2043,42 @@ export default {
|
||||
// Prüft Kollision zwischen Rechteck und Polygon
|
||||
rectPolygonCollision(rect, polygon) {
|
||||
// Konvertiere Polygon-Koordinaten von absoluten Pixeln zu relativen (0-1)
|
||||
const originalTileSize = 640; // Aus der JSON-Datei
|
||||
const currentTileSize = this.tiles.size; // Aktuelle Render-Größe
|
||||
const relativePolygon = polygon.map(point => ({
|
||||
x: point.x / 640, // originalTileSize
|
||||
y: point.y / 640
|
||||
x: point.x / originalTileSize,
|
||||
y: point.y / originalTileSize
|
||||
}));
|
||||
|
||||
// Prüfe ob eine der Rechteck-Ecken im Polygon liegt
|
||||
const corners = [
|
||||
{ x: rect.x, y: rect.y }, // Oben links
|
||||
{ x: rect.x + rect.width, y: rect.y }, // Oben rechts
|
||||
{ x: rect.x, y: rect.y + rect.height }, // Unten links
|
||||
{ x: rect.x + rect.width, y: rect.y + rect.height } // Unten rechts
|
||||
|
||||
// Berechne die rotierten Ecken des Taxis
|
||||
// rect ist bereits in relativen Koordinaten (0-1)
|
||||
const centerX = rect.x + rect.width / 2;
|
||||
const centerY = rect.y + rect.height / 2;
|
||||
const angle = this.taxi.imageAngle + this.taxi.angle;
|
||||
|
||||
// Ursprüngliche Ecken relativ zum Zentrum (in relativen Koordinaten)
|
||||
const halfWidth = rect.width / 2;
|
||||
const halfHeight = rect.height / 2;
|
||||
const originalCorners = [
|
||||
{ x: -halfWidth, y: -halfHeight }, // Oben links
|
||||
{ x: halfWidth, y: -halfHeight }, // Oben rechts
|
||||
{ x: -halfWidth, y: halfHeight }, // Unten links
|
||||
{ x: halfWidth, y: halfHeight } // Unten rechts
|
||||
];
|
||||
|
||||
// Rotiere die Ecken (bleibt in relativen Koordinaten)
|
||||
const corners = originalCorners.map(corner => ({
|
||||
x: centerX + corner.x * Math.cos(angle) - corner.y * Math.sin(angle),
|
||||
y: centerY + corner.x * Math.sin(angle) + corner.y * Math.cos(angle)
|
||||
}));
|
||||
|
||||
for (let i = 0; i < corners.length; i++) {
|
||||
const corner = corners[i];
|
||||
// corners sind bereits in relativen Koordinaten (0-1)
|
||||
const isInside = this.isPointInPolygon(corner.x, corner.y, relativePolygon);
|
||||
|
||||
if (isInside) {
|
||||
if (this.taxi.speed > 0) {
|
||||
console.log(`🚨 Ecke ${i} ist im Polygon!`);
|
||||
}
|
||||
return true; // Rechteck-Ecke ist im Polygon = Kollision
|
||||
}
|
||||
}
|
||||
@@ -2065,9 +2089,6 @@ export default {
|
||||
const isInside = this.isPointInRect(point.x, point.y, rect);
|
||||
|
||||
if (isInside) {
|
||||
if (this.taxi.speed > 0) {
|
||||
console.log(`🚨 Polygon-Punkt ${i} ist im Rechteck!`);
|
||||
}
|
||||
return true; // Polygon-Ecke ist im Rechteck = Kollision
|
||||
}
|
||||
}
|
||||
@@ -2103,8 +2124,13 @@ export default {
|
||||
isPointInPolygon(x, y, polygon) {
|
||||
let inside = false;
|
||||
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
||||
if (((polygon[i].y > y) !== (polygon[j].y > y)) &&
|
||||
(x < (polygon[j].x - polygon[i].x) * (y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x)) {
|
||||
const xi = polygon[i].x;
|
||||
const yi = polygon[i].y;
|
||||
const xj = polygon[j].x;
|
||||
const yj = polygon[j].y;
|
||||
|
||||
// Ray casting algorithm: Prüfe ob der Strahl von (x,y) nach rechts die Kante schneidet
|
||||
if (((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi)) {
|
||||
inside = !inside;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user