Private
Public Access
1
0

Add platform-specific implementations for assets, audio, WebSocket, and rendering on Desktop and WebAssembly platforms. Introduce embedded assets for WebAssembly and native file handling for Desktop. Add platform-specific chunk loading and game state synchronization.

This commit is contained in:
Sebastian Unterschütz
2026-01-04 01:25:04 +01:00
parent 85d697df19
commit 3232ee7c2f
86 changed files with 4931 additions and 486 deletions

View File

@@ -3,6 +3,7 @@ package server
import (
"fmt"
"log"
"time"
"git.zb-server.de/ZB-Server/EscapeFromTeacher/pkg/game"
)
@@ -47,10 +48,10 @@ func (r *Room) CheckCoinCollision(p *ServerPlayer) {
continue
}
// Coin-Hitbox
// Coin-Hitbox (muss DrawOffX/Y einbeziehen wie bei Obstacles!)
coinHitbox := game.Rect{
OffsetX: activeChunk.X + obj.X + assetDef.Hitbox.OffsetX,
OffsetY: obj.Y + assetDef.Hitbox.OffsetY,
OffsetX: activeChunk.X + obj.X + assetDef.DrawOffX + assetDef.Hitbox.OffsetX,
OffsetY: obj.Y + assetDef.DrawOffY + assetDef.Hitbox.OffsetY,
W: assetDef.Hitbox.W,
H: assetDef.Hitbox.H,
}
@@ -66,39 +67,93 @@ func (r *Room) CheckCoinCollision(p *ServerPlayer) {
}
}
// CheckPowerupCollision prüft ob Spieler Powerups einsammelt
func (r *Room) CheckPowerupCollision(p *ServerPlayer) {
if !p.IsAlive || p.IsSpectator {
return
}
playerHitbox := game.Rect{
OffsetX: p.X + r.pDrawOffX + r.pHitboxOffX,
OffsetY: p.Y + r.pDrawOffY + r.pHitboxOffY,
W: r.pW,
H: r.pH,
}
// Durch alle aktiven Chunks iterieren
for _, activeChunk := range r.ActiveChunks {
chunkDef, exists := r.World.ChunkLibrary[activeChunk.ChunkID]
if !exists {
continue
}
// Durch alle Objekte im Chunk
for objIdx, obj := range chunkDef.Objects {
assetDef, ok := r.World.Manifest.Assets[obj.AssetID]
if !ok {
continue
}
// Nur Powerups prüfen
if assetDef.Type != "powerup" {
continue
}
// Eindeutiger Key für dieses Powerup
powerupKey := fmt.Sprintf("%s_%d", activeChunk.ChunkID, objIdx)
// Wurde bereits eingesammelt?
if r.CollectedPowerups[powerupKey] {
continue
}
// Powerup-Hitbox
powerupHitbox := game.Rect{
OffsetX: activeChunk.X + obj.X + assetDef.DrawOffX + assetDef.Hitbox.OffsetX,
OffsetY: obj.Y + assetDef.DrawOffY + assetDef.Hitbox.OffsetY,
W: assetDef.Hitbox.W,
H: assetDef.Hitbox.H,
}
// Kollision?
if game.CheckRectCollision(playerHitbox, powerupHitbox) {
// Powerup einsammeln!
r.CollectedPowerups[powerupKey] = true
// Powerup-Effekt anwenden
switch obj.AssetID {
case "jumpboost":
p.HasDoubleJump = true
p.DoubleJumpUsed = false
log.Printf("⚡ %s hat Double Jump erhalten!", p.Name)
case "godmode":
p.HasGodMode = true
p.GodModeEndTime = time.Now().Add(10 * time.Second)
log.Printf("🛡️ %s hat Godmode erhalten! (10 Sekunden)", p.Name)
}
}
}
}
}
// UpdateDistanceScore aktualisiert Distanz-basierte Punkte
func (r *Room) UpdateDistanceScore() {
if r.Status != "RUNNING" {
return
}
// Anzahl lebender Spieler zählen
aliveCount := 0
// Jeder Spieler bekommt Punkte basierend auf seiner eigenen Distanz
// Punkte = (X-Position / TileSize) = Distanz in Tiles
for _, p := range r.Players {
if p.IsAlive && !p.IsSpectator {
aliveCount++
}
}
// Berechne Score basierend auf X-Position
// 1 Punkt pro Tile (64px)
newScore := int(p.X / 64.0)
if aliveCount == 0 {
return
}
// Multiplier = Anzahl lebender Spieler
multiplier := float64(aliveCount)
// Akkumulator erhöhen: multiplier Punkte pro Sekunde
// Bei 60 FPS: multiplier / 60.0 Punkte pro Tick
r.ScoreAccum += multiplier / 60.0
// Wenn Akkumulator >= 1.0, Punkte vergeben
if r.ScoreAccum >= 1.0 {
pointsToAdd := int(r.ScoreAccum)
r.ScoreAccum -= float64(pointsToAdd)
for _, p := range r.Players {
if p.IsAlive && !p.IsSpectator {
p.Score += pointsToAdd
// Nur updaten wenn höher als aktueller Score
if newScore > p.Score {
p.Score = newScore
}
}
}