Private
Public Access
1
0

Add initial project structure for "Escape From Teacher" game: server, client, level editor, and asset framework. Includes game rendering, physics, WebSocket server, NATS integration, and asset management setup.

This commit is contained in:
Sebastian Unterschütz
2026-01-01 15:21:50 +01:00
parent 3099ac42c0
commit 4b2995846e
65 changed files with 1943 additions and 0 deletions

View File

@@ -0,0 +1,184 @@
{
"assets": {
"baskeball": {
"ID": "baskeball",
"Type": "obstacle",
"Filename": "baskeball.png",
"Scale": 0.1,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -3,
"DrawOffY": -158,
"Color": {},
"Hitbox": {
"OffsetX": 3,
"OffsetY": 64,
"W": 99,
"H": 96,
"Type": ""
}
},
"coin": {
"ID": "coin",
"Type": "obstacle",
"Filename": "coin.png",
"Scale": 0.1,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -7,
"DrawOffY": -163,
"Color": {},
"Hitbox": {
"OffsetX": 6,
"OffsetY": 63,
"W": 94,
"H": 100,
"Type": ""
}
},
"desk": {
"ID": "desk",
"Type": "obstacle",
"Filename": "desk.png",
"Scale": 0.1,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -2,
"DrawOffY": -155,
"Color": {},
"Hitbox": {
"OffsetX": 4,
"OffsetY": 65,
"W": 100,
"H": 93,
"Type": ""
}
},
"eraser": {
"ID": "eraser",
"Type": "obstacle",
"Filename": "eraser.png",
"Scale": 0.05,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -29,
"DrawOffY": -61,
"Color": {},
"Hitbox": {
"OffsetX": 30,
"OffsetY": 14,
"W": 73,
"H": 47,
"Type": ""
}
},
"g-l": {
"ID": "g-l",
"Type": "obstacle",
"Filename": "g-l.png",
"Scale": 0.5,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -65,
"DrawOffY": -381,
"Color": {},
"Hitbox": {
"OffsetX": 64,
"OffsetY": 1,
"W": 121,
"H": 384,
"Type": ""
}
},
"h-l": {
"ID": "h-l",
"Type": "obstacle",
"Filename": "h-l.png",
"Scale": 0.15,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -19,
"DrawOffY": -357,
"Color": {},
"Hitbox": {
"OffsetX": 21,
"OffsetY": 2,
"W": 107,
"H": 360,
"Type": ""
}
},
"k-l-monitor": {
"ID": "k-l-monitor",
"Type": "obstacle",
"Filename": "k-l-monitor.png",
"Scale": 0.15,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -33,
"DrawOffY": -332,
"Color": {},
"Hitbox": {
"OffsetX": 7,
"OffsetY": 10,
"W": 147,
"H": 328,
"Type": ""
}
},
"pc-trash": {
"ID": "pc-trash",
"Type": "obstacle",
"Filename": "pc-trash.png",
"Scale": 0.15,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -3,
"DrawOffY": -240,
"Color": {},
"Hitbox": {
"OffsetX": 5,
"OffsetY": 111,
"W": 154,
"H": 132,
"Type": ""
}
},
"platform_1767135546": {
"ID": "platform_1767135546",
"Type": "platform",
"Filename": "platform_1767135546.png",
"Scale": 1,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": 1,
"DrawOffY": -34,
"Color": {},
"Hitbox": {
"OffsetX": 0,
"OffsetY": 2,
"W": 126,
"H": 28,
"Type": ""
}
},
"player": {
"ID": "player",
"Type": "obstacle",
"Filename": "player.png",
"Scale": 7,
"ProcWidth": 0,
"ProcHeight": 0,
"DrawOffX": -53,
"DrawOffY": -216,
"Color": {},
"Hitbox": {
"OffsetX": 53,
"OffsetY": 12,
"W": 108,
"H": 203,
"Type": ""
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

View File

@@ -0,0 +1,36 @@
{
"ID": "chunk_01",
"Width": 50,
"Objects": [
{
"AssetID": "platform_1767135546",
"X": 419,
"Y": 517
},
{
"AssetID": "platform_1767135546",
"X": 549,
"Y": 516
},
{
"AssetID": "platform_1767135546",
"X": 682,
"Y": 449
},
{
"AssetID": "platform_1767135546",
"X": 808,
"Y": 449
},
{
"AssetID": "eraser",
"X": 1280,
"Y": 529
},
{
"AssetID": "pc-trash",
"X": 1960,
"Y": 533
}
]
}

BIN
cmd/client/assets/coin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

BIN
cmd/client/assets/desk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
cmd/client/assets/g-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 KiB

BIN
cmd/client/assets/h-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 MiB

BIN
cmd/client/assets/k-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

BIN
cmd/client/assets/k-m.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

BIN
cmd/client/assets/m-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

BIN
cmd/client/assets/p-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

BIN
cmd/client/assets/r-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

BIN
cmd/client/assets/t-s.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

BIN
cmd/client/assets/w-l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

309
cmd/client/game_render.go Normal file
View File

@@ -0,0 +1,309 @@
package main
import (
"fmt"
"image/color"
"math"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text"
"github.com/hajimehoshi/ebiten/v2/vector"
"golang.org/x/image/font/basicfont"
)
// --- INPUT & UPDATE LOGIC ---
func (g *Game) UpdateGame() {
// --- 1. KEYBOARD INPUT ---
keyLeft := ebiten.IsKeyPressed(ebiten.KeyA) || ebiten.IsKeyPressed(ebiten.KeyLeft)
keyRight := ebiten.IsKeyPressed(ebiten.KeyD) || ebiten.IsKeyPressed(ebiten.KeyRight)
keyDown := inpututil.IsKeyJustPressed(ebiten.KeyS) || inpututil.IsKeyJustPressed(ebiten.KeyDown)
keyJump := inpututil.IsKeyJustPressed(ebiten.KeySpace) || inpututil.IsKeyJustPressed(ebiten.KeyW) || inpututil.IsKeyJustPressed(ebiten.KeyUp)
// --- 2. TOUCH INPUT HANDLING ---
g.handleTouchInput()
// --- 3. INPUTS ZUSAMMENFÜHREN & SENDEN ---
if g.connected {
// A) BEWEGUNG (Links/Rechts)
// Joystick auswerten (-1 bis 1)
joyDir := 0.0
if g.joyActive {
diffX := g.joyStickX - g.joyBaseX
if diffX < -20 {
joyDir = -1
} // Nach Links gezogen
if diffX > 20 {
joyDir = 1
} // Nach Rechts gezogen
}
// Senden: Keyboard ODER Joystick
if keyLeft || joyDir == -1 {
g.SendCommand("LEFT_DOWN")
} else if keyRight || joyDir == 1 {
g.SendCommand("RIGHT_DOWN")
} else {
// Wenn weder Links noch Rechts gedrückt ist, senden wir STOP.
g.SendCommand("LEFT_UP")
g.SendCommand("RIGHT_UP")
}
// B) NACH UNTEN (Fast Fall)
// Joystick weit nach unten gezogen?
isJoyDown := false
if g.joyActive && (g.joyStickY-g.joyBaseY) > 40 {
isJoyDown = true
}
if keyDown || isJoyDown {
g.SendCommand("DOWN")
}
// C) SPRINGEN
// Keyboard ODER Touch-Button
if keyJump || g.btnJumpActive {
g.SendCommand("JUMP")
g.btnJumpActive = false // Reset (Tap to jump)
}
}
// --- 4. KAMERA LOGIK ---
g.stateMutex.Lock()
defer g.stateMutex.Unlock()
// Wir folgen strikt dem Server-Scroll.
targetCam := g.gameState.ScrollX
// Negative Kamera verhindern
if targetCam < 0 {
targetCam = 0
}
// Kamera hart setzen
g.camX = targetCam
}
// Verarbeitet Touch-Eingaben für Joystick und Buttons
func (g *Game) handleTouchInput() {
touches := ebiten.TouchIDs()
// Reset, wenn keine Finger mehr auf dem Display sind
if len(touches) == 0 {
g.joyActive = false
g.joyStickX = g.joyBaseX
g.joyStickY = g.joyBaseY
return
}
joyFound := false
for _, id := range touches {
x, y := ebiten.TouchPosition(id)
fx, fy := float64(x), float64(y)
// 1. RECHTE SEITE: JUMP BUTTON
// Alles rechts der Bildschirmmitte ist "Springen"
if fx > ScreenWidth/2 {
// Prüfen, ob dieser Touch gerade NEU dazu gekommen ist
for _, justID := range inpututil.JustPressedTouchIDs() {
if id == justID {
g.btnJumpActive = true
break
}
}
continue
}
// 2. LINKE SEITE: JOYSTICK
// Wenn wir noch keinen Joystick-Finger haben, prüfen wir, ob dieser Finger startet
if !g.joyActive {
// Prüfen ob Touch in der Nähe der Joystick-Basis ist (Radius 150 Toleranz)
dist := math.Sqrt(math.Pow(fx-g.joyBaseX, 2) + math.Pow(fy-g.joyBaseY, 2))
if dist < 150 {
g.joyActive = true
g.joyTouchID = id
}
}
// Wenn das der Joystick-Finger ist -> Stick bewegen
if g.joyActive && id == g.joyTouchID {
joyFound = true
// Vektor berechnen (Wie weit ziehen wir weg?)
dx := fx - g.joyBaseX
dy := fy - g.joyBaseY
dist := math.Sqrt(dx*dx + dy*dy)
maxDist := 60.0 // Maximaler Radius des Sticks
// Begrenzen auf Radius
if dist > maxDist {
scale := maxDist / dist
dx *= scale
dy *= scale
}
g.joyStickX = g.joyBaseX + dx
g.joyStickY = g.joyBaseY + dy
}
}
// Wenn der Joystick-Finger losgelassen wurde, Joystick resetten
if !joyFound {
g.joyActive = false
g.joyStickX = g.joyBaseX
g.joyStickY = g.joyBaseY
}
}
// --- RENDERING LOGIC ---
func (g *Game) DrawGame(screen *ebiten.Image) {
// 1. Hintergrund & Boden
screen.Fill(ColSky)
floorH := float32(ScreenHeight - RefFloorY)
vector.DrawFilledRect(screen, 0, float32(RefFloorY), float32(ScreenWidth), floorH, ColGrass, false)
vector.DrawFilledRect(screen, 0, float32(RefFloorY)+20, float32(ScreenWidth), floorH-20, ColDirt, false)
// State Locken für Datenzugriff
g.stateMutex.Lock()
defer g.stateMutex.Unlock()
// 2. Chunks (Welt-Objekte)
for _, activeChunk := range g.gameState.WorldChunks {
chunkDef, exists := g.world.ChunkLibrary[activeChunk.ChunkID]
if !exists {
continue
}
for _, obj := range chunkDef.Objects {
// Asset zeichnen
g.DrawAsset(screen, obj.AssetID, activeChunk.X+obj.X, obj.Y)
}
}
// 3. Spieler
for id, p := range g.gameState.Players {
g.DrawAsset(screen, "player", p.X, p.Y)
// Name Tag
name := p.Name
if name == "" {
name = id
}
text.Draw(screen, name, basicfont.Face7x13, int(p.X-g.camX), int(p.Y-25), ColText)
// DEBUG: Rote Hitbox
if def, ok := g.world.Manifest.Assets["player"]; ok {
hx := float32(p.X + def.DrawOffX + def.Hitbox.OffsetX - g.camX)
hy := float32(p.Y + def.DrawOffY + def.Hitbox.OffsetY)
vector.StrokeRect(screen, hx, hy, float32(def.Hitbox.W), float32(def.Hitbox.H), 2, color.RGBA{255, 0, 0, 255}, false)
}
}
// 4. UI Status
if g.gameState.Status == "COUNTDOWN" {
msg := fmt.Sprintf("GO IN: %d", g.gameState.TimeLeft)
text.Draw(screen, msg, basicfont.Face7x13, ScreenWidth/2-40, ScreenHeight/2, color.RGBA{255, 255, 0, 255})
} else if g.gameState.Status == "RUNNING" {
dist := fmt.Sprintf("Distance: %.0f m", g.camX/64.0)
text.Draw(screen, dist, basicfont.Face7x13, ScreenWidth-150, 30, ColText)
}
// 5. DEBUG: TODES-LINIE
vector.StrokeLine(screen, 0, 0, 0, float32(ScreenHeight), 10, color.RGBA{255, 0, 0, 128}, false)
text.Draw(screen, "! DEATH ZONE !", basicfont.Face7x13, 10, ScreenHeight/2, color.RGBA{255, 0, 0, 255})
// 6. TOUCH CONTROLS OVERLAY
// A) Joystick Base
baseCol := color.RGBA{255, 255, 255, 50}
vector.DrawFilledCircle(screen, float32(g.joyBaseX), float32(g.joyBaseY), 60, baseCol, true)
vector.StrokeCircle(screen, float32(g.joyBaseX), float32(g.joyBaseY), 60, 2, color.RGBA{255, 255, 255, 100}, true)
// B) Joystick Knob
knobCol := color.RGBA{255, 255, 255, 150}
if g.joyActive {
knobCol = color.RGBA{100, 255, 100, 200}
}
vector.DrawFilledCircle(screen, float32(g.joyStickX), float32(g.joyStickY), 30, knobCol, true)
// C) Jump Button (Rechts)
jumpX := float32(ScreenWidth - 150)
jumpY := float32(ScreenHeight - 150)
vector.DrawFilledCircle(screen, jumpX, jumpY, 50, color.RGBA{255, 0, 0, 50}, true)
vector.StrokeCircle(screen, jumpX, jumpY, 50, 2, color.RGBA{255, 0, 0, 100}, true)
text.Draw(screen, "JUMP", basicfont.Face7x13, int(jumpX)-15, int(jumpY)+5, color.White)
// 7. DEBUG INFO (Oben Links)
myPosStr := "N/A"
for _, p := range g.gameState.Players {
myPosStr = fmt.Sprintf("X:%.0f Y:%.0f", p.X, p.Y)
break
}
debugMsg := fmt.Sprintf(
"FPS: %.2f\nState: %s\nPlayers: %d\nCamX: %.0f\nPos: %s",
ebiten.CurrentFPS(),
g.gameState.Status,
len(g.gameState.Players),
g.camX,
myPosStr,
)
vector.DrawFilledRect(screen, 10, 10, 200, 90, color.RGBA{0, 0, 0, 180}, false)
text.Draw(screen, debugMsg, basicfont.Face7x13, 20, 30, color.White)
}
// --- ASSET HELPER ---
func (g *Game) DrawAsset(screen *ebiten.Image, assetID string, worldX, worldY float64) {
// 1. Definition laden
def, ok := g.world.Manifest.Assets[assetID]
if !ok {
return
}
// 2. Screen Position berechnen (Welt - Kamera)
screenX := worldX - g.camX
screenY := worldY
// Optimierung: Nicht zeichnen, wenn komplett außerhalb
if screenX < -200 || screenX > ScreenWidth+200 {
return
}
// 3. Bild holen
img := g.assetsImages[assetID]
if img != nil {
op := &ebiten.DrawImageOptions{}
// Skalieren
op.GeoM.Scale(def.Scale, def.Scale)
// Positionieren: ScreenPos + DrawOffset
op.GeoM.Translate(
screenX+def.DrawOffX,
screenY+def.DrawOffY,
)
// Farbe anwenden
op.ColorScale.ScaleWithColor(def.Color.ToRGBA())
screen.DrawImage(img, op)
} else {
// FALLBACK (Buntes Rechteck)
vector.DrawFilledRect(screen,
float32(screenX+def.Hitbox.OffsetX),
float32(screenY+def.Hitbox.OffsetY),
float32(def.Hitbox.W),
float32(def.Hitbox.H),
def.Color.ToRGBA(),
false,
)
}
}

21
cmd/client/go.mod Normal file
View File

@@ -0,0 +1,21 @@
module git.zb-server.de/ZB-Server/EscapeFromTeacher/client
go 1.25.5
require (
github.com/hajimehoshi/ebiten/v2 v2.9.6
github.com/nats-io/nats.go v1.47.0
)
require (
github.com/ebitengine/gomobile v0.0.0-20250923094054-ea854a63cce1 // indirect
github.com/ebitengine/hideconsole v1.0.0 // indirect
github.com/ebitengine/purego v0.9.0 // indirect
github.com/jezek/xgb v1.1.1 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/nats-io/nkeys v0.4.11 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.36.0 // indirect
)

26
cmd/client/go.sum Normal file
View File

@@ -0,0 +1,26 @@
github.com/ebitengine/gomobile v0.0.0-20250923094054-ea854a63cce1 h1:+kz5iTT3L7uU+VhlMfTb8hHcxLO3TlaELlX8wa4XjA0=
github.com/ebitengine/gomobile v0.0.0-20250923094054-ea854a63cce1/go.mod h1:lKJoeixeJwnFmYsBny4vvCJGVFc3aYDalhuDsfZzWHI=
github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj1yReDqE=
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
github.com/ebitengine/purego v0.9.0 h1:mh0zpKBIXDceC63hpvPuGLiJ8ZAa3DfrFTudmfi8A4k=
github.com/ebitengine/purego v0.9.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/hajimehoshi/ebiten/v2 v2.9.6 h1:uP41hMkfcbfEfgiTlpzhgnTHGAAfbM/v/pNOZkelI78=
github.com/hajimehoshi/ebiten/v2 v2.9.6/go.mod h1:DAt4tnkYYpCvu3x9i1X/nK/vOruNXIlYq/tBXxnhrXM=
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/nats-io/nats.go v1.47.0 h1:YQdADw6J/UfGUd2Oy6tn4Hq6YHxCaJrVKayxxFqYrgM=
github.com/nats-io/nats.go v1.47.0/go.mod h1:iRWIPokVIFbVijxuMQq4y9ttaBTMe0SFdlZfMDd+33g=
github.com/nats-io/nkeys v0.4.11 h1:q44qGV008kYd9W1b1nEBkNzvnWxtRSQ7A8BoqRrcfa0=
github.com/nats-io/nkeys v0.4.11/go.mod h1:szDimtgmfOi9n25JpfIdGw12tZFYXqhGxjhVxsatHVE=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/image v0.31.0 h1:mLChjE2MV6g1S7oqbXC0/UcKijjm5fnJLUYKIYrLESA=
golang.org/x/image v0.31.0/go.mod h1:R9ec5Lcp96v9FTF+ajwaH3uGxPH4fKfHHAVbUILxghA=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=