Add chat
This commit is contained in:
17
game/game.go
17
game/game.go
@ -13,6 +13,7 @@ type Game struct {
|
||||
Camera rl.Camera3D
|
||||
Models []types.ModelAsset
|
||||
Music rl.Music
|
||||
Chat *Chat
|
||||
}
|
||||
|
||||
func New() *Game {
|
||||
@ -23,6 +24,7 @@ func New() *Game {
|
||||
PosTile: GetTile(5, 5),
|
||||
Speed: 50.0,
|
||||
TargetPath: []types.Tile{},
|
||||
UserData: nil,
|
||||
},
|
||||
OtherPlayers: make(map[int32]*types.Player),
|
||||
Camera: rl.Camera3D{
|
||||
@ -32,7 +34,9 @@ func New() *Game {
|
||||
Fovy: 45.0,
|
||||
Projection: rl.CameraPerspective,
|
||||
},
|
||||
Chat: NewChat(),
|
||||
}
|
||||
game.Player.UserData = game
|
||||
return game
|
||||
}
|
||||
|
||||
@ -52,6 +56,16 @@ func (g *Game) LoadAssets() error {
|
||||
}
|
||||
|
||||
func (g *Game) Update(deltaTime float32) {
|
||||
if message, sent := g.Chat.Update(); sent {
|
||||
g.Player.Lock()
|
||||
g.Player.ActionQueue = append(g.Player.ActionQueue, &pb.Action{
|
||||
Type: pb.Action_CHAT,
|
||||
ChatMessage: message,
|
||||
PlayerId: g.Player.ID,
|
||||
})
|
||||
g.Player.Unlock()
|
||||
}
|
||||
|
||||
g.HandleInput()
|
||||
|
||||
if len(g.Player.TargetPath) > 0 {
|
||||
@ -141,6 +155,7 @@ func (g *Game) Render() {
|
||||
|
||||
rl.EndMode3D()
|
||||
rl.DrawFPS(10, 10)
|
||||
g.Chat.Draw(int32(rl.GetScreenWidth()), int32(rl.GetScreenHeight()))
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
@ -153,7 +168,7 @@ func (g *Game) HandleInput() {
|
||||
clickedTile, clicked := g.GetTileAtMouse()
|
||||
if clicked {
|
||||
path := FindPath(GetTile(g.Player.PosTile.X, g.Player.PosTile.Y), clickedTile)
|
||||
if path != nil && len(path) > 1 {
|
||||
if len(path) > 1 {
|
||||
g.Player.Lock()
|
||||
g.Player.TargetPath = path[1:]
|
||||
g.Player.ActionQueue = append(g.Player.ActionQueue, &pb.Action{
|
||||
|
||||
Reference in New Issue
Block a user