-
Notifications
You must be signed in to change notification settings - Fork 0
/
Window.py
62 lines (45 loc) · 1.9 KB
/
Window.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
from pygame import HWSURFACE, DOUBLEBUF, RESIZABLE, VIDEORESIZE
import pygame
from GameStates.MainGameState import MainGameState
from Utility import Globals
class Window:
def __init__(self):
self.screen_size = (512, 600)
self.screen = pygame.display.set_mode(self.screen_size, HWSURFACE | DOUBLEBUF)
self.fake_screen = self.screen.copy()
self.running = False
self.game_state = None
self.current_frame = 0
self.camera_shake = 0
def shakeCamera(self, intensity):
self.camera_shake = abs(self.camera_shake + intensity)
def setScale(self, scale):
if scale > 3:
scale = 3
self.screen = pygame.display.set_mode((self.screen_size[0] * scale, self.screen_size[1] * scale),
HWSURFACE | DOUBLEBUF | RESIZABLE)
def change_game_state(self, game_state):
if self.game_state is not None:
self.game_state.end()
self.game_state = game_state
if type(self.game_state) is MainGameState:
Globals.game = self.game_state
if self.game_state is not None:
self.game_state.start()
def start(self):
clock = pygame.time.Clock()
self.change_game_state(MainGameState())
self.running = True
while self.running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
Globals.window.running = False
self.game_state.update()
self.game_state.draw(self.fake_screen)
# draw the fake screen on the real screen
self.screen.blit(pygame.transform.scale(self.fake_screen, self.screen.get_rect().size),
(self.camera_shake, 0))
self.camera_shake = -self.camera_shake / 2
pygame.display.flip()
clock.tick(60)
self.current_frame += 1