Skip to content

Commit

Permalink
Fix for spawning bug using the wrong coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
thorfour committed Dec 1, 2017
1 parent f348f94 commit 3e18605
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/game/state/maps/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions pkg/game/state/maps/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 3e18605

Please sign in to comment.