add offline moving platform logic: implement dynamic platform detection and movement handling in offline mode
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m49s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m49s
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"git.zb-server.de/ZB-Server/EscapeFromTeacher/pkg/config"
|
||||
@@ -9,6 +10,26 @@ import (
|
||||
"git.zb-server.de/ZB-Server/EscapeFromTeacher/pkg/physics"
|
||||
)
|
||||
|
||||
// CheckMovingPlatformLanding prüft ob der Spieler auf einer bewegenden Plattform steht
|
||||
func (g *Game) CheckMovingPlatformLanding(x, y, w, h float64) *MovingPlatform {
|
||||
playerRect := game.Rect{OffsetX: x, OffsetY: y, W: w, H: h}
|
||||
|
||||
for _, mp := range g.offlineMovingPlatforms {
|
||||
mpRect := game.Rect{
|
||||
OffsetX: mp.CurrentX + mp.DrawOffX + mp.HitboxOffX,
|
||||
OffsetY: mp.CurrentY + mp.DrawOffY + mp.HitboxOffY,
|
||||
W: mp.HitboxW,
|
||||
H: mp.HitboxH,
|
||||
}
|
||||
|
||||
// Etwas großzügigerer Check nach oben
|
||||
if game.CheckRectCollision(playerRect, mpRect) {
|
||||
return mp
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ApplyInput wendet einen Input auf den vorhergesagten Zustand an
|
||||
// Nutzt die gemeinsame Physik-Engine aus pkg/physics
|
||||
func (g *Game) ApplyInput(input InputState) {
|
||||
@@ -20,6 +41,29 @@ func (g *Game) ApplyInput(input InputState) {
|
||||
return
|
||||
}
|
||||
|
||||
// --- OFFLINE: Mit Plattform mitbewegen ---
|
||||
if g.isOffline && g.predictedGround {
|
||||
pConst := physics.DefaultPlayerConstants()
|
||||
mp := g.CheckMovingPlatformLanding(
|
||||
g.predictedX+pConst.DrawOffX+pConst.HitboxOffX,
|
||||
g.predictedY+pConst.DrawOffY+pConst.HitboxOffY,
|
||||
pConst.Width,
|
||||
pConst.Height,
|
||||
)
|
||||
if mp != nil {
|
||||
// Berechne Plattform-Geschwindigkeit
|
||||
dx := mp.EndX - mp.StartX
|
||||
dy := mp.EndY - mp.StartY
|
||||
dist := math.Sqrt(dx*dx + dy*dy)
|
||||
if dist > 0.1 {
|
||||
vx := (dx / dist) * (mp.Speed / 20.0) * mp.Direction
|
||||
vy := (dy / dist) * (mp.Speed / 20.0) * mp.Direction
|
||||
g.predictedX += vx
|
||||
g.predictedY += vy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Horizontale Bewegung mit analogem Joystick
|
||||
moveX := 0.0
|
||||
if input.Left {
|
||||
|
||||
Reference in New Issue
Block a user