-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgame.py
53 lines (43 loc) · 1.38 KB
/
game.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
import pygame
import constants as c
import frame as f
import sys
from sound_manager import SoundManager
from image_manager import ImageManager
class Game:
def __init__(self):
pygame.init()
pygame.mixer.set_num_channels(20)
SoundManager.init()
ImageManager.init()
self.screen = pygame.display.set_mode(c.WINDOW_SIZE)
pygame.display.set_caption(c.CAPTION)
self.clock = pygame.time.Clock()
self.main()
def main(self):
current_frame = f.GameFrame(self)
current_frame.load()
self.clock.tick(60)
while True:
dt, events = self.get_events()
if dt > 0.05:
dt = 0.05
current_frame.update(dt, events)
current_frame.draw(self.screen, (0, 0))
pygame.display.flip()
if current_frame.done:
current_frame = current_frame.next_frame()
current_frame.load()
def get_events(self):
dt = self.clock.tick(c.FRAMERATE)/1000
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_F4:
pygame.display.toggle_fullscreen()
return dt, events
if __name__=="__main__":
Game()