]>
Commit | Line | Data |
---|---|---|
d8ab67c7 | 1 | import sys |
189bf90c | 2 | import pygame |
189bf90c | 3 | import helpers |
e7f8dab4 | 4 | import threading |
189bf90c | 5 | |
8f88a3e4 | 6 | pygame.mixer.pre_init(frequency = 44100) |
189bf90c IB |
7 | pygame.init() |
8 | ||
9 | size = width, height = 1024, 600 | |
189bf90c | 10 | screen = pygame.display.set_mode(size) |
ba9ea93a IB |
11 | screen.fill((250, 250, 250)) |
12 | ||
13 | draw_lock = helpers.Lock("draw") | |
189bf90c | 14 | |
ba9ea93a | 15 | mapping = helpers.Mapping(screen, draw_lock) |
e7f8dab4 | 16 | helpers.parse_config(mapping) |
8f88a3e4 | 17 | |
e7f8dab4 | 18 | mapping.draw() |
189bf90c | 19 | |
ba9ea93a | 20 | draw_lock.acquire() |
189bf90c | 21 | pygame.display.flip() |
ba9ea93a | 22 | draw_lock.release() |
189bf90c IB |
23 | |
24 | contexts = [ | |
25 | 'normal' | |
26 | ] | |
27 | ||
28 | context = 'normal' | |
29 | ||
30 | while 1: | |
31 | event = pygame.event.wait() | |
e7f8dab4 | 32 | |
189bf90c IB |
33 | if event.type == pygame.QUIT or ( |
34 | event.type == pygame.KEYDOWN and | |
35 | event.mod == 4160 and | |
36 | event.key == pygame.K_c): | |
be27763f IB |
37 | for thread in threading.enumerate(): |
38 | if thread is threading.current_thread(): | |
39 | continue | |
40 | thread.join() | |
41 | ||
189bf90c IB |
42 | pygame.quit() |
43 | sys.exit() | |
44 | ||
45 | if context == 'normal': | |
d8ab67c7 | 46 | if event.type == pygame.KEYDOWN: |
e7f8dab4 | 47 | key = mapping.find_by_key_num(event.key) |
d8ab67c7 | 48 | if key is not None: |
e7f8dab4 | 49 | threading.Thread(target=key.do_actions).start() |
d8ab67c7 | 50 | elif event.type == pygame.MOUSEBUTTONUP: |
e7f8dab4 | 51 | key = mapping.find_by_collidepoint(pygame.mouse.get_pos()) |
d8ab67c7 | 52 | if key is not None: |
ba9ea93a | 53 | threading.Thread(target=key.list_actions, args = [screen]).start() |
189bf90c | 54 | |
ba9ea93a | 55 | draw_lock.acquire() |
189bf90c | 56 | pygame.display.flip() |
ba9ea93a | 57 | draw_lock.release() |
189bf90c | 58 |