- commit
- 36014cd795e3214bdb5d376333d10599b14f3b7e
- parent
- 4e1ab79cb8007ba3129312043018b53e57e13c94
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-09-27 06:07
collision between monsters and players
Diffstat
| M | game.go | 28 | ++++++++++++++++++++++++++-- |
1 files changed, 26 insertions, 2 deletions
diff --git a/game.go b/game.go
@@ -229,6 +229,24 @@ func (game *Game) MaybeNextLevel() {
229 229 game.broadcast(msgs)
230 230 }
231 231
-1 232 func (game *Game) getMonsterAt(pos Point) *Monster {
-1 233 for monster := range game.Monsters {
-1 234 if monster.Pos == pos {
-1 235 return monster
-1 236 }
-1 237 }
-1 238 return nil
-1 239 }
-1 240
-1 241 func (game *Game) getPlayerAt(pos Point) *Player {
-1 242 for player := range game.Players {
-1 243 if player.Pos == pos {
-1 244 return player
-1 245 }
-1 246 }
-1 247 return nil
-1 248 }
-1 249
232 250 func (game *Game) run() {
233 251 for {
234 252 select {
@@ -313,7 +331,10 @@ func (game *Game) run() {
313 331 continue
314 332 }
315 333 pos := player.Pos.Move(dir)
316 -1 if game.IsFree(pos) {
-1 334 monster := game.getMonsterAt(pos)
-1 335 if monster != nil {
-1 336 // TODO
-1 337 } else if game.IsFree(pos) {
317 338 player.Pos = pos
318 339 game.broadcast([]Message{
319 340 Message{
@@ -343,7 +364,10 @@ func (game *Game) run() {
343 364 } else if msg["dir"] == "left" {
344 365 pos.X -= 1
345 366 }
346 -1 if game.IsFree(pos) {
-1 367 player := game.getPlayerAt(pos)
-1 368 if player != nil {
-1 369 // TODO
-1 370 } else if game.getMonsterAt(pos) == nil && game.IsFree(pos) {
347 371 monster.Pos = pos
348 372 game.broadcast([]Message{
349 373 Message{