-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (43 loc) · 1.63 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
import pygame
from ui import * # pylint: disable=unused-wildcard-import
# pylint: disable=no-member
class App:
"""Create a single-window app with multiple scenes."""
def __init__(self):
"""Initialize pygame and the application."""
pygame.init()
pygame.display.set_caption("2048 in Python!")
icon = pygame.image.load('images\\2048_white.png')
pygame.display.set_icon(icon)
self.TILE_SIZE = 100
self.WIDTH = ((self.TILE_SIZE+20) * (4))-10
self.HEIGHT = ((self.TILE_SIZE+20) * (5))-10
self.SCREEN_SIZE = (self.WIDTH, self.HEIGHT)
self.screen = pygame.display.set_mode(self.SCREEN_SIZE)
self.running = True
self.board = Board()
def run(self):
"""Run the main event loop."""
activeScene = MenuScene(self.screen, self.board)
clock = pygame.time.Clock()
while activeScene != None:
pressedKeys = pygame.key.get_pressed()
# Event filtering
filteredEvents = []
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
self.board.save_game()
if not self.running:
activeScene.Terminate()
else:
filteredEvents.append(event)
activeScene.ProcessInput(filteredEvents, pressedKeys)
activeScene.Update()
activeScene.Render()
activeScene = activeScene.next
pygame.display.flip()
clock.tick(60)
pygame.quit()
if __name__ == '__main__':
App().run()