From 1bd0ab372d50337775d7acb856bedfe06172a51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20N=C3=B6llemeyer?= Date: Sat, 17 Aug 2024 12:28:39 +0200 Subject: [PATCH] enhanced FOV --- g.py | 2 -- game/screens/game_screens.py | 17 +++++++++++------ game/world_tools.py | 14 ++++++++------ main.py | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/g.py b/g.py index e30e095..64d1041 100644 --- a/g.py +++ b/g.py @@ -15,8 +15,6 @@ context: tcod.context.Context world: tcod.ecs.Registry """The active ECS registry and current session.""" -world_center: tuple[int,int] = Position(50, 50) - screens: list[Screen] = [] """A stack of states with the last item being the active state.""" diff --git a/game/screens/game_screens.py b/game/screens/game_screens.py index 067a833..0075be1 100644 --- a/game/screens/game_screens.py +++ b/game/screens/game_screens.py @@ -64,18 +64,23 @@ class MainScreen(Screen): def draw(e_pos, e_graph): screen_pos = e_pos - camera_pos - mp = world_pos_to_map_pos(e_pos) + map_pos = world_pos_to_map_pos(e_pos) if (-w <= screen_pos.x < w\ - and -h <= screen_pos.y < h)\ - and map.fov[mp.y][mp.x]: - graphic = e_graph + and -h <= screen_pos.y < h): + if map.fov[map_pos.y][map_pos.x]: + graphic = e_graph + else: + graphic = Graphic(0x2591, (50, 50, 50)) console.rgb[["ch", "fg"]][screen_pos.y + h, screen_pos.x + w] = graphic.ch, graphic.fg # Draw walls for (y, row) in enumerate(map.walkable): for (x, val) in enumerate(row): - if not val: - draw(map_pos_to_world_pos(Position(x,y)), Graphic(WALL_CHAR)) + pos = map_pos_to_world_pos(Position(x,y)) + if val: + draw(pos, Graphic(0)) # open air + else: + draw(pos, Graphic(WALL_CHAR)) # draw all entities that are not actors for entity in g.world.Q.all_of(components=[Position, Graphic]).none_of(tags=[IsActor]): draw(entity.components[Position], entity.components[Graphic]) diff --git a/game/world_tools.py b/game/world_tools.py index e0ede47..74a6783 100644 --- a/game/world_tools.py +++ b/game/world_tools.py @@ -1,25 +1,27 @@ """Functions for working with worlds.""" from __future__ import annotations - from random import Random - -import g +from typing import Final from tcod.ecs import Registry, Entity from tcod.map import Map +import g + from game.components import Gold, Graphic, Position from game.tags import IsActor, IsItem, IsPlayer, IsDoor +world_center: Final = Position(50, 50) + def world_pos_to_map_pos(pos): - return pos+g.world_center + return pos+world_center def map_pos_to_world_pos(pos): - return pos-g.world_center + return pos-world_center def add_wall(world, pos, remove=False): - r_pos = g.world_center + pos + r_pos = world_pos_to_map_pos(pos) map = world[None].components[Map] map.walkable[r_pos.y][r_pos.x] = remove map.transparent[r_pos.y][r_pos.x] = remove diff --git a/main.py b/main.py index 226a327..cfb479e 100755 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ def main() -> None: tileset = tcod.tileset.load_tilesheet( "data/Alloy_curses_12x12.png", columns=16, rows=16, charmap=tcod.tileset.CHARMAP_CP437 ) - tcod.tileset.procedural_block_elements(tileset=tileset) + #tcod.tileset.procedural_block_elements(tileset=tileset) g.screens = [MainMenu()] g.console = tcod.console.Console(80, 50)