Try gooner animation

This commit is contained in:
2025-01-20 14:30:34 +01:00
parent bcd63efd7b
commit 0e509ad752
10 changed files with 2674 additions and 19 deletions

View File

@ -68,17 +68,14 @@ func (g *Game) Update(deltaTime float32) {
return
}
// Assign model based on player ID
modelIndex := int(playerID) % len(g.Models)
g.Player = &types.Player{
Speed: 50.0,
TargetPath: []types.Tile{},
UserData: g,
QuitDone: make(chan struct{}),
ID: playerID,
Model: g.Models[modelIndex].Model,
Texture: g.Models[modelIndex].Texture,
}
g.AssignModelToPlayer(g.Player)
go network.HandleServerCommunication(conn, playerID, g.Player, g.OtherPlayers, g.QuitChan)
g.isLoggedIn = true
@ -163,8 +160,26 @@ func (g *Game) DrawPlayer(player *types.Player, model rl.Model) {
Z: player.PosActual.Z,
}
if player.ID%int32(len(g.Models)) == 0 {
modelAsset := g.Models[0]
// Check if model has animations
if modelAsset.Animations.Idle != nil || modelAsset.Animations.Walk != nil {
if player.IsMoving && len(modelAsset.Animations.Walk) > 0 {
anim := modelAsset.Animations.Walk[0] // Use first walk animation
player.AnimationFrame = player.AnimationFrame % anim.FrameCount
rl.UpdateModelAnimation(model, anim, player.AnimationFrame)
} else if len(modelAsset.Animations.Idle) > 0 {
anim := modelAsset.Animations.Idle[0] // Use first idle animation
player.AnimationFrame = player.AnimationFrame % anim.FrameCount
rl.UpdateModelAnimation(model, anim, player.AnimationFrame)
}
}
}
rl.DrawModel(model, playerPos, 16, rl.White)
// Draw floating messages and path indicators
if player.FloatingMessage != nil {
screenPos := rl.GetWorldToScreen(rl.Vector3{
X: playerPos.X,
@ -207,12 +222,9 @@ func (g *Game) Render() {
rl.BeginMode3D(g.Camera)
g.DrawMap()
g.DrawPlayer(g.Player, g.Player.Model)
for id, other := range g.OtherPlayers {
for _, other := range g.OtherPlayers {
if other.Model.Meshes == nil {
// Assign model based on player ID for consistency
modelIndex := int(id) % len(g.Models)
other.Model = g.Models[modelIndex].Model
other.Texture = g.Models[modelIndex].Texture
g.AssignModelToPlayer(other)
}
g.DrawPlayer(other, other.Model)
}
@ -352,3 +364,12 @@ func (g *Game) Shutdown() {
func (g *Game) HandleServerMessages(messages []*pb.ChatMessage) {
g.Chat.HandleServerMessages(messages)
}
func (g *Game) AssignModelToPlayer(player *types.Player) {
modelIndex := int(player.ID) % len(g.Models)
modelAsset := g.Models[modelIndex]
// Just use the original model - don't try to copy it
player.Model = modelAsset.Model
player.Texture = modelAsset.Texture
}