Browse code
...
Ed L authored on 24/07/2012 02:47:49
Showing 1 changed files
Showing 1 changed files
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,60 @@ |
1 |
+import libtcodpy as libtcod |
|
2 |
+ |
|
3 |
+#actual size of the window |
|
4 |
+SCREEN_WIDTH = 80 |
|
5 |
+SCREEN_HEIGHT = 50 |
|
6 |
+ |
|
7 |
+LIMIT_FPS = 20 #20 frames-per-second maximum |
|
8 |
+ |
|
9 |
+ |
|
10 |
+def handle_keys(): |
|
11 |
+ global playerx, playery |
|
12 |
+ |
|
13 |
+ #key = libtcod.console_check_for_keypress() #real-time |
|
14 |
+ key = libtcod.console_wait_for_keypress(True) #turn-based |
|
15 |
+ |
|
16 |
+ if key.vk == libtcod.KEY_ENTER and key.lalt: |
|
17 |
+ #Alt+Enter: toggle fullscreen |
|
18 |
+ libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen()) |
|
19 |
+ |
|
20 |
+ elif key.vk == libtcod.KEY_ESCAPE: |
|
21 |
+ return True #exit game |
|
22 |
+ |
|
23 |
+ #movement keys |
|
24 |
+ if libtcod.console_is_key_pressed(libtcod.KEY_UP): |
|
25 |
+ playery -= 1 |
|
26 |
+ |
|
27 |
+ elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN): |
|
28 |
+ playery += 1 |
|
29 |
+ |
|
30 |
+ elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT): |
|
31 |
+ playerx -= 1 |
|
32 |
+ |
|
33 |
+ elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT): |
|
34 |
+ playerx += 1 |
|
35 |
+ |
|
36 |
+ |
|
37 |
+############################################# |
|
38 |
+# Initialization & Main Loop |
|
39 |
+############################################# |
|
40 |
+ |
|
41 |
+libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD) |
|
42 |
+libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False) |
|
43 |
+libtcod.sys_set_fps(LIMIT_FPS) |
|
44 |
+ |
|
45 |
+playerx = SCREEN_WIDTH/2 |
|
46 |
+playery = SCREEN_HEIGHT/2 |
|
47 |
+ |
|
48 |
+libtcod.console_set_default_foreground(0, libtcod.white) |
|
49 |
+while not libtcod.console_is_window_closed(): |
|
50 |
+ |
|
51 |
+ libtcod.console_print(0, playerx, playery, '@') |
|
52 |
+ |
|
53 |
+ libtcod.console_flush() |
|
54 |
+ |
|
55 |
+ libtcod.console_print(0, playerx, playery, ' ') |
|
56 |
+ |
|
57 |
+ #handle keys and exit game if needed |
|
58 |
+ exit = handle_keys() |
|
59 |
+ if exit: |
|
60 |
+ break |