Implemented jumps
This commit is contained in:
@ -30,6 +30,18 @@ func (game *Game) Run() {
|
||||
<-close
|
||||
}
|
||||
|
||||
// BroadcastOthers sends the packet to all other players.
|
||||
func (game *Game) BroadcastOthers(code byte, data []byte, exclude *Player) {
|
||||
game.players.Each(func(other *Player) bool {
|
||||
if other == exclude {
|
||||
return true
|
||||
}
|
||||
|
||||
game.server.Send(code, data, other.address)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// start starts all game systems.
|
||||
func (game *Game) start() {
|
||||
go game.network()
|
||||
@ -42,6 +54,7 @@ func (game *Game) network() {
|
||||
game.server.SetHandler(packet.Ping, game.Ping)
|
||||
game.server.SetHandler(packet.Login, game.Login)
|
||||
game.server.SetHandler(packet.PlayerMove, game.Move)
|
||||
game.server.SetHandler(packet.PlayerJump, game.Jump)
|
||||
game.server.Run(4242)
|
||||
}
|
||||
|
||||
|
13
server/game/Jump.go
Normal file
13
server/game/Jump.go
Normal file
@ -0,0 +1,13 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"net"
|
||||
"server/game/packet"
|
||||
)
|
||||
|
||||
// Jump broadcasts the jump action.
|
||||
func (game *Game) Jump(data []byte, address *net.UDPAddr, server *Server) error {
|
||||
player := game.players.Get(address)
|
||||
game.BroadcastOthers(packet.PlayerJump, []byte(player.ID), player)
|
||||
return nil
|
||||
}
|
@ -17,14 +17,6 @@ func (game *Game) Move(data []byte, address *net.UDPAddr, server *Server) error
|
||||
update = AppendFloat(update, player.Position.X)
|
||||
update = AppendFloat(update, player.Position.Z)
|
||||
|
||||
game.players.Each(func(other *Player) bool {
|
||||
if other == player {
|
||||
return true
|
||||
}
|
||||
|
||||
game.server.Send(packet.PlayerMove, update, other.address)
|
||||
return true
|
||||
})
|
||||
|
||||
game.BroadcastOthers(packet.PlayerMove, update, player)
|
||||
return nil
|
||||
}
|
||||
|
@ -7,4 +7,6 @@ const (
|
||||
PlayerAdd = 10
|
||||
PlayerRemove = 11
|
||||
PlayerMove = 12
|
||||
PlayerJump = 13
|
||||
PlayerAttack = 14
|
||||
)
|
||||
|
Reference in New Issue
Block a user