Private
Public Access
1
0

- Refactor dirt and stone generation to optimize visible depth and adjust randomization.
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 8m32s

- Remove unused `StartWebSocketGateway` function from `websocket_gateway.go`.
- Add security checks to track player-room mapping, enforce valid input, and prevent ID spoofing in `gateway.go`.
- Refactor touch control logic to dynamically position joystick and buttons above gameplay floor.
- Introduce dynamic floor Y-coordinate calculation (`GetFloorYFromHeight`) for better scaling across different screen sizes.
- Adjust rendering logic to align assets, particles, and debug visuals with dynamic screen height transformations.
- Update canvas CSS to support fullscreen scaling without center alignment.
This commit is contained in:
Sebastian Unterschütz
2026-01-09 21:34:24 +01:00
parent d156dce2e7
commit 4be6cc791e
10 changed files with 250 additions and 77 deletions

View File

@@ -30,7 +30,8 @@ const (
StateLobby = 1
StateGame = 2
StateLeaderboard = 3
RefFloorY = 540
RefFloorY = 540 // Server-Welt Boden-Position (unveränderlich)
RefFloorYMobile = 270 // Nicht mehr verwendet
)
var (
@@ -122,6 +123,7 @@ type Game struct {
joyTouchID ebiten.TouchID
btnJumpActive bool
keyboardUsed bool // Wurde Tastatur benutzt?
lastCanvasHeight int // Cache der Canvas-Höhe für Touch-Input
// Debug Stats
showDebug bool // Debug-Overlay anzeigen (F3 zum Umschalten)
@@ -632,12 +634,104 @@ func (g *Game) DrawLobby(screen *ebiten.Image) {
}
func (g *Game) Layout(w, h int) (int, int) {
// Nutze die GESAMTE Bildschirmfläche ohne Einschränkungen
// Nutze die echte Window-Größe (Mobile: ~360px Höhe, Desktop: 720px+ Höhe)
// Das erlaubt dynamische Anpassung an verschiedene Bildschirmgrößen
return w, h
}
// --- HELPER ---
// GetFloorY gibt die Y-Position des Bodens basierend auf der aktuellen Bildschirmhöhe zurück
// WICHTIG: Kann nicht direkt aufgerufen werden, braucht Screen-Höhe als Parameter!
func GetFloorYFromHeight(screenHeight int) float64 {
h := screenHeight
if h == 0 {
// Fallback wenn keine Höhe verfügbar
h = ScreenHeight // 720
log.Printf("⚠️ GetFloorY: Screen height is 0, using fallback: %d", h)
}
// Ziel: Gameplay füllt den Bildschirm optimal aus
// Erde-Tiefe: ~100px (kompakt, damit mehr Gameplay-Raum bleibt)
dirtDepth := 100.0
// Berechne Boden-Position: möglichst weit unten
floorY := float64(h) - dirtDepth
// Minimum-Check: Bei sehr kleinen Bildschirmen (< 300px) mindestens 70% Höhe
minFloorY := float64(h) * 0.7
if floorY < minFloorY {
floorY = minFloorY
}
return floorY
}
// GetFloorY - Wrapper der versucht die Höhe zu bekommen (deprecated, benutze GetFloorYFromHeight)
func GetFloorY() float64 {
_, h := ebiten.WindowSize()
return GetFloorYFromHeight(h)
}
// GetScale gibt den Scale-Faktor zurück um die Spielwelt an den Bildschirm anzupassen
// Auf Mobile: Scale < 1.0 (rauszoomen, damit mehr sichtbar ist)
// Auf Desktop: Scale = 1.0 (normale Größe)
func GetScale() float64 {
_, h := ebiten.WindowSize()
if h == 0 {
h = ScreenHeight
}
// Mobile Geräte (kleine Bildschirme): Rauszoomen für bessere Sicht
if h <= 400 {
// Sehr kleine Bildschirme: 0.7x Scale (30% rauszoomen)
return 0.7
} else if h <= 600 {
// Mittlere Bildschirme: 0.85x Scale (15% rauszoomen)
return 0.85
}
// Desktop/große Bildschirme: Normale Größe
return 1.0
}
// GetScaleFromHeight - Scale mit expliziter Höhe
func GetScaleFromHeight(screenHeight int) float64 {
h := screenHeight
if h == 0 {
h = ScreenHeight
}
if h <= 400 {
return 0.7
} else if h <= 600 {
return 0.85
}
return 1.0
}
// WorldToScreenY konvertiert Server-Welt-Y-Koordinate zu Bildschirm-Y-Koordinate
// Nimmt die tatsächliche Bildschirmhöhe als Parameter (wichtig für WASM!)
func WorldToScreenYWithHeight(worldY float64, screenHeight int) float64 {
// Server arbeitet mit festen Koordinaten (Boden bei Y=540 für 720px Referenz)
// Client will Boden dynamisch positionieren
serverFloorY := float64(RefFloorY) // Server-Boden (540 bei 720px)
clientFloorY := GetFloorYFromHeight(screenHeight) // Client-Boden (dynamisch)
yOffset := clientFloorY - serverFloorY // Verschiebung (z.B. 620 - 540 = +80px nach unten)
return worldY + yOffset
}
// WorldToScreenY - Legacy wrapper (versucht WindowSize zu verwenden, funktioniert nicht in WASM!)
func WorldToScreenY(worldY float64) float64 {
_, h := ebiten.WindowSize()
if h == 0 {
h = ScreenHeight // Fallback
}
return WorldToScreenYWithHeight(worldY, h)
}
func isHit(x, y, w, h int) bool {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
mx, my := ebiten.CursorPosition()