-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (42 loc) · 1.5 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
import sys
import pygame
from settings import SCREEN_WIDTH, SCREEN_HEIGHT
from player import Player
from camera import Camera
from game import Scene1
class GameWindow:
def __init__(self):
pygame.init()
self.window_surface = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
self.clock = pygame.time.Clock()
self.player1 = Player()
self.player2 = Player(
"P2", "orange", pygame.K_j, pygame.K_l, pygame.K_i, pygame.K_k
)
self.camera1 = Camera(self.player1, (0, 0))
self.camera2 = Camera(self.player2, (0, SCREEN_HEIGHT // 2))
self.set_scene()
def set_scene(self):
self.scene = Scene1([self.player1, self.player2])
def run(self):
dt = 0.0
while True:
self.window_surface.fill("black")
for event in pygame.event.get([pygame.QUIT]):
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
self.scene.update(dt)
self.camera1.update(self.scene.scene_surface)
self.camera2.update(self.scene.scene_surface)
self.window_surface.blit(
self.camera1.camera_surface, self.camera1.screen_pos
)
self.window_surface.blit(
self.camera2.camera_surface, self.camera2.screen_pos
)
pygame.display.update()
dt = self.clock.tick(60) / 1000
if __name__ == "__main__":
game = GameWindow()
game.run()