-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
67 lines (50 loc) · 1.86 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
"""Main file of the game."""
import sys
import pygame
from src.canvas import build_canvas, get_canvas
from src.command_line import CL
from src.level import Level
from src.screen import Screen
from src.settings import FPS, WATER_COLOR
class Game:
"""Game object."""
def __init__(self):
"""Initialize pygame and set caption."""
pygame.init()
pygame.display.set_caption("CLing")
self.clock = pygame.time.Clock()
# Create canvas with a screen and a command line
self.canvas = get_canvas()
self.cmd_line = CL(canvas=self.canvas)
self.screen = Screen(self.canvas, self.cmd_line)
# Initialize Level object with all game interactions
self.level = Level(self.screen, self.cmd_line)
# Sound effect
main_sound = pygame.mixer.Sound("src/audio/main.ogg")
main_sound.set_volume(0.01)
main_sound.play(loops=-1)
def run(self):
"""Run game."""
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Run CL methods interacting with events
self.cmd_line.run_event(event, self.level)
# # Pause game and toggle menu screen
# if event.type == pygame.KEYDOWN:
# if event.key == pygame.K_m:
# self.level.toggle_menu()
# Build layout screen + command line
build_canvas(self.canvas, self.screen, self.cmd_line)
# Draw and update on screen and command line
self.screen.surface.fill(WATER_COLOR)
self.level.run()
# Update
pygame.display.update()
self.clock.tick(FPS)
if __name__ == "__main__":
game = Game()
game.run()