My Pygame Game Engine

Initial commit

WillM b01a98aa

Changed files
+921
.vscode
__pycache__
src
+2
.gitattributes
··· 1 + # Auto detect text files and perform LF normalization 2 + * text=auto
+15
.vscode/launch.json
··· 1 + { 2 + // Use IntelliSense to learn about possible attributes. 3 + // Hover to view descriptions of existing attributes. 4 + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 + "version": "0.2.0", 6 + "configurations": [ 7 + { 8 + "name": "Python: Project", 9 + "type": "python", 10 + "request": "launch", 11 + "program": "E:\\Coding\\Python\\Pygame\\Folder 2\\Car-Game\\client.py", 12 + "console": "integratedTerminal" 13 + } 14 + ] 15 + }
+2
README.md
··· 1 + # Game Engine 2 + My Pygame Game Engine
__pycache__/client.cpython-39.pyc

This is a binary file and will not be displayed.

__pycache__/game.cpython-39.pyc

This is a binary file and will not be displayed.

__pycache__/input.cpython-39.pyc

This is a binary file and will not be displayed.

__pycache__/notification.cpython-39.pyc

This is a binary file and will not be displayed.

+27
client.py
··· 1 + import pygame, time 2 + from src.scripts.game import Game 3 + from src.scripts.project import * 4 + 5 + game = Game() 6 + 7 + game.initialize() 8 + 9 + while game.running: 10 + ## Update 11 + 12 + update_start_time = time.time() 13 + game.update() 14 + update() 15 + game.end_update() 16 + update_end_time = time.time() 17 + 18 + ## Render 19 + 20 + render_start_time = time.time() 21 + game.render() 22 + render() 23 + game.end_render() 24 + 25 + render_end_time = time.time() 26 + 27 + pygame.quit()
src/__pycache__/__init__.cpython-39.pyc

This is a binary file and will not be displayed.

+4
src/properties.json
··· 1 + { 2 + "id": "Engine", 3 + "version": "0.0.1" 4 + }
+21
src/resources/main/assets/colors.json
··· 1 + { 2 + "notification.border": "#495b66", 3 + "notification.fill": "#c5d4de", 4 + "notification.text": "#272a2e", 5 + 6 + "options.background": "#141517", 7 + "options.text": "#ebeff5", 8 + 9 + "main_menu.background": "#435560", 10 + "main_menu.marker": "#6e7c7c", 11 + "main_menu.text": "#c8c6a7", 12 + "main_menu.dark_text": "#92967d", 13 + "main_menu.bright_bg": "#576974", 14 + "main_menu.bright_bg_2": "#4d5f6a", 15 + 16 + "game.background": "#5f6169", 17 + 18 + "console.background": "#393a3d", 19 + "console.marker": "#f0f0f2", 20 + "console.text": "#f0f0f2" 21 + }
src/resources/main/assets/fonts/default.png

This is a binary file and will not be displayed.

src/resources/main/assets/fonts/default.ttf

This is a binary file and will not be displayed.

src/resources/main/assets/icon.ico

This is a binary file and will not be displayed.

src/resources/main/assets/icon.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/blood/blood_0.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/blood/blood_1.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/blood/blood_2.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/blood/blood_3.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_0.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_1.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_2.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_3.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_4.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_5.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_6.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/car/car_7.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/npc/npc_dead.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/npc/npc_right.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_0.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_1.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_2.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_3.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_4.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_5.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_6.png

This is a binary file and will not be displayed.

src/resources/main/assets/images/wasd/car_7.png

This is a binary file and will not be displayed.

src/resources/main/data/lang/config/autoload

This is a binary file and will not be displayed.

+8
src/resources/main/data/lang/en_US.json
··· 1 + { 2 + "factory.main_screen.play": "Play", 3 + "factory.main_screen.options": "Options", 4 + "factory.main_screen.exit": "Exit", 5 + 6 + "factory.options.show_fps": "Show FPS", 7 + "factory.options.reset_save": "Reset Save" 8 + }
src/scripts/__init__.py

This is a binary file and will not be displayed.

src/scripts/__pycache__/__init__.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/colors.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/debug.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/fonts.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/game.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/input.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/lang.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/language.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/notification.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/options.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/project.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/sound.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/__pycache__/typemania.cpython-39.pyc

This is a binary file and will not be displayed.

+104
src/scripts/game.py
··· 1 + import pygame, os, json, pyautogui, sys, time 2 + 3 + from .modules.input import Input 4 + from .modules.language import Language_Handler 5 + from .modules.colors import Color_Handler 6 + from .modules.sound import Sound_Handler 7 + from .modules.image import image 8 + from .modules.math_utils import math_utils 9 + from .modules.renderer import renderer 10 + from .modules.fonts import font_handler 11 + 12 + from .modules.screens.screen_1 import screen_1 13 + from .modules.screens.screen_2 import screen_2 14 + from .modules.screens.screen_3 import screen_3 15 + from .modules.screens.screen_4 import screen_4 16 + 17 + class Game: 18 + 19 + game_speed = 1 20 + clock = pygame.time.Clock() 21 + 22 + running = True 23 + title = "Game" 24 + 25 + current_assetpack = "main" 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.language_handler = Language_Handler(self) 37 + self.color_handler = Color_Handler(self) 38 + self.sound_handler = Sound_Handler(self) 39 + self.image = image(self) 40 + self.math = math_utils() 41 + self.renderer = renderer(self) 42 + self.font_handler = font_handler(self) 43 + 44 + self.previous_time = time.time() 45 + 46 + self.input.set_input_state('general') 47 + 48 + with open(os.path.join("src", "properties.json"), "r") as file: 49 + self.properties = json.load(file) 50 + 51 + self.change_title(self.properties["id"]) 52 + icon = pygame.image.load(os.path.join("src", "resources", self.current_assetpack, "assets", "icon.png")) 53 + pygame.display.set_icon(icon) 54 + 55 + def initialize(self): 56 + self.change_title(self.properties["id"]) 57 + self.input.input_state = "general" 58 + 59 + sscreen_1 = screen_1(self) 60 + sscreen_2 = screen_2(self) 61 + sscreen_3 = screen_3(self) 62 + sscreen_4 = screen_4(self) 63 + self.renderer.load_screen(sscreen_1, 'screen_1') 64 + self.renderer.load_screen(sscreen_2, 'screen_2') 65 + self.renderer.load_screen(sscreen_3, 'screen_3') 66 + self.renderer.load_screen(sscreen_4, 'screen_4') 67 + self.renderer.switch_screen('screen_1') 68 + 69 + self.screen = 1 70 + 71 + def update(self): 72 + # Calculate Delta Time 73 + now = time.time() 74 + self.delta_time = now - self.previous_time 75 + self.previous_time = now 76 + 77 + self.input.any_key_pressed = False 78 + for event in pygame.event.get(): 79 + if event.type == pygame.QUIT: 80 + self.stop() 81 + if event.type == pygame.KEYDOWN: 82 + self.input.any_key_pressed = True 83 + 84 + if self.input.is_just_pressed('LEFT'): 85 + self.screen -= 1 86 + if self.input.is_just_pressed('RIGHT'): 87 + self.screen += 1 88 + 89 + self.screen = min(4, max(self.screen, 1)) 90 + if self.renderer.current_screen != 'screen_' + str(self.screen): 91 + self.renderer.switch_screen('screen_' + str(self.screen)) 92 + 93 + # Screens 94 + self.renderer.update() 95 + 96 + def end_update(self): 97 + self.input.check_keys() 98 + self.input.mouse_button_last_frame = self.input.is_mouse_button_pressed() 99 + 100 + def render(self): 101 + self.renderer.render() 102 + 103 + def end_render(self): 104 + pass
src/scripts/modules/__pycache__/camera.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/colors.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/console.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/debug.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/ex_math.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/fonts.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/gui.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/image.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/input.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/language.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/math_utils.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/notification.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/renderer.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/screen_handler.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/__pycache__/sound.cpython-39.pyc

This is a binary file and will not be displayed.

+23
src/scripts/modules/colors.py
··· 1 + import json, os 2 + from colormap import hex2rgb 3 + 4 + class Color_Handler: 5 + def __init__(self, game): 6 + self.game = game 7 + 8 + def get_hex(self, color_link): 9 + with open(os.path.join("src", "resources", self.game.current_assetpack, "assets", "colors.json"), "r") as color_file: 10 + color_json = json.load(color_file) 11 + if color_link in color_json: 12 + return color_json[color_link] 13 + else: 14 + return "#00000" 15 + 16 + def get_rgb(self, color_link): 17 + with open(os.path.join("src", "resources", self.game.current_assetpack, "assets", "colors.json"), "r") as color_file: 18 + color_json = json.load(color_file) 19 + if color_link in color_json: 20 + return hex2rgb(color_json[color_link]) 21 + else: 22 + return (0, 0, 0) 23 +
+12
src/scripts/modules/fonts.py
··· 1 + import pygame, os 2 + pygame.font.init() 3 + 4 + class font_handler: 5 + def __init__(self, game) -> None: 6 + self.game = game 7 + 8 + def render(self, text, font, size, color): 9 + font_file = pygame.font.Font(os.path.join('src', 'resources', self.game.current_assetpack, 'assets', 'fonts', font + '.ttf'), size) 10 + return font_file.render(text, True, color) 11 + 12 +
+348
src/scripts/modules/gui.py
··· 1 + import pygame 2 + 3 + class center_constraint(): 4 + pass 5 + 6 + class aspect_constraint(): 7 + def __init__(self, aspect_ratio) -> None: 8 + self.value = aspect_ratio 9 + 10 + class percentage_constraint(): 11 + def __init__(self, percentage): 12 + self.value = percentage 13 + 14 + class pixel_constraint(): 15 + def __init__(self, pixel): 16 + self.value = pixel 17 + 18 + class gui_rect: 19 + x_constraint = None 20 + y_constraint = None 21 + width_constraint = None 22 + height_constraint = None 23 + 24 + x = 0 25 + y = 0 26 + 27 + tween = False 28 + tween_x = 0 29 + tween_y = 0 30 + tween_mult = 0 31 + 32 + tween_s = False 33 + tween_width = 0 34 + tween_height = 0 35 + tween_s_mult = 0 36 + 37 + width = 0 38 + height = 0 39 + 40 + border_radius = 0 41 + outline = 0 42 + 43 + color = (0, 0, 0) 44 + 45 + parent = None 46 + 47 + ## Set Constraints 48 + 49 + # Position Constraints 50 + 51 + def set_x_constraint(self, x_constraint): 52 + self.x_constraint = x_constraint 53 + 54 + def set_y_constraint(self, y_constraint): 55 + self.y_constraint = y_constraint 56 + 57 + # Size Constraints 58 + 59 + def set_width_constraint(self, width_constraint): 60 + self.width_constraint = width_constraint 61 + 62 + def set_height_constraint(self, height_constraint): 63 + self.height_constraint = height_constraint 64 + 65 + # Misc to rect 66 + 67 + def set_border_radius(self, radius): 68 + self.border_radius = radius 69 + 70 + def set_outline_radius(self, outline): 71 + self.outline = outline 72 + 73 + def set_draw_color(self, rgb): 74 + self.color = rgb 75 + 76 + # Tools 77 + 78 + def is_touching_mouse(self): 79 + mx, my = pygame.mouse.get_pos() 80 + if self.game.math.in_rect(mx, my, self.x, self.y , self.width, self.height): 81 + return True 82 + return False 83 + 84 + def tween_to(self, x, y, mult): 85 + self.tween = True 86 + self.tween_x = x 87 + self.tween_y = y 88 + self.tween_mult = mult 89 + 90 + def tween_size(self, width, height, mult): 91 + self.tween_s = True 92 + self.tween_width = width 93 + self.tween_height = height 94 + self.tween_s_mult = mult 95 + 96 + def __init__(self, game) -> None: 97 + self.game = game 98 + self.visible = True 99 + 100 + ## Update thingy 101 + 102 + def update(self): 103 + 104 + ## Set Position thing 105 + 106 + if not self.tween: 107 + # Set X Constraints 108 + 109 + if self.x_constraint != None: 110 + class_use = type(self.x_constraint) 111 + if self.parent == None: 112 + if class_use == center_constraint: 113 + self.x = self.game.renderer.get_screen_size()[0] / 2 - (int(self.width) / 2) 114 + if class_use == percentage_constraint: 115 + self.x = self.game.renderer.get_screen_size()[0] * self.x_constraint.value 116 + if class_use == pixel_constraint: 117 + self.x = self.x_constraint.value 118 + else: 119 + if class_use == center_constraint: 120 + self.x = self.parent.x + (self.parent.width / 2) - (int(self.width) / 2) 121 + if class_use == percentage_constraint: 122 + self.x = self.parent.x + (self.parent.width * self.x_constraint.value) 123 + if class_use == pixel_constraint: 124 + self.x = self.parent.x + self.x_constraint.value 125 + 126 + # Set Y Constraints 127 + 128 + if self.y_constraint != None: 129 + class_use = type(self.y_constraint) 130 + if self.parent == None: 131 + if class_use == center_constraint: 132 + self.y = self.game.renderer.get_screen_size()[1] / 2 - (int(self.height) / 2) 133 + if class_use == percentage_constraint: 134 + self.y = self.game.renderer.get_screen_size()[1] * self.y_constraint.value 135 + if class_use == pixel_constraint: 136 + self.y = self.y_constraint.value 137 + else: 138 + if class_use == center_constraint: 139 + self.y = self.parent.y + (self.parent.height / 2) - (int(self.height) / 2) 140 + if class_use == percentage_constraint: 141 + self.y = self.parent.y + (self.parent.height * self.y_constraint.value) 142 + if class_use == pixel_constraint: 143 + self.y = self.parent.y + self.y_constraint.value 144 + 145 + ## Set size thingy 146 + 147 + if not self.tween_s: 148 + 149 + # Set Width Constraints 150 + 151 + if self.width_constraint != None: 152 + class_use = type(self.width_constraint) 153 + if self.parent == None: 154 + if class_use == percentage_constraint: 155 + self.width = self.game.renderer.get_screen_size()[0] * self.width_constraint.value 156 + if class_use == aspect_constraint: 157 + self.width = self.height * self.width_constraint.value 158 + if class_use == pixel_constraint: 159 + self.width = self.width_constraint.value 160 + else: 161 + if class_use == percentage_constraint: 162 + self.width = self.parent.width * self.width_constraint.value 163 + if class_use == aspect_constraint: 164 + self.width = self.height * self.width_constraint.value 165 + if class_use == pixel_constraint: 166 + self.width = self.width_constraint.value 167 + 168 + # Set Height Constraints 169 + 170 + if self.height_constraint != None: 171 + class_use = type(self.height_constraint) 172 + if self.parent == None: 173 + if class_use == percentage_constraint: 174 + self.height = self.game.renderer.get_screen_size()[1] * self.height_constraint.value 175 + if class_use == aspect_constraint: 176 + self.height = self.width * self.height_constraint.value 177 + if class_use == pixel_constraint: 178 + self.height = self.height_constraint.value 179 + else: 180 + if class_use == percentage_constraint: 181 + self.height = self.parent.height * self.height_constraint.value 182 + if class_use == aspect_constraint: 183 + self.height = self.width * self.height_constraint.value() 184 + if class_use == pixel_constraint: 185 + self.height = self.height_constraint.value 186 + 187 + # Tween Position 188 + 189 + if self.tween: 190 + tmp_x = 0 191 + tmp_y = 0 192 + class_use = type(self.tween_x) 193 + if self.parent == None: 194 + if class_use == center_constraint: 195 + tmp_x = self.game.renderer.get_screen_size()[0] / 2 - (int(self.width) / 2) 196 + if class_use == percentage_constraint: 197 + tmp_x = self.game.renderer.get_screen_size()[0] * self.tween_x.value 198 + if class_use == pixel_constraint: 199 + tmp_x = self.tween_x.value 200 + else: 201 + if class_use == center_constraint: 202 + tmp_x = self.parent.x + (self.parent.width / 2) - (int(self.width) / 2) 203 + if class_use == percentage_constraint: 204 + tmp_x = self.parent.x + (self.parent.width * self.tween_x.value) 205 + if class_use == pixel_constraint: 206 + tmp_x = self.parent.x + self.tween_x.value 207 + 208 + class_use = type(self.tween_y) 209 + if self.parent == None: 210 + if class_use == center_constraint: 211 + tmp_y = self.game.renderer.get_screen_size()[1] / 2 - (int(self.height) / 2) 212 + if class_use == percentage_constraint: 213 + tmp_y = self.game.renderer.get_screen_size()[1] * self.tween_y.value 214 + if class_use == pixel_constraint: 215 + tmp_y = self.tween_y.value 216 + else: 217 + if class_use == center_constraint: 218 + tmp_y = self.parent.y + (self.parent.height / 2) - (int(self.height) / 2) 219 + if class_use == percentage_constraint: 220 + tmp_y = self.parent.y + (self.parent.height * self.tween_y.value) 221 + if class_use == pixel_constraint: 222 + tmp_y = self.parent.y + self.tween_y.value 223 + 224 + self.x += (tmp_x - self.x) / ((self.tween_mult * self.game.delta_time) * 600) 225 + self.y += (tmp_y - self.y) / ((self.tween_mult * self.game.delta_time) * 600) 226 + if int(self.x) == int(tmp_y) and int(self.y) and int(tmp_y): 227 + self.tween = False 228 + self.x_constraint = self.tween_x 229 + self.y_constraint = self.tween_y 230 + 231 + # Tween Size 232 + 233 + if self.tween_s: 234 + tmp_width = 0 235 + tmp_height = 0 236 + class_use = type(self.tween_width) 237 + if self.parent == None: 238 + if class_use == percentage_constraint: 239 + tmp_width = self.game.renderer.get_screen_size()[0] * self.tween_width.value 240 + if class_use == aspect_constraint: 241 + tmp_width = tmp_height 242 + if class_use == pixel_constraint: 243 + tmp_width = self.tween_width.value 244 + else: 245 + if class_use == percentage_constraint: 246 + tmp_width = self.parent.width * self.tween_width.value 247 + if class_use == aspect_constraint: 248 + tmp_width = tmp_height 249 + if class_use == pixel_constraint: 250 + tmp_width = self.tween_width.value 251 + 252 + class_use = type(self.tween_height) 253 + if self.parent == None: 254 + if class_use == percentage_constraint: 255 + tmp_height = self.game.renderer.get_screen_size()[1] * self.tween_height.value 256 + if class_use == aspect_constraint: 257 + tmp_height = tmp_width 258 + if class_use == pixel_constraint: 259 + tmp_height = self.tmp_height.value 260 + else: 261 + if class_use == percentage_constraint: 262 + tmp_height = self.parent.height * self.tmp_height.value 263 + if class_use == aspect_constraint: 264 + tmp_height = tmp_width 265 + if class_use == pixel_constraint: 266 + tmp_height = self.tmp_height.value 267 + 268 + self.width += (tmp_width - self.width) / ((self.tween_s_mult * self.game.delta_time) * 600) 269 + self.height += (tmp_height - self.height) / ((self.tween_s_mult * self.game.delta_time) * 600) 270 + if int(self.width) == int(tmp_width) and int(self.height) and int(tmp_height): 271 + self.tween_s = False 272 + self.width_constraint = self.tween_width 273 + self.height_constraint = self.tween_height 274 + 275 + def render(self): 276 + if self.visible: 277 + pygame.draw.rect(self.game.renderer.screen, self.color, ((self.x, self.y), (self.width, self.height)), self.outline, self.border_radius) 278 + 279 + class gui_toggle_button: 280 + def __init__(self, game) -> None: 281 + self.game = game 282 + self.rect = gui_rect(game) 283 + 284 + self.hover = False 285 + self.toggled = False 286 + 287 + def update(self): 288 + self.rect.update() 289 + if self.rect.is_touching_mouse(): 290 + self.hover = True 291 + else: 292 + self.hover = False 293 + 294 + if self.hover and self.game.input.is_mouse_button_just_pressed(): 295 + self.toggled = not self.toggled 296 + 297 + def render(self): 298 + self.rect.render() 299 + 300 + class gui_press_button: 301 + def __init__(self, game) -> None: 302 + self.game = game 303 + self.rect = gui_rect(game) 304 + 305 + self.hover = False 306 + self.pressed = False 307 + 308 + def update(self): 309 + self.rect.update() 310 + if self.rect.is_touching_mouse(): 311 + self.hover = True 312 + else: 313 + self.hover = False 314 + 315 + if self.hover and self.game.input.is_mouse_button_pressed(): 316 + self.pressed = True 317 + else: 318 + self.pressed = False 319 + 320 + def render(self): 321 + self.rect.render() 322 + 323 + class gui_slider: 324 + def __init__(self, game, val_start, val_end) -> None: 325 + self.game = game 326 + self.slider_body = gui_rect(game) 327 + self.slider_head = gui_rect(game) 328 + 329 + self.value = 0 330 + self.value_range = (val_start, val_end) 331 + 332 + def update(self): 333 + self.slider_body.update() 334 + self.slider_head.update() 335 + 336 + slider_bigger_bounding_box = ((self.slider_body.x, self.slider_body.y - 10), (self.slider_body.width, self.slider_body.height + 30)) 337 + 338 + self.slider_head.x = max(self.slider_body.x, min(self.slider_head.x, self.slider_body.x + self.slider_body.width)) 339 + 340 + self.value = (self.slider_head.x - self.slider_body.x) / (self.slider_body.width / self.value_range[1]) * 1.06 341 + 342 + mx, my = pygame.mouse.get_pos() 343 + if self.game.math.in_rect(mx, my, slider_bigger_bounding_box[0][0], slider_bigger_bounding_box[0][1], slider_bigger_bounding_box[1][0], slider_bigger_bounding_box[1][1]) and self.game.input.is_mouse_button_pressed(): 344 + self.slider_head.tween_to(pixel_constraint(mx - self.slider_head.parent.x - self.slider_head.width / 2), center_constraint(), 12) 345 + 346 + def render(self): 347 + self.slider_body.render() 348 + self.slider_head.render()
+8
src/scripts/modules/image.py
··· 1 + import pygame, os 2 + 3 + class image: 4 + def __init__(self, game): 5 + self.game = game 6 + 7 + def load(self, image): 8 + return pygame.image.load(os.path.join('src', 'resources', self.game.current_assetpack, 'assets', 'images', image))
+49
src/scripts/modules/input.py
··· 1 + from re import L 2 + import pygame, keyboard 3 + 4 + class Input: 5 + 6 + input_state = "main" 7 + 8 + record_keys = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 9 + "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", 10 + "UP", "DOWN", "LEFT", "RIGHT", 11 + "SPACE", "CTRL", "SHIFT", "ALT", "RETURN", "ESCAPE", "TAB", "BACKSPACE", 12 + "period", "subtract", "'"] 13 + 14 + def set_input_state(self, state): 15 + self.input_state = state 16 + 17 + def __init__(self): 18 + self.any_key_pressed = False 19 + 20 + self.last_frame_keys = [] 21 + for i in self.record_keys: 22 + self.last_frame_keys.append(False) 23 + 24 + self.mouse_button_last_frame = False 25 + 26 + def is_pressed(self, key, input_state=""): 27 + if input_state != "": 28 + return bool(keyboard.is_pressed(key) and pygame.mouse.get_focused() and input_state == self.input_state) 29 + else: 30 + return bool(keyboard.is_pressed(key) and pygame.mouse.get_focused()) 31 + 32 + def check_keys(self): 33 + for i, key in enumerate(self.record_keys): 34 + self.last_frame_keys[i] = self.is_pressed(key) 35 + 36 + def is_just_pressed(self, key, input_state=""): 37 + if input_state != "": 38 + return bool(keyboard.is_pressed(key) and not self.last_frame_keys[self.record_keys.index(key)] and pygame.mouse.get_focused() and input_state == self.input_state) 39 + else: 40 + return bool(keyboard.is_pressed(key) and not self.last_frame_keys[self.record_keys.index(key)] and pygame.mouse.get_focused()) 41 + 42 + def is_any_key_pressed(self): 43 + return self.any_key_pressed 44 + 45 + def is_mouse_button_pressed(self): 46 + return pygame.mouse.get_pressed()[0] 47 + 48 + def is_mouse_button_just_pressed(self): 49 + return pygame.mouse.get_pressed()[0] and not self.mouse_button_last_frame
+21
src/scripts/modules/language.py
··· 1 + import json, os 2 + 3 + class Language_Handler: 4 + current_language_id = "en_US" 5 + 6 + def __init__(self, game): 7 + self.game = game 8 + 9 + with open(os.path.join("src", "resources", self.game.current_assetpack, "data", "lang", self.current_language_id + ".json"), "r") as lang_file: 10 + self.lang_json = json.load(lang_file) 11 + 12 + def translatable_text(self, lang_file_link): 13 + if lang_file_link in self.lang_json: 14 + text = self.lang_json[lang_file_link] 15 + return text 16 + else: 17 + return lang_file_link 18 + 19 + 20 + 21 +
+29
src/scripts/modules/math_utils.py
··· 1 + import pygame, math 2 + 3 + class math_utils: 4 + def rotate_center(self, image, angle, x, y): 5 + rotated_image = pygame.transform.rotate(image, angle) 6 + new_rect = rotated_image.get_rect(center = image.get_rect(center = (x, y)).center) 7 + 8 + return rotated_image, new_rect 9 + 10 + def distance_between_points(self, x1, y1, x2, y2): 11 + return math.hypot(x2 - x1, y2 - y1) 12 + 13 + def direction_between_points(self, x1, y1, x2, y2): 14 + radians = math.atan2(y2-y1, x2-x1) 15 + return(math.degrees(radians)) 16 + 17 + def lengthdir_x(self, length, angle): 18 + radian_angle = angle * math.pi / 180 19 + return length * math.cos(radian_angle) 20 + 21 + def lengthdir_y(self, length, angle): 22 + radian_angle = angle * math.pi / 180 23 + return length * math.sin(radian_angle) 24 + 25 + def in_rect(self, x, y, rectx, recty, width, height): 26 + if x > rectx and x < rectx + width: 27 + if y > recty and y < recty + height: 28 + return True 29 + return False
+36
src/scripts/modules/renderer.py
··· 1 + import pygame, pyautogui 2 + 3 + class Screen: 4 + pass 5 + 6 + class Camera: 7 + def __init__(self) -> None: 8 + self.x = 0 9 + self.y = 0 10 + 11 + class renderer: 12 + def __init__(self, game): 13 + self.game = game 14 + self.camera = Camera() 15 + 16 + self.screens = {} 17 + self.current_screen = '' 18 + 19 + self.screen = pygame.display.set_mode((1280, 720), pygame.RESIZABLE) 20 + 21 + def get_screen_size(self): 22 + return (self.screen.get_width(), self.screen.get_height()) 23 + 24 + def load_screen(self, screen: Screen, screen_id): 25 + screen_add = screen 26 + self.screens[screen_id] = screen_add 27 + 28 + def switch_screen(self, screen_id): 29 + self.current_screen = screen_id 30 + 31 + def update(self): 32 + self.screens[self.current_screen].update() 33 + 34 + def render(self): 35 + self.screens[self.current_screen].render() 36 + pygame.display.update()
src/scripts/modules/screens/__init__.py

This is a binary file and will not be displayed.

src/scripts/modules/screens/__pycache__/__init__.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/screens/__pycache__/main_menu.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/screens/__pycache__/screen_1.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/screens/__pycache__/screen_2.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/screens/__pycache__/screen_3.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/modules/screens/__pycache__/screen_4.cpython-39.pyc

This is a binary file and will not be displayed.

+89
src/scripts/modules/screens/screen_1.py
··· 1 + from src.scripts.modules.renderer import Screen 2 + from src.scripts.modules.gui import * 3 + import os 4 + 5 + class screen_1(Screen): 6 + def __init__(self, game): 7 + self.game = game 8 + 9 + self.button = gui_toggle_button(game) 10 + 11 + self.button.rect.set_x_constraint(percentage_constraint(0.06)) 12 + self.button.rect.set_y_constraint(percentage_constraint(0.07)) 13 + self.button.rect.set_height_constraint(percentage_constraint(0.1)) 14 + self.button.rect.set_width_constraint(aspect_constraint(3)) 15 + self.button.rect.set_border_radius(5) 16 + self.button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 17 + 18 + self.slider = gui_slider(game, 0, 100) 19 + 20 + self.slider.slider_body.set_x_constraint(percentage_constraint(0.06)) 21 + self.slider.slider_body.set_y_constraint(percentage_constraint(0.25)) 22 + self.slider.slider_body.set_width_constraint(pixel_constraint(200)) 23 + self.slider.slider_body.set_height_constraint(pixel_constraint(5)) 24 + self.slider.slider_body.set_border_radius(50) 25 + self.slider.slider_body.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 26 + 27 + self.slider.slider_head.parent = self.slider.slider_body 28 + self.slider.slider_head.set_x_constraint(pixel_constraint(0)) 29 + self.slider.slider_head.set_y_constraint(center_constraint()) 30 + self.slider.slider_head.set_width_constraint(pixel_constraint(20)) 31 + self.slider.slider_head.set_height_constraint(pixel_constraint(20)) 32 + self.slider.slider_head.set_border_radius(10) 33 + self.slider.slider_head.set_draw_color(self.game.color_handler.get_rgb('main_menu.text')) 34 + 35 + self.button2 = gui_toggle_button(game) 36 + 37 + self.button2.rect.set_x_constraint(percentage_constraint(0.06)) 38 + self.button2.rect.set_y_constraint(percentage_constraint(0.32)) 39 + self.button2.rect.set_width_constraint(percentage_constraint(0.12)) 40 + self.button2.rect.set_height_constraint(percentage_constraint(0.1)) 41 + self.button2.rect.set_outline_radius(5) 42 + self.button2.rect.set_border_radius(30) 43 + self.button2.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 44 + 45 + self.button_inside_rect = gui_rect(game) 46 + 47 + self.button_inside_rect.parent = self.button2.rect 48 + self.button_inside_rect.set_x_constraint(percentage_constraint(0.05)) 49 + self.button_inside_rect.set_y_constraint(center_constraint()) 50 + self.button_inside_rect.set_width_constraint(aspect_constraint(1)) 51 + self.button_inside_rect.set_height_constraint(percentage_constraint(0.8)) 52 + self.button_inside_rect.set_border_radius(30) 53 + self.button_inside_rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 54 + 55 + def update(self): 56 + self.button.update() 57 + self.slider.update() 58 + self.button2.update() 59 + self.button_inside_rect.update() 60 + 61 + self.button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 62 + if self.button.hover: 63 + self.button.rect.tween_to(percentage_constraint(0.08), percentage_constraint(0.07), 24) 64 + self.button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg_2')) 65 + else: 66 + self.button.rect.tween_to(percentage_constraint(0.06), percentage_constraint(0.07), 24) 67 + 68 + if self.button.toggled: 69 + self.button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.text')) 70 + self.button.rect.tween_to(percentage_constraint(0.08), percentage_constraint(0.07), 24) 71 + 72 + if self.button2.hover: 73 + self.button_inside_rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg_2')) 74 + else: 75 + self.button_inside_rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 76 + 77 + self.button_inside_rect.tween_to(percentage_constraint(0.05), center_constraint(), 24) 78 + if self.button2.toggled: 79 + self.button_inside_rect.tween_to(percentage_constraint(0.57), center_constraint(), 24) 80 + 81 + def render(self): 82 + self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 83 + self.button.render() 84 + self.slider.render() 85 + self.button2.render() 86 + self.button_inside_rect.render() 87 + self.game.renderer.screen.blit(self.game.font_handler.render(str(int(self.slider.value)), 'default', 32, self.game.color_handler.get_rgb('main_menu.text')), (300, 160)) 88 + #value = int((self.slider_head.x - self.slider_body.x) / (self.slider_body.width / 100)) 89 + #self.game.renderer.screen.blit(self.game.font_handler.render(str(value), 'default', 48, self.game.color_handler.get_rgb('main_menu.text')), (20, 20))
+33
src/scripts/modules/screens/screen_2.py
··· 1 + from src.scripts.modules.renderer import Screen 2 + from src.scripts.modules.gui import * 3 + import os 4 + 5 + class screen_2(Screen): 6 + def __init__(self, game): 7 + self.game = game 8 + 9 + self.slider = gui_slider(game, 0, 100) 10 + 11 + self.slider.slider_body.set_x_constraint(center_constraint()) 12 + self.slider.slider_body.set_y_constraint(center_constraint()) 13 + self.slider.slider_body.set_width_constraint(pixel_constraint(200)) 14 + self.slider.slider_body.set_height_constraint(pixel_constraint(5)) 15 + self.slider.slider_body.set_border_radius(10) 16 + self.slider.slider_body.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 17 + 18 + self.slider.slider_head.parent = self.slider.slider_body 19 + self.slider.slider_head.set_x_constraint(pixel_constraint(0)) 20 + self.slider.slider_head.set_y_constraint(center_constraint()) 21 + self.slider.slider_head.set_width_constraint(pixel_constraint(20)) 22 + self.slider.slider_head.set_height_constraint(pixel_constraint(20)) 23 + self.slider.slider_head.set_border_radius(10) 24 + self.slider.slider_head.set_draw_color(self.game.color_handler.get_rgb('main_menu.text')) 25 + 26 + def update(self): 27 + self.slider.update() 28 + 29 + def render(self): 30 + self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 31 + self.slider.render() 32 + #value = int((self.slider_head.x - self.slider_body.x) / (self.slider_body.width / 100)) 33 + #self.game.renderer.screen.blit(self.game.font_handler.render(str(value), 'default', 48, self.game.color_handler.get_rgb('main_menu.text')), (20, 20))
+22
src/scripts/modules/screens/screen_3.py
··· 1 + from src.scripts.modules.renderer import Screen 2 + from src.scripts.modules.gui import * 3 + import os 4 + 5 + class screen_3(Screen): 6 + def __init__(self, game): 7 + self.game = game 8 + 9 + self.rect = gui_rect(game) 10 + 11 + self.rect.set_x_constraint(center_constraint()) 12 + self.rect.set_y_constraint(pixel_constraint(20)) 13 + self.rect.set_width_constraint(percentage_constraint(0.1)) 14 + self.rect.set_height_constraint(aspect_constraint(1)) 15 + self.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 16 + 17 + def update(self): 18 + self.rect.update() 19 + 20 + def render(self): 21 + self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 22 + self.rect.render()
+46
src/scripts/modules/screens/screen_4.py
··· 1 + from src.scripts.modules.renderer import Screen 2 + from src.scripts.modules.gui import * 3 + import os 4 + 5 + class screen_4(Screen): 6 + def __init__(self, game): 7 + self.game = game 8 + 9 + self.button = gui_toggle_button(game) 10 + 11 + self.button.rect.set_x_constraint(center_constraint()) 12 + self.button.rect.set_y_constraint(center_constraint()) 13 + self.button.rect.set_width_constraint(percentage_constraint(0.12)) 14 + self.button.rect.set_height_constraint(percentage_constraint(0.1)) 15 + self.button.rect.set_outline_radius(5) 16 + self.button.rect.set_border_radius(30) 17 + self.button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 18 + 19 + self.button_inside_rect = gui_rect(game) 20 + 21 + self.button_inside_rect.parent = self.button.rect 22 + self.button_inside_rect.set_x_constraint(percentage_constraint(0.05)) 23 + self.button_inside_rect.set_y_constraint(center_constraint()) 24 + self.button_inside_rect.set_width_constraint(aspect_constraint(1)) 25 + self.button_inside_rect.set_height_constraint(percentage_constraint(0.8)) 26 + self.button_inside_rect.set_border_radius(30) 27 + self.button_inside_rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 28 + 29 + 30 + def update(self): 31 + self.button.update() 32 + self.button_inside_rect.update() 33 + 34 + if self.button.hover: 35 + self.button_inside_rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg_2')) 36 + else: 37 + self.button_inside_rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 38 + 39 + self.button_inside_rect.tween_to(percentage_constraint(0.05), center_constraint(), 24) 40 + if self.button.toggled: 41 + self.button_inside_rect.tween_to(percentage_constraint(0.57), center_constraint(), 24) 42 + 43 + def render(self): 44 + self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 45 + self.button.render() 46 + self.button_inside_rect.render()
+17
src/scripts/modules/sound.py
··· 1 + import pygame, os 2 + pygame.mixer.init() 3 + 4 + class Sound_Handler: 5 + 6 + sounds = {} 7 + 8 + def __init__(self, game): 9 + self.game = game 10 + 11 + def load_sound(self, sound_id, sound_file): 12 + self.sounds[sound_id] = { 13 + "file": pygame.mixer.Sound(os.path.join("src", "resources", self.game.current_assetpack, "assets", "sounds", sound_file + ".ogg")) 14 + } 15 + 16 + def play_sound(self, sound_id): 17 + self.sounds[sound_id]["file"].play()
+5
src/scripts/project.py
··· 1 + def update(): 2 + pass 3 + 4 + def render(): 5 + pass