2024-09-30 10:04:38 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-10-11 14:47:52 +02:00
|
|
|
"log"
|
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() {
|
2024-10-03 11:53:36 +02:00
|
|
|
rl.InitWindow(1024, 768, "GoonScape")
|
2024-09-30 15:34:16 +02:00
|
|
|
defer rl.CloseWindow()
|
2024-10-01 21:59:29 +02:00
|
|
|
rl.InitAudioDevice()
|
|
|
|
defer rl.CloseAudioDevice()
|
2024-09-30 15:34:16 +02:00
|
|
|
|
2025-01-13 11:10:48 +01:00
|
|
|
game := game.New()
|
|
|
|
if err := game.LoadAssets(); err != nil {
|
|
|
|
log.Fatalf("Failed to load assets: %v", err)
|
2024-09-30 15:34:16 +02:00
|
|
|
}
|
2025-01-13 11:10:48 +01:00
|
|
|
defer game.Cleanup()
|
2024-09-30 15:34:16 +02:00
|
|
|
|
2025-01-13 11:10:48 +01:00
|
|
|
conn, playerID, err := network.ConnectToServer()
|
2024-10-11 14:47:52 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to connect to server: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
2025-01-13 11:10:48 +01:00
|
|
|
game.Player.ID = playerID
|
|
|
|
modelIndex := int(playerID) % len(game.Models)
|
|
|
|
game.Player.Model = game.Models[modelIndex].Model
|
|
|
|
game.Player.Texture = game.Models[modelIndex].Texture
|
2024-10-11 15:58:09 +02:00
|
|
|
|
2025-01-13 11:10:48 +01:00
|
|
|
go network.HandleServerCommunication(conn, playerID, game.Player, game.OtherPlayers)
|
2024-10-31 01:06:39 +01:00
|
|
|
|
2025-01-13 11:10:48 +01:00
|
|
|
rl.PlayMusicStream(game.Music)
|
|
|
|
rl.SetMusicVolume(game.Music, 0.5)
|
2024-10-31 01:06:39 +01:00
|
|
|
rl.SetTargetFPS(60)
|
2024-10-01 21:59:29 +02:00
|
|
|
|
2024-09-30 15:34:16 +02:00
|
|
|
for !rl.WindowShouldClose() {
|
2025-01-13 11:10:48 +01:00
|
|
|
rl.UpdateMusicStream(game.Music)
|
2024-09-30 15:34:16 +02:00
|
|
|
deltaTime := rl.GetFrameTime()
|
|
|
|
|
2025-01-13 11:10:48 +01:00
|
|
|
game.Update(deltaTime)
|
|
|
|
game.Render()
|
2024-09-30 15:34:16 +02:00
|
|
|
}
|
|
|
|
}
|