Ignore out of bounds
This commit is contained in:
parent
1360956c0a
commit
de826da3c1
@ -3,6 +3,7 @@ package gamemap
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WorldMap is the data structure used game world
|
// WorldMap is the data structure used game world
|
||||||
@ -14,7 +15,7 @@ type WorldMap struct {
|
|||||||
|
|
||||||
// GetTile method is used to grab a tile value with error checking
|
// GetTile method is used to grab a tile value with error checking
|
||||||
func (m WorldMap) GetTile(x int, y int) (int, error) {
|
func (m WorldMap) GetTile(x int, y int) (int, error) {
|
||||||
if x > m.max_x || y > m.max_y {
|
if x > m.max_x || y > m.max_y || x < 0 || y < 0 {
|
||||||
return -1, fmt.Errorf("Map out of bounds error: %d, %d", x, y)
|
return -1, fmt.Errorf("Map out of bounds error: %d, %d", x, y)
|
||||||
}
|
}
|
||||||
return m.data[x][y], nil
|
return m.data[x][y], nil
|
||||||
|
Reference in New Issue
Block a user