Begin setup of map generation
This commit is contained in:
parent
07dd70b25f
commit
56267fe8a7
@ -3,15 +3,14 @@ from tcod.console import Console
|
||||
|
||||
import tile_types
|
||||
|
||||
|
||||
class GameMap:
|
||||
def __init__(self, width: int, height: int):
|
||||
self.width, self.height = width, height;
|
||||
self.tiles = np.full((width, height), fill_value=tile_types.floor, order="F")
|
||||
|
||||
self.tiles[30:33, 22] = tile_types.wall
|
||||
self.width, self.height = width, height
|
||||
self.tiles = np.full((width, height), fill_value=tile_types.wall, order="F")
|
||||
|
||||
def in_bounds(self, x: int, y: int) -> bool:
|
||||
"""Return True if x and y are inside of the bounds of the map."""
|
||||
"""Return True if x and y are inside the bounds of the map."""
|
||||
return 0 <= x < self.width and 0 <= y < self.height
|
||||
|
||||
def render(self, console: Console):
|
||||
|
6
main.py
6
main.py
@ -3,8 +3,8 @@ import tcod
|
||||
|
||||
from engine import Engine
|
||||
from entity import Entity
|
||||
from game_map import GameMap
|
||||
from input_handlers import EventHandler
|
||||
from procgen import generate_dungeon
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@ -23,11 +23,11 @@ def main() -> None:
|
||||
|
||||
event_handler = EventHandler()
|
||||
|
||||
player = Entity(int(screen_width / 2), int(screen_height/ 2), "@", (255, 255, 255))
|
||||
player = Entity(int(screen_width / 2), int(screen_height / 2), "@", (255, 255, 255))
|
||||
npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@", (255, 255, 0))
|
||||
entities = {npc, player}
|
||||
|
||||
game_map = GameMap(map_width, map_height)
|
||||
game_map = generate_dungeon(map_width, map_height)
|
||||
|
||||
engine = Engine(entities, event_handler, game_map, player)
|
||||
|
||||
|
36
procgen.py
Normal file
36
procgen.py
Normal file
@ -0,0 +1,36 @@
|
||||
from typing import Tuple
|
||||
|
||||
from game_map import GameMap
|
||||
import tile_types
|
||||
|
||||
|
||||
class RectangularRoom:
|
||||
def __init__(self, x: int, y: int, width: int, height: int):
|
||||
self.x1 = x
|
||||
self.y1 = y
|
||||
self.x2 = x + width
|
||||
self.y2 = y + height
|
||||
|
||||
@property
|
||||
def center(self) -> Tuple[int, int]:
|
||||
center_x = int((self.x1 + self.x2) / 2)
|
||||
center_y = int((self.y1 + self.y1) / 2)
|
||||
|
||||
return center_x, center_y
|
||||
|
||||
@property
|
||||
def inner(self) -> Tuple[slice, slice]:
|
||||
"""Return the inner area of this room as a 2D array index."""
|
||||
return slice(self.x1 + 1, self.x2), slice(self.y1 + 1, self.y2)
|
||||
|
||||
|
||||
def generate_dungeon(map_width, map_height) -> GameMap:
|
||||
dungeon = GameMap(map_width, map_height)
|
||||
|
||||
room_1 = RectangularRoom(x=20, y=15, width=10, height=15)
|
||||
room_2 = RectangularRoom(x=35, y=15, width=10, height=15)
|
||||
|
||||
dungeon.tiles[room_1.inner] = tile_types.floor
|
||||
dungeon.tiles[room_2.inner] = tile_types.floor
|
||||
|
||||
return dungeon
|
@ -1,2 +1,2 @@
|
||||
tcod>=11.13
|
||||
tcod>=11.14
|
||||
numpy>=1.18
|
@ -20,6 +20,7 @@ tile_dt = np.dtype(
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def new_tile(
|
||||
*, # Enforce the use of keywords, so that parameter order doesn't matter
|
||||
walkable: int,
|
||||
|
Loading…
Reference in New Issue
Block a user