多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 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) } ```