-
Notifications
You must be signed in to change notification settings - Fork 0
/
adventure.py
74 lines (54 loc) · 1.73 KB
/
adventure.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
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import libtcodpy as libtcod
class Screen:
""" Screen for viewing the game
includes screen properties
such as frame_rate"""
height = 50
width = 80
limit_fps = 20
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(width, height, 'Blossom Rogue', False)
libtcod.sys_set_fps(limit_fps)
def __init__ (self):
""" Class initialiser """
pass
class Player:
""" Player Character Object """
name = 'hero'
hit_points = 0
strength = 0
dexterity = 0
endurance = 0
location_x = Screen.width/2
location_y = Screen.height/2
avatar = '@'
def __init__ (self):
""" Class initialiser """
pass
def handle_keys():
key = libtcod.console_wait_for_keypress(True)
if key.vk == libtcod.KEY_ENTER and key.lalt:
#Alt+Enter: toggle fullscreen
libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
elif key.vk == libtcod.KEY_ESCAPE:
return True #exit game
if libtcod.console_is_key_pressed(libtcod.KEY_UP):
Player.location_y -= 1
elif libtcod.console_is_key_pressed(libtcod.KEY_DOWN):
Player.location_y += 1
elif libtcod.console_is_key_pressed(libtcod.KEY_LEFT):
Player.location_x -= 1
elif libtcod.console_is_key_pressed(libtcod.KEY_RIGHT):
Player.location_x += 1
def Game():
while not libtcod.console_is_window_closed():
libtcod.console_set_foreground_color(0, libtcod.white)
libtcod.console_print_left(0, Player.location_x, Player.location_y, libtcod.BKGND_NONE, Player.avatar)
libtcod.console_flush()
libtcod.console_print_left(0, Player.location_x, Player.location_y, libtcod.BKGND_NONE, ' ')
exit = handle_keys()
if exit:
break
if __name__=='__main__':
Game()