diff --git a/simulation.go b/simulation.go index 53fb53b..0d626fd 100644 --- a/simulation.go +++ b/simulation.go @@ -89,55 +89,89 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st // ============================================================================ func updatePhysics(s *SimState, didJump, isCrouching bool, currentSpeed float64) { + // 1. Powerup Logik (Jump Boots) jumpPower := JumpPower if s.BootTicks > 0 { jumpPower = HighJumpPower s.BootTicks-- } + // 2. Sind wir am Boden? isGrounded := checkGrounded(s) - // Fehler behoben: "currentHeight declared but not used" entfernt. - // Wir brauchen es hier nicht, da checkPlatformLanding mit fixen 50.0 rechnet. - // Die Hitbox-Änderung passiert nur in checkCollisions. - - if isCrouching && !isGrounded { - s.VelY += 2.0 // Fast Fall + // 3. Ducken / Fast Fall + // (Variable 'currentHeight' entfernt, da sie hier nicht gebraucht wird) + if isCrouching { + // Wenn man in der Luft duckt, fällt man schneller ("Fast Fall") + if !isGrounded { + s.VelY += 2.0 + } } + // 4. Springen if didJump && isGrounded && !isCrouching { s.VelY = jumpPower isGrounded = false - checkJumpSuspicion(s) } + // 5. Schwerkraft anwenden s.VelY += Gravity + oldY := s.PosY newY := s.PosY + s.VelY landed := false - // A. Plattform Landung (One-Way Logic) - if s.VelY > 0 { + // ============================================================ + // PLATTFORM KOLLISION (MIT VERTICAL SWEEP) + // ============================================================ + + if s.VelY > 0 { // Nur wenn wir fallen + + // Wir nutzen hier die Standard-Höhe für die Füße. + // Auch beim Ducken bleiben die Füße meist unten (oder ziehen hoch?), + // aber für die Landung auf Plattformen ist die Standard-Box sicherer. + playerFeetOld := oldY + PlayerHeight + playerFeetNew := newY + PlayerHeight + + // Player X ist fest bei 50, Breite 30 + pLeft := 50.0 + pRight := 50.0 + 30.0 + for _, p := range s.Platforms { - hit, landY := checkPlatformLanding(p.X, p.Y, p.Width, 50.0, oldY, newY, s.VelY) - if hit { - newY = landY - s.VelY = 0 - landed = true - break + + // 1. Horizontal Check (Großzügig!) + // Toleranz an den Rändern (-5 / +5), damit man nicht abrutscht + if (pRight-5.0 > p.X) && (pLeft+5.0 < p.X+p.Width) { + + // 2. Vertikaler Sweep (Durchsprung-Schutz) + // Check: Füße waren vorher <= Plattform-Oberkante + // UND Füße sind jetzt >= Plattform-Oberkante + if playerFeetOld <= p.Y && playerFeetNew >= p.Y { + + // Korrektur: Wir setzen den Spieler exakt AUF die Plattform + newY = p.Y - PlayerHeight + s.VelY = 0 + landed = true + isGrounded = true + break // Landung erfolgreich + } } } } - // B. Boden Landung + // ============================================================ + // BODEN KOLLISION + // ============================================================ if !landed { if newY >= PlayerYBase { newY = PlayerYBase s.VelY = 0 + isGrounded = true } } + // Neue Position setzen s.PosY = newY }