2024-01-26 16:14:20 +00:00
|
|
|
package game
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"math"
|
|
|
|
"net"
|
|
|
|
"server/game/packet"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Move updates the location and direction the client is currently moving towards.
|
|
|
|
func (game *Game) Move(data []byte, address *net.UDPAddr, server *Server) error {
|
|
|
|
player := game.players.Get(address)
|
|
|
|
player.Position.X = math.Float32frombits(binary.LittleEndian.Uint32(data))
|
|
|
|
player.Position.Z = math.Float32frombits(binary.LittleEndian.Uint32(data[4:]))
|
|
|
|
|
|
|
|
update := []byte(player.ID)
|
|
|
|
update = AppendFloat(update, player.Position.X)
|
|
|
|
update = AppendFloat(update, player.Position.Z)
|
|
|
|
|
2024-01-26 21:45:26 +00:00
|
|
|
game.BroadcastOthers(packet.PlayerMove, update, player)
|
2024-01-26 16:14:20 +00:00
|
|
|
return nil
|
|
|
|
}
|