//moveTowardsHero determines if a character can move towards the player. //Function returns 2 values. //True if the player is next to the character and his coordinates. func (npc *NPC) moveTowardsHero(labyrinth *Labyrinth.Labyrinth) (bool, *Point.Point) { var upTile string if labyrinth.IsInBondaries(npc.Location.X-1, npc.Location.Y) { upTile = labyrinth.Labyrinth[npc.Location.X-1][npc.Location.Y] } if upTile == Labyrinth.CharSymbol { return true, &Point.Point{npc.Location.X - 1, npc.Location.Y, nil} } var downTile string if labyrinth.IsInBondaries(npc.Location.X+1, npc.Location.Y) { downTile = labyrinth.Labyrinth[npc.Location.X+1][npc.Location.Y] } if downTile == Labyrinth.CharSymbol { return true, &Point.Point{npc.Location.X + 1, npc.Location.Y, nil} } var leftTile string if labyrinth.IsInBondaries(npc.Location.X, npc.Location.Y-1) { leftTile = labyrinth.Labyrinth[npc.Location.X][npc.Location.Y-1] } if leftTile == Labyrinth.CharSymbol { return true, &Point.Point{npc.Location.X, npc.Location.Y - 1, nil} } var rightTile string if labyrinth.IsInBondaries(npc.Location.X, npc.Location.Y+1) { rightTile = labyrinth.Labyrinth[npc.Location.X][npc.Location.Y+1] } if rightTile == Labyrinth.CharSymbol { return true, &Point.Point{npc.Location.X, npc.Location.Y + 1, nil} } return false, &Point.Point{} }
//MemorizeLabyrinth determines which tiles a character can see and add them to a map. //Takes a labyrinth as an argument. func (hero *Hero) MemorizeLabyrinth(labyrinth *Labyrinth.Labyrinth, center *Point.Point) { var minX int = center.X - hero.Base.VisionRadious var maxX int = center.X + hero.Base.VisionRadious var minY int = center.Y - hero.Base.VisionRadious var maxY int = center.Y + hero.Base.VisionRadious var y int for currentY := minY; currentY <= maxY; currentY++ { for xAscend := center.X; xAscend <= maxX; xAscend++ { y = Point.LineEquationRegardsToX(xAscend, center.X, center.Y, maxX, currentY) if labyrinth.IsInBondaries(xAscend, y) && labyrinth.Labyrinth[xAscend][y] != Labyrinth.Wall { hero.Memory[Point.Point{xAscend, y, nil}] = hero.MemoryDuration } else { hero.Memory[Point.Point{xAscend, y, nil}] = hero.MemoryDuration break } } for xDescend := center.X; xDescend >= minX; xDescend-- { y = Point.LineEquationRegardsToX(xDescend, center.X, center.Y, minX, currentY) if labyrinth.IsInBondaries(xDescend, y) && labyrinth.Labyrinth[xDescend][y] != Labyrinth.Wall { hero.Memory[Point.Point{xDescend, y, nil}] = hero.MemoryDuration } else { hero.Memory[Point.Point{xDescend, y, nil}] = hero.MemoryDuration break } } } var x int for currentX := minX; currentX <= maxX; currentX++ { for yDescend := center.Y; yDescend >= minY; yDescend-- { x = Point.LineEquationRegardsToY(yDescend, center.X, center.Y, currentX, minY) if labyrinth.IsInBondaries(x, yDescend) && labyrinth.Labyrinth[x][yDescend] != Labyrinth.Wall { hero.Memory[Point.Point{x, yDescend, nil}] = hero.MemoryDuration } else { hero.Memory[Point.Point{x, yDescend, nil}] = hero.MemoryDuration break } } for yAscend := center.Y; yAscend <= maxY; yAscend++ { x = Point.LineEquationRegardsToY(yAscend, center.X, center.Y, currentX, maxY) if labyrinth.IsInBondaries(x, yAscend) && labyrinth.Labyrinth[x][yAscend] != Labyrinth.Wall { hero.Memory[Point.Point{x, yAscend, nil}] = hero.MemoryDuration } else { hero.Memory[Point.Point{x, yAscend, nil}] = hero.MemoryDuration break } } } }