Private
Public Access
1
0

Add WebAssembly support for assets and chunks, implement gameover screen rendering, and enhance server gameplay logic with dynamic speeds, team naming, and score components.

This commit is contained in:
Sebastian Unterschütz
2026-01-04 14:30:31 +01:00
parent ce51a2ba4f
commit 95d61bf66e
68 changed files with 913 additions and 424 deletions

View File

@@ -23,6 +23,8 @@ type ServerPlayer struct {
InputX float64 // -1 (Links), 0, 1 (Rechts)
LastInputSeq uint32 // Letzte verarbeitete Input-Sequenz
Score int
DistanceScore int // Score basierend auf zurückgelegter Distanz
BonusScore int // Score aus Coins und anderen Boni
IsAlive bool
IsSpectator bool
@@ -68,9 +70,12 @@ type Room struct {
Countdown int
NextStart time.Time
HostID string
TeamName string // Name des Teams (vom Host gesetzt)
CollectedCoins map[string]bool // Key: "chunkID_objectIndex"
CollectedPowerups map[string]bool // Key: "chunkID_objectIndex"
ScoreAccum float64 // Akkumulator für Distanz-Score
CurrentSpeed float64 // Aktuelle Geschwindigkeit (steigt mit der Zeit)
GameStartTime time.Time // Wann das Spiel gestartet wurde
// Chunk-Pool für fairen Random-Spawn
ChunkPool []string // Verfügbare Chunks für nächsten Spawn
@@ -100,7 +105,8 @@ func NewRoom(id string, nc *nats.Conn, w *game.World) *Room {
CollectedCoins: make(map[string]bool),
CollectedPowerups: make(map[string]bool),
ChunkSpawnedCount: make(map[string]int),
pW: 40, pH: 60, // Fallback
CurrentSpeed: config.RunSpeed, // Startet mit normaler Geschwindigkeit
pW: 40, pH: 60, // Fallback
}
// Initialisiere Chunk-Pool mit allen verfügbaren Chunks
@@ -281,6 +287,12 @@ func (r *Room) HandleInput(input game.ClientInput) {
if input.PlayerID == r.HostID && r.Status == "LOBBY" {
r.StartCountdown()
}
case "SET_TEAM_NAME":
// Nur Host darf Team-Name setzen und nur in der Lobby
if input.PlayerID == r.HostID && r.Status == "LOBBY" {
r.TeamName = input.TeamName
log.Printf("🏷️ Team-Name gesetzt: '%s' (von Host %s)", r.TeamName, p.Name)
}
}
}
@@ -301,9 +313,19 @@ func (r *Room) Update() {
r.Countdown = int(rem.Seconds()) + 1
if rem <= 0 {
r.Status = "RUNNING"
r.GameStartTime = time.Now()
r.CurrentSpeed = config.RunSpeed
}
} else if r.Status == "RUNNING" {
r.GlobalScrollX += config.RunSpeed
// Geschwindigkeit erhöhen: +0.5 pro 10 Sekunden (max +5.0 nach 100 Sekunden)
elapsed := time.Since(r.GameStartTime).Seconds()
speedIncrease := (elapsed / 10.0) * 0.5
if speedIncrease > 5.0 {
speedIncrease = 5.0
}
r.CurrentSpeed = config.RunSpeed + speedIncrease
r.GlobalScrollX += r.CurrentSpeed
// Bewegende Plattformen updaten
r.UpdateMovingPlatforms()
}
@@ -333,9 +355,9 @@ func (r *Room) Update() {
// X Bewegung
// Symmetrische Geschwindigkeit: Links = Rechts
// Nach rechts: RunSpeed + 11, Nach links: RunSpeed - 11
// Ergebnis: Rechts = 18, Links = -4 (beide gleich weit vom Scroll)
currentSpeed := config.RunSpeed + (p.InputX * 11.0)
// Nach rechts: CurrentSpeed + 11, Nach links: CurrentSpeed - 11
// Verwendet r.CurrentSpeed statt config.RunSpeed für dynamische Geschwindigkeit
currentSpeed := r.CurrentSpeed + (p.InputX * 11.0)
nextX := p.X + currentSpeed
hitX, typeX := r.CheckCollision(nextX+r.pDrawOffX+r.pHitboxOffX, p.Y+r.pDrawOffY+r.pHitboxOffY, r.pW, r.pH)
@@ -343,7 +365,7 @@ func (r *Room) Update() {
if typeX == "wall" {
// Wand getroffen - kann klettern!
p.OnWall = true
// X-Position nicht ändern (bleibt an der Wand)
// X-Position NICHT ändern (bleibt vor der Wand stehen)
} else if typeX == "obstacle" {
// Godmode prüfen
if p.HasGodMode && time.Now().Before(p.GodModeEndTime) {
@@ -405,15 +427,9 @@ func (r *Room) Update() {
hitY, typeY := r.CheckCollision(p.X+r.pDrawOffX+r.pHitboxOffX, nextY+r.pDrawOffY+r.pHitboxOffY, r.pW, r.pH)
if hitY {
if typeY == "wall" {
// An der Wand: Nicht töten, sondern Position halten
if p.OnWall {
p.VY = 0
} else {
// Von oben/unten gegen Wand - töten (kein Klettern in Y-Richtung)
p.Y = nextY
r.KillPlayer(p)
continue
}
// An der Wand: Nicht töten, Position halten und klettern ermöglichen
p.VY = 0
p.OnWall = true
} else if typeY == "obstacle" {
// Obstacle - immer töten
p.Y = nextY
@@ -774,6 +790,7 @@ func (r *Room) Broadcast() {
TimeLeft: r.Countdown,
WorldChunks: r.ActiveChunks,
HostID: r.HostID,
TeamName: r.TeamName,
ScrollX: r.GlobalScrollX,
CollectedCoins: r.CollectedCoins,
CollectedPowerups: r.CollectedPowerups,