WIP sdl renderer
This commit is contained in:
parent
68aa90cac8
commit
ef3f64bfa2
3 changed files with 22 additions and 11 deletions
1
g.py
1
g.py
|
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||
import tcod.console
|
||||
import tcod.context
|
||||
import tcod.ecs
|
||||
import tcod.sdl.video
|
||||
import tcod.tileset
|
||||
import tcod.sdl.render
|
||||
import tcod.render
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ from __future__ import annotations
|
|||
from typing import Protocol, TypeAlias
|
||||
|
||||
import attrs
|
||||
import tcod.console
|
||||
from tcod.console import Console
|
||||
from tcod.event import Event, Quit
|
||||
from tcod.event import wait as wait_for_event
|
||||
import tcod.event
|
||||
|
||||
import g
|
||||
|
|
@ -16,10 +18,10 @@ class Screen(Protocol):
|
|||
|
||||
__slots__ = ()
|
||||
|
||||
def on_event(self, event: tcod.event.Event) -> ScreenResult:
|
||||
def on_event(self, event: Event) -> ScreenResult:
|
||||
"""Called on events."""
|
||||
|
||||
def on_draw(self, console: tcod.console.Console) -> None:
|
||||
def on_draw(self, console: Console) -> None:
|
||||
"""Called when the screen is being drawn."""
|
||||
|
||||
|
||||
|
|
@ -84,9 +86,10 @@ def main_loop() -> None:
|
|||
"""Run the active screen forever."""
|
||||
while g.screens:
|
||||
main_draw()
|
||||
for event in tcod.event.wait():
|
||||
if event.type == 'WindowClose':
|
||||
raise SystemExit()
|
||||
for event in wait_for_event():
|
||||
match event:
|
||||
case Quit():
|
||||
raise SystemExit()
|
||||
tile_event = g.context.convert_event(event)
|
||||
if g.screens:
|
||||
_apply_screen_result(g.screens[-1].on_event(tile_event))
|
||||
|
|
|
|||
17
main.py
17
main.py
|
|
@ -5,10 +5,13 @@ from __future__ import annotations
|
|||
|
||||
import tcod.console
|
||||
import tcod.context
|
||||
import tcod.render
|
||||
import tcod.tileset
|
||||
import game.tilesetmanager
|
||||
import g
|
||||
import tcod.sdl.video
|
||||
import tcod.sdl.render
|
||||
|
||||
import g
|
||||
import game.tilesetmanager
|
||||
import game.screens
|
||||
from game.screens.menu_screens import MainMenu
|
||||
|
||||
|
|
@ -20,17 +23,21 @@ def main() -> None:
|
|||
g.screens = [MainMenu()]
|
||||
g.background = tcod.console.Console(80, 35)
|
||||
g.foreground = tcod.console.Console(80, 35)
|
||||
g.sdl_window = tcod.sdl.video.new_window(
|
||||
win = tcod.sdl.video.new_window(
|
||||
g.background.width * g.tileset.tile_width,
|
||||
g.background.height * g.tileset.tile_height,
|
||||
flags=tcod.lib.SDL_WINDOW_RESIZABLE,
|
||||
)
|
||||
|
||||
g.sdl_window = win
|
||||
|
||||
|
||||
g.sdl_renderer = tcod.sdl.render.new_renderer(g.sdl_window, target_textures=True)
|
||||
|
||||
g.atlas = tcod.render.SDLTilesetAtlas(g.sdl_renderer, g.tileset)
|
||||
|
||||
|
||||
g.console_render = tcod.render.SDLConsoleRender(atlas=g.atlas)
|
||||
|
||||
|
||||
with tcod.context.new(console=g.background, tileset=g.tileset) as g.context:
|
||||
game.screens.main_loop()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue