Menu with broken exit and settings
This commit is contained in:
35
game/game.go
35
game/game.go
@ -18,6 +18,7 @@ type Game struct {
|
||||
Chat *Chat
|
||||
MenuOpen bool
|
||||
QuitChan chan struct{} // Channel to signal shutdown
|
||||
QuitDone chan struct{} // New channel to signal when cleanup is complete
|
||||
}
|
||||
|
||||
func New() *Game {
|
||||
@ -29,6 +30,7 @@ func New() *Game {
|
||||
Speed: 50.0,
|
||||
TargetPath: []types.Tile{},
|
||||
UserData: nil,
|
||||
QuitDone: make(chan struct{}),
|
||||
},
|
||||
OtherPlayers: make(map[int32]*types.Player),
|
||||
Camera: rl.Camera3D{
|
||||
@ -40,6 +42,7 @@ func New() *Game {
|
||||
},
|
||||
Chat: NewChat(),
|
||||
QuitChan: make(chan struct{}),
|
||||
QuitDone: make(chan struct{}),
|
||||
}
|
||||
game.Player.UserData = game
|
||||
game.Chat.userData = game
|
||||
@ -182,6 +185,35 @@ func (g *Game) Render() {
|
||||
}
|
||||
rl.EndMode3D()
|
||||
|
||||
// Draw floating messages
|
||||
drawFloatingMessage := func(msg *types.FloatingMessage) {
|
||||
if msg == nil || time.Now().After(msg.ExpireTime) {
|
||||
return
|
||||
}
|
||||
pos := msg.ScreenPos
|
||||
text := msg.Content
|
||||
textWidth := rl.MeasureText(text, 20)
|
||||
|
||||
for offsetX := -2; offsetX <= 2; offsetX++ {
|
||||
for offsetY := -2; offsetY <= 2; offsetY++ {
|
||||
rl.DrawText(text,
|
||||
int32(pos.X)-textWidth/2+int32(offsetX),
|
||||
int32(pos.Y)+int32(offsetY),
|
||||
20,
|
||||
rl.Black)
|
||||
}
|
||||
}
|
||||
rl.DrawText(text, int32(pos.X)-textWidth/2, int32(pos.Y), 20, rl.Yellow)
|
||||
}
|
||||
|
||||
if g.Player.FloatingMessage != nil {
|
||||
drawFloatingMessage(g.Player.FloatingMessage)
|
||||
}
|
||||
|
||||
for _, other := range g.OtherPlayers {
|
||||
drawFloatingMessage(other.FloatingMessage)
|
||||
}
|
||||
|
||||
// Draw menu if open
|
||||
if g.MenuOpen {
|
||||
g.DrawMenu()
|
||||
@ -261,7 +293,8 @@ func (g *Game) DrawMenu() {
|
||||
case "Settings":
|
||||
// TODO: Implement settings
|
||||
case "Exit Game":
|
||||
close(g.QuitChan) // Signal all goroutines to shut down
|
||||
close(g.QuitChan)
|
||||
<-g.QuitDone
|
||||
rl.CloseWindow()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user