-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
92 lines (76 loc) · 2.83 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import time
import pygame
from pygame.locals import *
# Local imports
from constants import *
from durak_game import Durak
from menu import Menu
class MainController:
def __init__(self):
# Create pygame instance, set screen, clock
pygame.init()
pygame.display.set_caption("Durak")
self.screen = pygame.display.set_mode(SCREENSIZE, 0, 32)
self.clock = pygame.time.Clock()
self.clock.tick(60)
self.debugFont = pygame.font.SysFont("Arial", 18)
# screen_state decides what the screen should be aspirationally displaying
self.screen_state = MENU_SCREEN
# animate_state decides what we are currently animating
self.animate_state = MENU_SCREEN
self.game_created = False
self.background, self.game = None, None
self.menu = Menu(self.clock)
self.set_background()
def set_background(self):
self.background = pygame.surface.Surface(SCREENSIZE)
self.background.fill(GREEN)
# Start Game
def start_game(self):
self.game = Durak(self.clock, self)
# Update
def update(self):
self.check_events()
if self.screen_state == MENU_SCREEN:
self.menu.update()
elif self.screen_state == GAME_SCREEN:
# create and start game
if not self.game_created:
self.start_game()
self.game_created = True
self.game.update()
self.render()
# Check Events
def check_events(self):
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == MOUSEBUTTONDOWN:
if self.animate_state == MENU_SCREEN:
self.menu.mouse_click()
self.animate_state = self.menu.get_menu_click()
elif self.animate_state == GAME_SCREEN:
self.game.mouse_click()
# Render
def render(self):
self.screen.blit(self.background, (0, 0))
if self.screen_state == GAME_SCREEN:
self.game.render(self.screen)
# "kill" our menu if we don't need it
if self.menu is not None:
self.menu = None
if self.animate_state == MENU_SCREEN:
self.menu.render(self.screen)
elif self.animate_state == GAME_SCREEN:
# animate menu off screen while screen_state waits
if self.screen_state == MENU_SCREEN:
self.menu.render(self.screen)
self.screen_state = self.menu.animate_off()
self.draw_FPS()
pygame.display.update()
def draw_FPS(self):
self.screen.blit(self.debugFont.render(str(round(self.clock.get_fps())), False, (255, 255, 0)), (15, 0))
if __name__ == '__main__':
main_window = MainController()
while True:
main_window.update()