diff --git a/g.py b/g.py index c90b6b0..14e3d78 100644 --- a/g.py +++ b/g.py @@ -40,5 +40,6 @@ sdl_renderer: tcod.sdl.render.Renderer atlas: tcod.render.SDLTilesetAtlas """The tileset atlas""" -console_render: tcod.render.SDLConsoleRender +console_render1: tcod.render.SDLConsoleRender +console_render2: tcod.render.SDLConsoleRender """The console renderer""" diff --git a/game/screens/__init__.py b/game/screens/__init__.py index 77e78b4..4a30da0 100644 --- a/game/screens/__init__.py +++ b/game/screens/__init__.py @@ -53,16 +53,18 @@ def main_draw() -> None: if not g.screens: return g.background.clear() + g.foreground.clear() g.foreground.rgba["bg"][:] = 0 g.foreground.rgba["fg"][:] = 0 g.screens[-1].on_draw(g.background) # g.context.present(g.background) # g.sdl_renderer.copy(g.console_render.render(g.background)) - # g.foreground.blit(g.background, fg_alpha=1.0, bg_alpha=0.0) - bg_tex = g.console_render.render(g.background) - fg_tex = g.console_render.render(g.foreground) - +# g.foreground.blit(g.background, fg_alpha=1.0, bg_alpha=0.0) + bg_tex = g.console_render1.render(g.background) + bg_tex.blend_mode = 1 + fg_tex = g.console_render2.render(g.foreground) + fg_tex.blend_mode = 1 with g.sdl_renderer.set_render_target(bg_tex): g.sdl_renderer.copy(fg_tex) @@ -119,7 +121,7 @@ def draw_previous_screens(screen: Screen, console: tcod.console.Console, dim: bo return prev_screen.on_draw(console) if dim and screen is g.screens[-1]: - g.foreground.rgb["fg"] //= 4 - g.foreground.rgb["bg"] //= 4 - g.background.rgb["fg"] //= 4 - g.background.rgb["bg"] //= 4 + g.foreground.rgba["fg"] //= 4 + g.foreground.rgba["bg"] //= 4 + g.background.rgba["fg"] //= 4 + g.background.rgba["bg"] //= 4 diff --git a/game/screens/game_screens.py b/game/screens/game_screens.py index ca5f266..a729857 100644 --- a/game/screens/game_screens.py +++ b/game/screens/game_screens.py @@ -62,7 +62,7 @@ def _draw_entity(entity: tcod.ecs.Entity, camera_pos, camera_radius_x, camera_ra map_pos = world_pos_to_map_pos(pos) if g.world[None].components[Map].fov[map_pos.y, map_pos.x]: graphic = entity.components[Graphic] - g.foreground.rgba[["ch", "fg", "bg"]][screen_pos.y + camera_radius_y, screen_pos.x + camera_radius_x] = graphic.ch, graphic.fg, graphic.bg + g.foreground.rgba[["ch", "fg"]][screen_pos.y + camera_radius_y, screen_pos.x + camera_radius_x] = graphic.ch, graphic.fg @attrs.define() @@ -86,6 +86,7 @@ class MainScreen(Screen): def on_draw(self, console: tcod.console.Console) -> None: """Draw the standard screen.""" + console = g.background centers = [a.components[Position] for a in g.world.Q.all_of(tags=[IsPlayer])] camera_pos = sum(centers, start=Position(0,0)) camera_pos = camera_pos.mod(len(centers)) diff --git a/game/screens/menus.py b/game/screens/menus.py index 9df7066..2e707e1 100644 --- a/game/screens/menus.py +++ b/game/screens/menus.py @@ -7,9 +7,11 @@ from typing import Protocol import attrs import tcod.console +import tcod.constants import tcod.event from tcod.event import KeySym +import g from game.constants import DIRECTION_KEYS from game.screens import Pop, Screen, ScreenResult, draw_previous_screens @@ -93,6 +95,6 @@ class ListMenu(Screen): def on_draw(self, console: tcod.console.Console) -> None: """Render the menu.""" - draw_previous_screens(self, console) + draw_previous_screens(self, g.foreground) for i, item in enumerate(self.items): - item.on_draw(console, x=self.x, y=self.y + i, highlight=i == self.selected) + item.on_draw(g.foreground, x=self.x, y=self.y + i, highlight=i == self.selected) diff --git a/main.py b/main.py index 0f2653e..dc67cb6 100755 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ from __future__ import annotations import tcod.console import tcod.context +import tcod.constants import tcod.render import tcod.tileset import tcod.sdl.video @@ -23,6 +24,7 @@ def main() -> None: g.screens = [MainMenu()] g.background = tcod.console.Console(80, 35) g.foreground = tcod.console.Console(80, 35) + win = tcod.sdl.video.new_window( g.background.width * g.tileset.tile_width, g.background.height * g.tileset.tile_height, @@ -36,7 +38,8 @@ def main() -> None: g.atlas = tcod.render.SDLTilesetAtlas(g.sdl_renderer, g.tileset) - g.console_render = tcod.render.SDLConsoleRender(atlas=g.atlas) + g.console_render1 = tcod.render.SDLConsoleRender(atlas=g.atlas) + g.console_render2 = tcod.render.SDLConsoleRender(atlas=g.atlas) game.screens.main_loop()