feature/menu #3

Merged
bdnugget merged 4 commits from feature/menu into master 2025-01-18 22:26:19 +00:00
3 changed files with 78 additions and 27 deletions
Showing only changes of commit fb018e2a7d - Show all commits

View File

@ -168,13 +168,12 @@ func (c *Chat) Update() (string, bool) {
c.inputBuffer = c.inputBuffer[:0]
c.cursorPos = 0
c.isTyping = false
return message, true
}
c.isTyping = false
}
if rl.IsKeyPressed(rl.KeyEscape) {
if rl.IsKeyPressed(rl.KeyEscape) && c.isTyping {
c.inputBuffer = c.inputBuffer[:0]
c.cursorPos = 0
c.isTyping = false

View File

@ -16,6 +16,7 @@ type Game struct {
Models []types.ModelAsset
Music rl.Music
Chat *Chat
MenuOpen bool
}
func New() *Game {
@ -59,6 +60,17 @@ func (g *Game) LoadAssets() error {
}
func (g *Game) Update(deltaTime float32) {
// Handle ESC for menu
if rl.IsKeyPressed(rl.KeyEscape) {
g.MenuOpen = !g.MenuOpen
return
}
// Don't process other inputs if menu is open
if g.MenuOpen {
return
}
if message, sent := g.Chat.Update(); sent {
g.Player.Lock()
g.Player.ActionQueue = append(g.Player.ActionQueue, &pb.Action{
@ -168,36 +180,17 @@ func (g *Game) Render() {
}
rl.EndMode3D()
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)
// Draw menu if open
if g.MenuOpen {
g.DrawMenu()
}
if g.Player.FloatingMessage != nil {
drawFloatingMessage(g.Player.FloatingMessage)
}
for _, other := range g.OtherPlayers {
drawFloatingMessage(other.FloatingMessage)
// Only draw chat if menu is not open
if !g.MenuOpen {
g.Chat.Draw(int32(rl.GetScreenWidth()), int32(rl.GetScreenHeight()))
}
rl.DrawFPS(10, 10)
g.Chat.Draw(int32(rl.GetScreenWidth()), int32(rl.GetScreenHeight()))
rl.EndDrawing()
}
@ -223,3 +216,61 @@ func (g *Game) HandleInput() {
}
}
}
func (g *Game) DrawMenu() {
screenWidth := float32(rl.GetScreenWidth())
screenHeight := float32(rl.GetScreenHeight())
// Semi-transparent background
rl.DrawRectangle(0, 0, int32(screenWidth), int32(screenHeight), rl.ColorAlpha(rl.Black, 0.7))
// Menu title
title := "Menu"
titleSize := int32(40)
titleWidth := rl.MeasureText(title, titleSize)
rl.DrawText(title, int32(screenWidth/2)-titleWidth/2, 100, titleSize, rl.White)
// Menu buttons
buttonWidth := float32(200)
buttonHeight := float32(40)
buttonY := float32(200)
buttonSpacing := float32(60)
menuItems := []string{"Resume", "Settings", "Exit Game"}
for _, item := range menuItems {
buttonRect := rl.Rectangle{
X: screenWidth/2 - buttonWidth/2,
Y: buttonY,
Width: buttonWidth,
Height: buttonHeight,
}
// Check mouse hover
mousePoint := rl.GetMousePosition()
mouseHover := rl.CheckCollisionPointRec(mousePoint, buttonRect)
// Draw button
if mouseHover {
rl.DrawRectangleRec(buttonRect, rl.ColorAlpha(rl.White, 0.3))
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
switch item {
case "Resume":
g.MenuOpen = false
case "Settings":
// TODO: Implement settings
case "Exit Game":
rl.CloseWindow()
}
}
}
// Draw button text
textSize := int32(20)
textWidth := rl.MeasureText(item, textSize)
textX := int32(buttonRect.X+buttonRect.Width/2) - textWidth/2
textY := int32(buttonRect.Y + buttonRect.Height/2 - float32(textSize)/2)
rl.DrawText(item, textX, textY, textSize, rl.White)
buttonY += buttonSpacing
}
}

View File

@ -30,6 +30,7 @@ func main() {
}
rl.InitWindow(1024, 768, "GoonScape")
rl.SetExitKey(0)
defer rl.CloseWindow()
rl.InitAudioDevice()
defer rl.CloseAudioDevice()