ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 3.5 AOI格子添加删除操作 > mmo\_game/core/aoi.go ```go //通过GID获取当前格子的全部playerID func (m *AOIManager) GetPidsByGid(gID int) (playerIDs []int) { playerIDs = m.grids[gID].GetPlyerIDs() return } //移除一个格子中的PlayerID func (m *AOIManager) RemovePidFromGrid(pID, gID int) { m.grids[gID].Remove(pID) } //添加一个PlayerID到一个格子中 func (m *AOIManager) AddPidToGrid(pID, gID int) { m.grids[gID].Add(pID) } //通过横纵坐标添加一个Player到一个格子中 func (m *AOIManager) AddToGridByPos(pID int, x, y float32) { gID := m.GetGidByPos(x, y) grid := m.grids[gID] grid.Add(pID) } //通过横纵坐标把一个Player从对应的格子中删除 func (m *AOIManager) RemoveFromGridByPos(pID int, x, y float32) { gID := m.GetGidByPos(x, y) grid := m.grids[gID] grid.Remove(pID) } ```