1import pygame, os, json, pyautogui, sys, time
2
3from .modules.input import Input
4from .modules.notification import Notification_Handler
5from .modules.language import Language_Handler
6from .modules.colors import Color_Handler
7from .modules.fonts import Font_Handler
8from .modules.sound import Sound_Handler
9from .typemania.typemania import typemania
10
11from .options import options
12
13class Game:
14 main_screen = pygame.display.set_mode((1920, 1080))
15 main_surface = pygame.Surface((1920, 1080))
16
17 game_speed = 1
18 clock = pygame.time.Clock()
19
20 running = True
21 title = "Game"
22
23 current_assetpack = "main"
24
25 display_width, display_height = pyautogui.size()
26
27 def stop(self):
28 self.running = False
29
30 def change_title(self, title):
31 self.title = title
32 pygame.display.set_caption(title)
33
34 def __init__(self):
35 self.input = Input()
36 self.notification_handler = Notification_Handler(self)
37 self.language_handler = Language_Handler(self)
38 self.color_handler = Color_Handler(self)
39 self.font_handler = Font_Handler(self)
40 self.sound_handler = Sound_Handler(self)
41
42 self.typemania = typemania(self)
43
44 self.display_width, self.display_height = pyautogui.size()
45
46 self.scene_options = options(self)
47
48 self.show_debug = False
49
50 self.previous_time = time.time()
51
52 with open(os.path.join("src", "properties.json"), "r") as file:
53 self.properties = json.load(file)
54
55 self.change_title(self.properties["id"])
56 icon = pygame.image.load(os.path.join("src", "resources", self.current_assetpack, "assets", "icon.png"))
57 pygame.display.set_icon(icon)
58
59 def initialize(self):
60 self.notification_handler.send("Successful Start", "Game started succesfully on version " + self.properties["version"])
61 self.change_title(self.properties["id"])
62 self.input.input_state = "game"
63
64 def begin_update(self):
65
66 # Calculate Delta Time
67 now = time.time()
68 self.delta_time = now - self.previous_time
69 self.previous_time = now
70
71 self.input.any_key_pressed = False
72 for event in pygame.event.get():
73 if event.type == pygame.QUIT:
74 self.stop()
75 if event.type == pygame.KEYDOWN:
76 self.input.any_key_pressed = True
77
78 def update(self):
79 self.scene_options.update()
80
81 def end_update(self):
82 self.notification_handler.update()
83
84 self.input.check_keys()
85
86 def render(self):
87 self.scene_options.render()
88
89 self.notification_handler.render()
90
91 copyright_text = self.font_handler.get_font("default_15").render("willmexe © 2021", True, (self.color_handler.get_color_rgb("typemania.text")))
92 self.main_surface.blit(copyright_text, (self.display_width / 2 - copyright_text.get_width() / 2, self.display_height - self.font_handler.get_font_size("default_15") - 10))
93
94 def main_loop_final(self, update_time, render_time):
95 if self.scene_options.show_fps == True:
96 self.scene_options.fps_module.draw_stats(update_time, render_time)
97
98 surf = self.main_surface
99 if self.main_screen.get_width() != self.main_surface.get_width():
100 if self.main_screen.get_height() != self.main_surface.get_height():
101 surf = pygame.transform.scale(self.main_surface, (self.main_screen.get_width(), self.main_screen.get_height()))
102 self.main_screen.blit(surf, (0, 0))
103 pygame.display.update()
104 self.clock.tick(60)