fix game
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 6m49s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 6m49s
This commit is contained in:
@@ -21,34 +21,23 @@ func (r *Room) CheckCoinCollision(p *ServerPlayer) {
|
||||
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 {
|
||||
if !ok || assetDef.Type != "coin" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Nur Coins prüfen
|
||||
if assetDef.Type != "coin" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Eindeutiger Key für diesen Coin
|
||||
coinKey := fmt.Sprintf("%s_%d", activeChunk.ChunkID, objIdx)
|
||||
|
||||
// Wurde bereits eingesammelt?
|
||||
if r.CollectedCoins[coinKey] {
|
||||
continue
|
||||
}
|
||||
|
||||
// Coin-Hitbox (muss DrawOffX/Y einbeziehen wie bei Obstacles!)
|
||||
coinHitbox := game.Rect{
|
||||
OffsetX: activeChunk.X + obj.X + assetDef.DrawOffX + assetDef.Hitbox.OffsetX,
|
||||
OffsetY: obj.Y + assetDef.DrawOffY + assetDef.Hitbox.OffsetY,
|
||||
@@ -56,9 +45,7 @@ func (r *Room) CheckCoinCollision(p *ServerPlayer) {
|
||||
H: assetDef.Hitbox.H,
|
||||
}
|
||||
|
||||
// Kollision?
|
||||
if game.CheckRectCollision(playerHitbox, coinHitbox) {
|
||||
// Coin einsammeln!
|
||||
r.CollectedCoins[coinKey] = true
|
||||
p.BonusScore += 200
|
||||
p.Score = p.DistanceScore + p.BonusScore
|
||||
@@ -81,34 +68,23 @@ func (r *Room) CheckPowerupCollision(p *ServerPlayer) {
|
||||
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 {
|
||||
if !ok || assetDef.Type != "powerup" {
|
||||
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,
|
||||
@@ -116,35 +92,77 @@ func (r *Room) CheckPowerupCollision(p *ServerPlayer) {
|
||||
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)
|
||||
p.DoubleJumpEndTime = time.Now().Add(15 * time.Second)
|
||||
log.Printf("⚡ %s hat Double Jump erhalten! (15 Sekunden)", 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)
|
||||
|
||||
case "magnet":
|
||||
p.HasMagnet = true
|
||||
p.MagnetEndTime = time.Now().Add(8 * time.Second)
|
||||
log.Printf("🧲 %s hat Magnet erhalten! (8 Sekunden)", p.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ApplyMagnetEffect sammelt alle Coins im Umkreis von ~300px automatisch ein
|
||||
func (r *Room) ApplyMagnetEffect(p *ServerPlayer) {
|
||||
const magnetRadius = 300.0
|
||||
|
||||
playerCenterX := p.X + r.pDrawOffX + r.pHitboxOffX + r.pW/2
|
||||
playerCenterY := p.Y + r.pDrawOffY + r.pHitboxOffY + r.pH/2
|
||||
|
||||
for _, activeChunk := range r.ActiveChunks {
|
||||
chunkDef, exists := r.World.ChunkLibrary[activeChunk.ChunkID]
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
|
||||
for objIdx, obj := range chunkDef.Objects {
|
||||
assetDef, ok := r.World.Manifest.Assets[obj.AssetID]
|
||||
if !ok || assetDef.Type != "coin" {
|
||||
continue
|
||||
}
|
||||
|
||||
coinKey := fmt.Sprintf("%s_%d", activeChunk.ChunkID, objIdx)
|
||||
if r.CollectedCoins[coinKey] {
|
||||
continue
|
||||
}
|
||||
|
||||
coinCenterX := activeChunk.X + obj.X + assetDef.DrawOffX + assetDef.Hitbox.OffsetX + assetDef.Hitbox.W/2
|
||||
coinCenterY := obj.Y + assetDef.DrawOffY + assetDef.Hitbox.OffsetY + assetDef.Hitbox.H/2
|
||||
|
||||
dx := coinCenterX - playerCenterX
|
||||
dy := coinCenterY - playerCenterY
|
||||
|
||||
if dx*dx+dy*dy <= magnetRadius*magnetRadius {
|
||||
r.CollectedCoins[coinKey] = true
|
||||
p.BonusScore += 200
|
||||
p.Score = p.DistanceScore + p.BonusScore
|
||||
log.Printf("🧲 %s hat Coin per Magnet eingesammelt! Score: %d", p.Name, p.Score)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateDistanceScore aktualisiert Distanz-basierte Punkte
|
||||
func (r *Room) UpdateDistanceScore() {
|
||||
if r.Status != "RUNNING" {
|
||||
return
|
||||
}
|
||||
|
||||
// Zähle lebende Spieler
|
||||
aliveCount := 0
|
||||
for _, p := range r.Players {
|
||||
if p.IsAlive && !p.IsSpectator {
|
||||
@@ -156,15 +174,9 @@ func (r *Room) UpdateDistanceScore() {
|
||||
return
|
||||
}
|
||||
|
||||
// Pro lebendem Spieler werden Punkte hinzugefügt
|
||||
// Dies akkumuliert die Punkte: mehr Spieler = schnellere Punktesammlung
|
||||
// Jeder Tick (bei 60 FPS) fügt aliveCount Punkte hinzu
|
||||
pointsToAdd := aliveCount
|
||||
|
||||
// Jeder lebende Spieler bekommt die gleichen Punkte
|
||||
for _, p := range r.Players {
|
||||
if p.IsAlive && !p.IsSpectator {
|
||||
p.DistanceScore += pointsToAdd
|
||||
p.DistanceScore += aliveCount
|
||||
p.Score = p.DistanceScore + p.BonusScore
|
||||
}
|
||||
}
|
||||
@@ -180,7 +192,6 @@ func (r *Room) KillPlayer(p *ServerPlayer) {
|
||||
p.IsSpectator = true
|
||||
log.Printf("💀 %s ist gestorben! Final Score: %d", p.Name, p.Score)
|
||||
|
||||
// Prüfen ob alle tot sind
|
||||
aliveCount := 0
|
||||
for _, pl := range r.Players {
|
||||
if pl.IsAlive && !pl.IsSpectator {
|
||||
|
||||
Reference in New Issue
Block a user