forked from libtcod/python-tcod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventget.py
More file actions
executable file
·49 lines (40 loc) · 1.63 KB
/
eventget.py
File metadata and controls
executable file
·49 lines (40 loc) · 1.63 KB
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
#!/usr/bin/env python3
# To the extent possible under law, the libtcod maintainers have waived all
# copyright and related or neighboring rights for this example. This work is
# published from: United States.
# https://creativecommons.org/publicdomain/zero/1.0/
"""An demonstration of event handling using the tcod.event module.
"""
from typing import List
import tcod
WIDTH, HEIGHT = 720, 480
def main() -> None:
"""Example program for tcod.event"""
event_log: List[str] = []
motion_desc = ""
with tcod.context.new(width=WIDTH, height=HEIGHT) as context:
console = context.new_console()
while True:
# Display all event items.
console.clear()
console.print(0, console.height - 1, motion_desc)
for i, item in enumerate(event_log[::-1]):
y = console.height - 3 - i
if y < 0:
break
console.print(0, y, item)
context.present(console, integer_scaling=True)
# Handle events.
for event in tcod.event.wait():
context.convert_event(event) # Set tile coordinates for event.
print(repr(event))
if isinstance(event, tcod.event.Quit):
raise SystemExit()
if isinstance(event, tcod.event.WindowResized) and event.type == "WINDOWRESIZED":
console = context.new_console()
if isinstance(event, tcod.event.MouseMotion):
motion_desc = str(event)
else:
event_log.append(str(event))
if __name__ == "__main__":
main()