sdl rendering progress?
This commit is contained in:
parent
467c6606da
commit
af941dc848
5 changed files with 22 additions and 13 deletions
3
g.py
3
g.py
|
|
@ -40,5 +40,6 @@ sdl_renderer: tcod.sdl.render.Renderer
|
||||||
atlas: tcod.render.SDLTilesetAtlas
|
atlas: tcod.render.SDLTilesetAtlas
|
||||||
"""The tileset atlas"""
|
"""The tileset atlas"""
|
||||||
|
|
||||||
console_render: tcod.render.SDLConsoleRender
|
console_render1: tcod.render.SDLConsoleRender
|
||||||
|
console_render2: tcod.render.SDLConsoleRender
|
||||||
"""The console renderer"""
|
"""The console renderer"""
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ def main_draw() -> None:
|
||||||
if not g.screens:
|
if not g.screens:
|
||||||
return
|
return
|
||||||
g.background.clear()
|
g.background.clear()
|
||||||
|
g.foreground.clear()
|
||||||
g.foreground.rgba["bg"][:] = 0
|
g.foreground.rgba["bg"][:] = 0
|
||||||
g.foreground.rgba["fg"][:] = 0
|
g.foreground.rgba["fg"][:] = 0
|
||||||
g.screens[-1].on_draw(g.background)
|
g.screens[-1].on_draw(g.background)
|
||||||
|
|
@ -60,9 +61,10 @@ def main_draw() -> None:
|
||||||
|
|
||||||
# g.sdl_renderer.copy(g.console_render.render(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)
|
# g.foreground.blit(g.background, fg_alpha=1.0, bg_alpha=0.0)
|
||||||
bg_tex = g.console_render.render(g.background)
|
bg_tex = g.console_render1.render(g.background)
|
||||||
fg_tex = g.console_render.render(g.foreground)
|
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):
|
with g.sdl_renderer.set_render_target(bg_tex):
|
||||||
g.sdl_renderer.copy(fg_tex)
|
g.sdl_renderer.copy(fg_tex)
|
||||||
|
|
||||||
|
|
@ -119,7 +121,7 @@ def draw_previous_screens(screen: Screen, console: tcod.console.Console, dim: bo
|
||||||
return
|
return
|
||||||
prev_screen.on_draw(console)
|
prev_screen.on_draw(console)
|
||||||
if dim and screen is g.screens[-1]:
|
if dim and screen is g.screens[-1]:
|
||||||
g.foreground.rgb["fg"] //= 4
|
g.foreground.rgba["fg"] //= 4
|
||||||
g.foreground.rgb["bg"] //= 4
|
g.foreground.rgba["bg"] //= 4
|
||||||
g.background.rgb["fg"] //= 4
|
g.background.rgba["fg"] //= 4
|
||||||
g.background.rgb["bg"] //= 4
|
g.background.rgba["bg"] //= 4
|
||||||
|
|
|
||||||
|
|
@ -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)
|
map_pos = world_pos_to_map_pos(pos)
|
||||||
if g.world[None].components[Map].fov[map_pos.y, map_pos.x]:
|
if g.world[None].components[Map].fov[map_pos.y, map_pos.x]:
|
||||||
graphic = entity.components[Graphic]
|
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()
|
@attrs.define()
|
||||||
|
|
@ -86,6 +86,7 @@ class MainScreen(Screen):
|
||||||
|
|
||||||
def on_draw(self, console: tcod.console.Console) -> None:
|
def on_draw(self, console: tcod.console.Console) -> None:
|
||||||
"""Draw the standard screen."""
|
"""Draw the standard screen."""
|
||||||
|
console = g.background
|
||||||
centers = [a.components[Position] for a in g.world.Q.all_of(tags=[IsPlayer])]
|
centers = [a.components[Position] for a in g.world.Q.all_of(tags=[IsPlayer])]
|
||||||
camera_pos = sum(centers, start=Position(0,0))
|
camera_pos = sum(centers, start=Position(0,0))
|
||||||
camera_pos = camera_pos.mod(len(centers))
|
camera_pos = camera_pos.mod(len(centers))
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,11 @@ from typing import Protocol
|
||||||
|
|
||||||
import attrs
|
import attrs
|
||||||
import tcod.console
|
import tcod.console
|
||||||
|
import tcod.constants
|
||||||
import tcod.event
|
import tcod.event
|
||||||
from tcod.event import KeySym
|
from tcod.event import KeySym
|
||||||
|
|
||||||
|
import g
|
||||||
from game.constants import DIRECTION_KEYS
|
from game.constants import DIRECTION_KEYS
|
||||||
from game.screens import Pop, Screen, ScreenResult, draw_previous_screens
|
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:
|
def on_draw(self, console: tcod.console.Console) -> None:
|
||||||
"""Render the menu."""
|
"""Render the menu."""
|
||||||
draw_previous_screens(self, console)
|
draw_previous_screens(self, g.foreground)
|
||||||
for i, item in enumerate(self.items):
|
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)
|
||||||
|
|
|
||||||
5
main.py
5
main.py
|
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import tcod.console
|
import tcod.console
|
||||||
import tcod.context
|
import tcod.context
|
||||||
|
import tcod.constants
|
||||||
import tcod.render
|
import tcod.render
|
||||||
import tcod.tileset
|
import tcod.tileset
|
||||||
import tcod.sdl.video
|
import tcod.sdl.video
|
||||||
|
|
@ -23,6 +24,7 @@ def main() -> None:
|
||||||
g.screens = [MainMenu()]
|
g.screens = [MainMenu()]
|
||||||
g.background = tcod.console.Console(80, 35)
|
g.background = tcod.console.Console(80, 35)
|
||||||
g.foreground = tcod.console.Console(80, 35)
|
g.foreground = tcod.console.Console(80, 35)
|
||||||
|
|
||||||
win = tcod.sdl.video.new_window(
|
win = tcod.sdl.video.new_window(
|
||||||
g.background.width * g.tileset.tile_width,
|
g.background.width * g.tileset.tile_width,
|
||||||
g.background.height * g.tileset.tile_height,
|
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.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()
|
game.screens.main_loop()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue