-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (47 loc) · 1.47 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
from rectangle_room import RectRoom
import random
import tcod
from entity import Entity
from entity_type import EntityType
from event_handler import EventHandler
from game import Game
from game_map import GameMap
from tile_type import TileType
def main() -> None:
"""
Entry point.
"""
# Load the font.
tileset = tcod.tileset.load_tilesheet("fonts/glifix-20x20.png", 16, 16, tcod.tileset.CHARMAP_CP437)
# Create the window.
context = tcod.context.new( # New window with pixel width and height
width = 1920 // 2,
height = 1080 // 2,
tileset = tileset,
title = "Roguelike",
vsync = True,
sdl_window_flags = tcod.context.SDL_WINDOW_RESIZABLE | tcod.context.SDL_WINDOW_MAXIMIZED,
)
# Temporary game stuff.
game = Game(Entity(EntityType.PLAYER, 0, 0))
game_map = GameMap(game, 512, 512, TileType.FLOOR)
# Initialize event handling.
event_handler = EventHandler(game)
# Run the game loop.
while True:
# New root console, sized to fit screen.
root_console = context.new_console(order="F")
# Render the game.
game_map.render(root_console)
# Display final console.
context.present(root_console, integer_scaling=True)
# Wait for, and handle, events.
for event in tcod.event.wait():
context.convert_event(event) # Sets tile coordinates for mouse events.
# If the event results in running a command, run it.
command = event_handler.dispatch(event)
if command:
command.execute()
if __name__ == "__main__":
main()