Rename the Map's Point question methods to use "point" instead of "tile"

This commit is contained in:
Eryn Wells 2023-03-08 08:57:20 -08:00
parent 7ee790e25e
commit eda44a8792
4 changed files with 12 additions and 13 deletions

View file

@ -71,8 +71,8 @@ class BumpAction(MoveAction):
def perform(self, engine: 'Engine') -> ActionResult: def perform(self, engine: 'Engine') -> ActionResult:
new_position = self.actor.position + self.direction new_position = self.actor.position + self.direction
position_is_in_bounds = engine.map.tile_is_in_bounds(new_position) position_is_in_bounds = engine.map.point_is_in_bounds(new_position)
position_is_walkable = engine.map.tile_is_walkable(new_position) position_is_walkable = engine.map.point_is_walkable(new_position)
for ent in engine.entities: for ent in engine.entities:
if new_position != ent.position or not ent.blocks_movement: if new_position != ent.position or not ent.blocks_movement:

View file

@ -78,10 +78,10 @@ class HostileEnemy(AI):
new_position = self.entity.position + direction new_position = self.entity.position + direction
overlaps_existing_entity = any(new_position == ent.position for ent in engine.entities) overlaps_existing_entity = any(new_position == ent.position for ent in engine.entities)
try: try:
tile_is_walkable = engine.map.tile_is_walkable(new_position) point_is_walkable = engine.map.point_is_walkable(new_position)
except ValueError: except ValueError:
tile_is_walkable = False point_is_walkable = False
if not overlaps_existing_entity and tile_is_walkable: if not overlaps_existing_entity and point_is_walkable:
if engine.map.visible[tuple(self.entity.position)]: if engine.map.visible[tuple(self.entity.position)]:
log.AI.info('Hero is NOT visible to %s, bumping %s randomly', self.entity, direction) log.AI.info('Hero is NOT visible to %s, bumping %s randomly', self.entity, direction)
action = BumpAction(self.entity, direction) action = BumpAction(self.entity, direction)

View file

@ -17,13 +17,13 @@ from .events import EngineEventHandler, GameOverEventHandler
from .map import Map from .map import Map
from .map.generator import RoomsAndCorridorsGenerator from .map.generator import RoomsAndCorridorsGenerator
from .map.generator.cellular_atomata import CellularAtomataMapGenerator from .map.generator.cellular_atomata import CellularAtomataMapGenerator
from .map.generator.corridor import ElbowCorridorGenerator
from .map.generator.room import ( from .map.generator.room import (
BSPRectMethod, BSPRectMethod,
CellularAtomatonRoomMethod, CellularAtomatonRoomMethod,
OrRoomMethod, OrRoomMethod,
RoomGenerator, RoomGenerator,
RectangularRoomMethod) RectangularRoomMethod)
from .map.generator.corridor import ElbowCorridorGenerator
from .messages import MessageLog from .messages import MessageLog
from .object import Actor, Entity, Hero, Monster from .object import Actor, Entity, Hero, Monster

View file

@ -9,7 +9,6 @@ import random
from typing import Iterable from typing import Iterable
import numpy as np import numpy as np
import numpy.typing as npt
import tcod import tcod
from ..configuration import Configuration from ..configuration import Configuration
@ -82,25 +81,25 @@ class Map:
self.tiles.shape) if self.tiles[x, y]['walkable']] self.tiles.shape) if self.tiles[x, y]['walkable']]
return random.choice(self.__walkable_points) return random.choice(self.__walkable_points)
def tile_is_in_bounds(self, point: Point) -> bool: def point_is_in_bounds(self, point: Point) -> bool:
'''Return True if the given point is inside the bounds of the map''' '''Return True if the given point is inside the bounds of the map'''
return 0 <= point.x < self.size.width and 0 <= point.y < self.size.height return 0 <= point.x < self.size.width and 0 <= point.y < self.size.height
def tile_is_walkable(self, point: Point) -> bool: def point_is_walkable(self, point: Point) -> bool:
'''Return True if the tile at the given point is walkable''' '''Return True if the tile at the given point is walkable'''
if not self.tile_is_in_bounds(point): if not self.point_is_in_bounds(point):
raise ValueError(f'Point {point!s} is not in bounds') raise ValueError(f'Point {point!s} is not in bounds')
return self.tiles[point.numpy_index]['walkable'] return self.tiles[point.numpy_index]['walkable']
def point_is_visible(self, point: Point) -> bool: def point_is_visible(self, point: Point) -> bool:
'''Return True if the point is visible to the player''' '''Return True if the point is visible to the player'''
if not self.tile_is_in_bounds(point): if not self.point_is_in_bounds(point):
raise ValueError(f'Point {point!s} is not in bounds') raise ValueError(f'Point {point!s} is not in bounds')
return self.visible[point.numpy_index] return self.visible[point.numpy_index]
def point_is_explored(self, point: Point) -> bool: def point_is_explored(self, point: Point) -> bool:
'''Return True if the tile at the given point has been explored by the player''' '''Return True if the tile at the given point has been explored by the player'''
if not self.tile_is_in_bounds(point): if not self.point_is_in_bounds(point):
raise ValueError(f'Point {point!s} is not in bounds') raise ValueError(f'Point {point!s} is not in bounds')
return self.explored[point.numpy_index] return self.explored[point.numpy_index]
@ -109,7 +108,7 @@ class Map:
self.highlighted.fill(False) self.highlighted.fill(False)
for pt in points: for pt in points:
self.highlighted[pt.x, pt.y] = True self.highlighted[pt.numpy_index] = True
def find_walkable_path_from_point_to_point(self, point_a: Point, point_b: Point) -> Iterable[Point]: def find_walkable_path_from_point_to_point(self, point_a: Point, point_b: Point) -> Iterable[Point]:
''' '''