2024-09-30 10:04:38 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-01-18 14:23:48 +01:00
|
|
|
"flag"
|
2024-10-11 14:47:52 +02:00
|
|
|
"log"
|
2025-01-18 20:38:35 +01:00
|
|
|
"strings"
|
2024-09-30 10:04:38 +02:00
|
|
|
|
2025-01-13 11:10:48 +01:00
|
|
|
"gitea.boner.be/bdnugget/goonscape/game"
|
|
|
|
"gitea.boner.be/bdnugget/goonscape/network"
|
2024-09-30 10:04:38 +02:00
|
|
|
rl "github.com/gen2brain/raylib-go/raylib"
|
2024-09-30 15:34:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2025-01-19 21:23:47 +01:00
|
|
|
// Parse command line flags
|
|
|
|
local := flag.Bool("local", false, "Connect to local server")
|
|
|
|
addr := flag.String("addr", "", "Server address (host or host:port)")
|
2025-01-18 14:23:48 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
2025-01-19 21:23:47 +01:00
|
|
|
// Set server address based on flags
|
2025-01-18 14:23:48 +01:00
|
|
|
if *local {
|
2025-01-19 21:23:47 +01:00
|
|
|
if *addr != "" {
|
|
|
|
log.Fatal("Cannot use -local and -addr together")
|
|
|
|
}
|
2025-01-18 14:23:48 +01:00
|
|
|
network.SetServerAddr("localhost:6969")
|
2025-01-18 20:38:35 +01:00
|
|
|
} else if *addr != "" {
|
2025-01-19 21:23:47 +01:00
|
|
|
// If port is not specified, append default port
|
2025-01-18 20:38:35 +01:00
|
|
|
if !strings.Contains(*addr, ":") {
|
2025-01-19 21:23:47 +01:00
|
|
|
*addr += ":6969"
|
2025-01-18 20:38:35 +01:00
|
|
|
}
|
|
|
|
network.SetServerAddr(*addr)
|
2025-01-18 14:23:48 +01:00
|
|
|
}
|
|
|
|
|
2024-10-03 11:53:36 +02:00
|
|
|
rl.InitWindow(1024, 768, "GoonScape")
|
2025-01-18 22:23:08 +01:00
|
|
|
rl.SetExitKey(0)
|
2025-01-23 09:42:42 +01:00
|
|
|
defer rl.CloseWindow()
|
2025-01-22 20:14:58 +01:00
|
|
|
|
2025-01-23 09:42:42 +01:00
|
|
|
rl.InitAudioDevice()
|
|
|
|
defer rl.CloseAudioDevice()
|
2024-09-30 15:34:16 +02:00
|
|
|
|
2025-01-19 21:23:47 +01:00
|
|
|
rl.SetTargetFPS(60)
|
|
|
|
|
2025-01-23 09:42:42 +01:00
|
|
|
game := game.New()
|
|
|
|
if err := game.LoadAssets(); err != nil {
|
|
|
|
log.Fatalf("Failed to load assets: %v", err)
|
|
|
|
}
|
|
|
|
defer game.Cleanup()
|
2024-09-30 15:34:16 +02:00
|
|
|
|
2025-01-23 09:42:42 +01:00
|
|
|
rl.PlayMusicStream(game.Music)
|
|
|
|
rl.SetMusicVolume(game.Music, 0.5)
|
2024-10-01 21:59:29 +02:00
|
|
|
|
2024-09-30 15:34:16 +02:00
|
|
|
for !rl.WindowShouldClose() {
|
|
|
|
deltaTime := rl.GetFrameTime()
|
2025-01-23 09:42:42 +01:00
|
|
|
rl.UpdateMusicStream(game.Music)
|
|
|
|
game.Update(deltaTime)
|
|
|
|
game.Render()
|
2025-01-22 20:14:58 +01:00
|
|
|
}
|
2025-01-23 09:42:42 +01:00
|
|
|
|
|
|
|
// Wait for clean shutdown
|
|
|
|
<-game.QuitChan
|
2024-09-30 15:34:16 +02:00
|
|
|
}
|