-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (47 loc) · 1.33 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
import sys
import pygame
from pygame.locals import *
from src.game_engine import GameEngine
from src.utils.custom_events import *
pygame.init()
# Initialisation
pygame.display.set_caption("Pyjeweled")
engine = GameEngine()
# Allow only events that are relevant
pygame.event.set_allowed([
MOUSEMOTION,
MOUSEBUTTONUP,
MOUSEBUTTONDOWN
])
loop = True
while loop:
# Update the game
engine.tick()
# Read player inputs
for event in pygame.event.get():
pygame.event.pump()
# Click the close button = quit game
if event.type == QUIT:
loop = False
# Mouse events handling
elif event.type == MOUSEMOTION:
engine.on_mouse_motion(event)
elif event.type == MOUSEBUTTONDOWN:
engine.on_mouse_down(event)
# Timer handling
elif event.type == DEBOUNCE_ALLOW:
engine.debounce = False
# Game start
elif event.type == RESET:
engine.reset()
elif event.type == START_EASY:
engine.start("easy", False)
elif event.type == START_MEDIUM:
engine.start("medium", False)
elif event.type == START_HARD:
engine.start("hard", False)
elif event.type == START_INFINITE:
engine.start("infinite", True)
print("Bye!")
pygame.quit()
sys.exit()