| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package game
- import (
- "github.com/gorilla/websocket"
- )
- //玩家
- type Player struct {
- Conn *websocket.Conn
- IsValid bool
- //当前所在的房间
- Room *Room
- //用户信息(需要客户端上传)
- userInfo interface{}
- }
- func (player *Player) OnLoad() {
- player.IsValid = true
- }
- func (player *Player) OnDestroy() {
- player.IsValid = false
- //断开连接时,玩家就要离开房间
- if player.Room != nil {
- player.Room.Leave(player)
- }
- }
- //RPC接口-请求进入房间
- func (player *Player) RequestEnterRoom(userInfo interface{}) {
- player.userInfo = userInfo
- if player.Room == nil {
- MatchAndEnterRoom(player)
- }
- }
- //RPC接口-上传数据帧
- func (player *Player) UploadFrames(frames []interface{}) {
- if player.Room != nil {
- player.Room.CacheFrames(frames)
- }
- }
- //通知客户端-匹配完成
- func (player *Player) Notify_onMatchComplete(id int, playerInfos map[int]interface{}, uuid_ string, timestamp_ int64) {
- SendPackFunction(player.Conn, "onMatchComplete", id, playerInfos, uuid_, timestamp_)
- }
- //通知客户端-游戏开始
- func (player *Player) Notify_onGameStart() {
- SendPackFunction(player.Conn, "onGameStart")
- }
- //通知客户端-下发帧同步数据
- func (player *Player) Notify_onFrameSync(frames []interface{}) {
- SendPackFunction(player.Conn, "onFrameSync", frames)
- }
|