-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
77 lines (57 loc) · 1.96 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
import pygame
from pathlib import Path
from functools import lru_cache
from scripts.input import InputManager
from scripts.window import Window
from scripts.arrows import ArrowsArea
from scripts.score import Score
from scripts.menu import Menu
from scripts.levellist import LevelList
class ArrowGame:
FRAME_RATE = 60
def __init__(self):
pygame.init()
pygame.mixer.init()
self.click = pygame.mixer.Sound("data/sounds/click.wav")
self.select = pygame.mixer.Sound("data/sounds/select.wav")
self.accent_colour = (200, 55, 181)
self.screen = "menu"
self.clock = pygame.time.Clock()
self.frame = 0
self.data = Path("data")
self.window = Window(self)
self.input = InputManager(self)
self.arrows_area = ArrowsArea(self)
self.score = Score(self)
self.menu = Menu(self)
self.level_list = LevelList(self)
@lru_cache
def load_image(self, filename):
return pygame.image.load(self.data / "images" / filename)
def mainloop(self):
while True:
self.input.process_inputs()
self.window.update()
self.show_screen()
self.window.render()
self.clock.tick(self.FRAME_RATE)
self.frame += 1
def show_screen(self):
if self.screen == "game":
self.arrows_area.update(self.frame)
self.arrows_area.render()
self.score.update(self.frame)
self.score.render()
elif self.screen == "menu":
self.menu.update(self.frame)
self.menu.render()
elif self.screen == "list":
self.level_list.update(self.frame)
self.level_list.render()
def play_song(self, song_path, difficulty=0):
self.screen = "game"
self.arrows_area.song.load(song_path, difficulty)
self.arrows_area.song.play()
if __name__ == "__main__":
game = ArrowGame()
game.mainloop()