Begin setup of map generation
This commit is contained in:
parent
07dd70b25f
commit
56267fe8a7
11
game_map.py
11
game_map.py
@ -1,17 +1,16 @@
|
|||||||
import numpy as np # type: ignore
|
import numpy as np # type: ignore
|
||||||
from tcod.console import Console
|
from tcod.console import Console
|
||||||
|
|
||||||
import tile_types
|
import tile_types
|
||||||
|
|
||||||
|
|
||||||
class GameMap:
|
class GameMap:
|
||||||
def __init__(self, width: int, height: int):
|
def __init__(self, width: int, height: int):
|
||||||
self.width, self.height = width, height;
|
self.width, self.height = width, height
|
||||||
self.tiles = np.full((width, height), fill_value=tile_types.floor, order="F")
|
self.tiles = np.full((width, height), fill_value=tile_types.wall, order="F")
|
||||||
|
|
||||||
self.tiles[30:33, 22] = tile_types.wall
|
|
||||||
|
|
||||||
def in_bounds(self, x: int, y: int) -> bool:
|
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
|
return 0 <= x < self.width and 0 <= y < self.height
|
||||||
|
|
||||||
def render(self, console: Console):
|
def render(self, console: Console):
|
||||||
|
16
main.py
16
main.py
@ -3,8 +3,8 @@ import tcod
|
|||||||
|
|
||||||
from engine import Engine
|
from engine import Engine
|
||||||
from entity import Entity
|
from entity import Entity
|
||||||
from game_map import GameMap
|
|
||||||
from input_handlers import EventHandler
|
from input_handlers import EventHandler
|
||||||
|
from procgen import generate_dungeon
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
@ -23,20 +23,20 @@ def main() -> None:
|
|||||||
|
|
||||||
event_handler = EventHandler()
|
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))
|
npc = Entity(int(screen_width / 2 - 5), int(screen_height / 2), "@", (255, 255, 0))
|
||||||
entities = {npc, player}
|
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)
|
engine = Engine(entities, event_handler, game_map, player)
|
||||||
|
|
||||||
with tcod.context.new_terminal(
|
with tcod.context.new_terminal(
|
||||||
screen_width,
|
screen_width,
|
||||||
screen_height,
|
screen_height,
|
||||||
tileset=tileset,
|
tileset=tileset,
|
||||||
title="Yet Another Roguelike Tutorial",
|
title="Yet Another Roguelike Tutorial",
|
||||||
vsync=True,
|
vsync=True,
|
||||||
) as context:
|
) as context:
|
||||||
root_console = tcod.Console(screen_width, screen_height, order="F")
|
root_console = tcod.Console(screen_width, screen_height, order="F")
|
||||||
while True:
|
while True:
|
||||||
|
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
|
numpy>=1.18
|
@ -15,16 +15,17 @@ graphic_dt = np.dtype(
|
|||||||
tile_dt = np.dtype(
|
tile_dt = np.dtype(
|
||||||
[
|
[
|
||||||
("walkable", np.bool), # True if this tile can be walked over.
|
("walkable", np.bool), # True if this tile can be walked over.
|
||||||
("transparent", np.bool), # True if this tile doesn't block FOV.
|
("transparent", np.bool), # True if this tile doesn't block FOV.
|
||||||
("dark", graphic_dt), # Graphics for when this tile is not in FOV.
|
("dark", graphic_dt), # Graphics for when this tile is not in FOV.
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def new_tile(
|
def new_tile(
|
||||||
*, # Enforce the use of keywords, so that parameter order doesn't matter
|
*, # Enforce the use of keywords, so that parameter order doesn't matter
|
||||||
walkable: int,
|
walkable: int,
|
||||||
transparent: int,
|
transparent: int,
|
||||||
dark: Tuple[int, Tuple[int, int, int], Tuple[int, int, int]]
|
dark: Tuple[int, Tuple[int, int, int], Tuple[int, int, int]]
|
||||||
) -> np.ndarray:
|
) -> np.ndarray:
|
||||||
"""Helper function for defining individual tile types"""
|
"""Helper function for defining individual tile types"""
|
||||||
return np.array((walkable, transparent, dark), dtype=tile_dt)
|
return np.array((walkable, transparent, dark), dtype=tile_dt)
|
||||||
|
Loading…
Reference in New Issue
Block a user