Ignore out of bounds

This commit is contained in:
Layla 2020-08-21 00:48:47 -04:00
parent 1360956c0a
commit de826da3c1
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31

View File

@ -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