Private
Public Access
1
0

bug fixes
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 3m42s

This commit is contained in:
Sebastian Unterschütz
2025-11-26 10:59:05 +01:00
parent fc8b22dd7c
commit 95119cdf98
4 changed files with 191 additions and 69 deletions

View File

@@ -7,11 +7,15 @@ import (
)
func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[string]string) (bool, int, []ActiveObstacle) {
// State laden
posY := parseOr(vals["pos_y"], PlayerYBase)
velY := parseOr(vals["vel_y"], 0.0)
score := int(parseOr(vals["score"], 0))
rngStateVal, _ := strconv.ParseInt(vals["rng_state"], 10, 64)
// NEU: Wir laden die bisher vergangene Zeit (Ticks)
ticksAlive := int(parseOr(vals["total_ticks"], 0))
rngStateVal, _ := strconv.ParseInt(vals["rng_state"], 10, 64)
godLives := int(parseOr(vals["p_god_lives"], 0))
hasBat := vals["p_has_bat"] == "1"
bootTicks := int(parseOr(vals["p_boot_ticks"], 0))
@@ -28,9 +32,14 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
playerDead := false
for i := 0; i < totalTicks; i++ {
currentSpeed := BaseSpeed + (float64(score) / 1000)
if currentSpeed > 10.0 {
currentSpeed = 10.0
// WICHTIG: Wir erhöhen die Zeit
ticksAlive++
// LOGIK FIX: Geschwindigkeit basiert jetzt auf ZEIT (Ticks), nicht Score!
// 3000 Ticks = ca. 50 Sekunden. Da wird es schneller.
currentSpeed := BaseSpeed + (float64(ticksAlive)/3000.0)*0.5
if currentSpeed > 12.0 {
currentSpeed = 12.0
}
currentJumpPower := JumpPower
@@ -39,6 +48,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
bootTicks--
}
// Input Verarbeitung
didJump := false
isCrouching := false
for _, inp := range inputs {
@@ -52,6 +62,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
}
}
// Physik
isGrounded := posY >= PlayerYBase-1.0
currentHeight := PlayerHeight
if isCrouching {
@@ -77,6 +88,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
hitboxY = posY + (PlayerHeight - currentHeight)
}
// Obstacles
nextObstacles := []ActiveObstacle{}
rightmostX := 0.0
@@ -87,10 +99,10 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
continue
}
// Passed Check (Verhindert Hängenbleiben an "toten" Objekten)
paddingX := 10.0
realRightEdge := obs.X + obs.Width - paddingX
if realRightEdge < 55.0 {
if obs.X+obs.Width-paddingX < 55.0 {
// Schon vorbei -> Keine Kollision mehr prüfen
nextObstacles = append(nextObstacles, obs)
if obs.X+obs.Width > rightmostX {
rightmostX = obs.X + obs.Width
@@ -105,16 +117,14 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
pLeft, pRight := 50.0+paddingX, 50.0+30.0-paddingX
pTop, pBottom := hitboxY+paddingY_Top, hitboxY+currentHeight-5.0
oLeft := obs.X + paddingX
oRight := obs.X + obs.Width - paddingX + currentSpeed
oLeft, oRight := obs.X+paddingX, obs.X+obs.Width-paddingX
oTop, oBottom := obs.Y+paddingY_Top, obs.Y+obs.Height-5.0
isCollision := pRight > oLeft && pLeft < oRight && pBottom > oTop && pTop < oBottom
if isCollision {
if obs.Type == "coin" {
score += 2000
score += 2000 // Score Bonus macht das Spiel nicht mehr kaputt!
continue
} else if obs.Type == "powerup" {
if obs.ID == "p_god" {
@@ -147,17 +157,18 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
}
obstacles = nextObstacles
// Spawning
if rightmostX < GameWidth-10.0 {
rawGap := 400.0 + rng.NextRange(0, 500)
gap := float64(int(rawGap))
gap := float64(int(400.0 + rng.NextRange(0, 500)))
spawnX := rightmostX + gap
if spawnX < GameWidth {
spawnX = GameWidth
}
isBossPhase := (score % 1500) > 1200
var possibleDefs []ObstacleDef
// LOGIK FIX: Boss Phase basiert auf ZEIT (Ticks)
isBossPhase := (ticksAlive % 1500) > 1200
var possibleDefs []ObstacleDef
for _, d := range defaultConfig.Obstacles {
if isBossPhase {
if d.ID == "principal" || d.ID == "trashcan" {
@@ -167,7 +178,8 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
if d.ID == "principal" {
continue
}
if d.ID == "eraser" && score < 500 {
// Eraser kommt ab Tick 3000 (ca. 50 sekunden)
if d.ID == "eraser" && ticksAlive < 3000 {
continue
}
possibleDefs = append(possibleDefs, d)
@@ -175,7 +187,6 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
}
def := rng.PickDef(possibleDefs)
if def != nil && def.CanTalk {
if rng.NextFloat() > 0.7 {
rng.NextFloat()
@@ -186,23 +197,17 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
if def.Type == "powerup" && rng.NextFloat() > 0.1 {
def = nil
}
if def != nil {
spawnY := GroundY - def.Height - def.YOffset
obstacles = append(obstacles, ActiveObstacle{
ID: def.ID,
Type: def.Type,
X: spawnX,
Y: spawnY,
Width: def.Width,
Height: def.Height,
ID: def.ID, Type: def.Type, X: spawnX, Y: spawnY, Width: def.Width, Height: def.Height,
})
}
}
}
if !playerDead {
score++
score++ // Basis-Score läuft normal weiter
} else {
break
}
@@ -216,6 +221,7 @@ func simulateChunk(sessionID string, inputs []Input, totalTicks int, vals map[st
rdb.HSet(ctx, "session:"+sessionID, map[string]interface{}{
"score": score,
"total_ticks": ticksAlive, // NEU: Speichern
"pos_y": fmt.Sprintf("%f", posY),
"vel_y": fmt.Sprintf("%f", velY),
"rng_state": rng.State,