From 3e18605b15c2ca9e73e485545fe74410823a3eeb Mon Sep 17 00:00:00 2001 From: thor Date: Thu, 30 Nov 2017 20:40:42 -0800 Subject: [PATCH] Fix for spawning bug using the wrong coordinates --- pkg/game/state/maps/generate.go | 5 +++-- pkg/game/state/maps/maps.go | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/game/state/maps/generate.go b/pkg/game/state/maps/generate.go index ad10afc..624615e 100644 --- a/pkg/game/state/maps/generate.go +++ b/pkg/game/state/maps/generate.go @@ -183,7 +183,7 @@ func randMapCoord() Coordinate { } // placeObject places an object in a maze at arandom open location -func placeObject(c Coordinate, o io.Runeable, lvl [][]io.Runeable) Coordinate { +func placeObject(c Coordinate, o io.Runeable, lvl [][]io.Runeable) (Coordinate, io.Runeable) { glog.V(6).Infof("Coord: (%v,%v) = %s", c.X, c.Y, string(o.Rune())) @@ -218,9 +218,10 @@ func placeObject(c Coordinate, o io.Runeable, lvl [][]io.Runeable) Coordinate { } // Add the object + d := lvl[c.Y][c.X] lvl[c.Y][c.X] = o - return c + return c, d } // placeObjects places the required objects for a level diff --git a/pkg/game/state/maps/maps.go b/pkg/game/state/maps/maps.go index 5bbd3e2..32a77fc 100644 --- a/pkg/game/state/maps/maps.go +++ b/pkg/game/state/maps/maps.go @@ -46,12 +46,11 @@ func (m *Maps) RemoveCharacter(c *character.Character) { // SpawnCharacter places the character on the home level func (m *Maps) SpawnCharacter(c *character.Character) { - // Save the displaced element - l := randMapCoord() - m.displaced = m.active[l.Y][l.X] - // Place the character on the map - placeObject(l, c, m.active) + l, d := placeObject(randMapCoord(), c, m.active) + + // Save the displaced element + m.displaced = d // Set the character to the location c.Teleport(int(l.X), int(l.Y))