-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (53 loc) · 1.65 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
63
64
65
66
67
68
69
70
"""
LodeRunner Clone
----------------
By: Bonnie Ishiguro and Nick Francisci
for Game Programming: Level 4
"""
import time
from config import Config
from graphics import *
from drawable import Drawable
from tiles import Tile, Gold, HiddenLadder
from characters import *
from event import Event
# TODO: Move these somewhere more appropriate (drawable?)
def load_level(num):
Config.config_level(num)
Drawable.recreateWindow()
Tile.load_level(num)
Character.load_characters(num)
KEYMAP = {
'Left': 'Player.main.move(-1, 0)',
'Right': 'Player.main.move(1, 0)',
'Up': 'Player.main.move(0, -1)',
'Down': 'Player.main.move(0, 1)',
'a': 'Player.main.dig(-1)',
'z': 'Player.main.dig(1)',
'q': 'exit(0)'
}
LEVELS = [1, 2]
def main():
frame_duration = 1.0/60.0
for level in LEVELS:
load_level(level)
while not Player.main.at_exit():
frame_start_time = time.time()
key = Drawable._window.checkKey()
if key in KEYMAP:
eval(KEYMAP[key])
Event.update()
if not Config.hidden_flag:
if Gold.all_taken():
HiddenLadder.showAll()
Player.main.redraw()
for baddie in Baddie.baddies:
baddie.redraw()
Config.hidden_flag = True
# baddies should probably move here
frame_time = time.time() - frame_start_time
if frame_time < frame_duration:
time.sleep(frame_duration - frame_time)
Drawable.won()
if __name__ == '__main__':
main()