My Pygame Game Engine

Fixed input to work on mac

ffs

WillM 9ffe3c8f bf54c43e

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

This is a binary file and will not be displayed.

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

This is a binary file and will not be displayed.

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

This is a binary file and will not be displayed.

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

This is a binary file and will not be displayed.

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

This is a binary file and will not be displayed.

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

This is a binary file and will not be displayed.

-66
src/scripts/game/bullet.py
··· 1 - import pygame, math, random 2 - from src.scripts.modules.entity import * 3 - 4 - class bullet_shooty_thingy: 5 - def __init__(self, game, parent) -> None: 6 - self.game = game 7 - self.parent = parent 8 - 9 - self.parent.bullets = [] 10 - self.image = self.game.image.load("bullet.png") 11 - 12 - self.firerate = 20 13 - self.firerate_counter = 0 14 - 15 - def update(self): 16 - self.firerate_counter += 100 * self.game.delta_time 17 - if self.game.input.is_mouse_button_pressed() and self.firerate_counter > self.firerate: 18 - self.firerate_counter = 0 19 - mx, my = pygame.mouse.get_pos() 20 - self.parent.bullets.append([self.parent.transform.x, self.parent.transform.y, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, self.game.relative_mxmy[0], self.game.relative_mxmy[1]) + random.randrange(-5, 5), 400]) 21 - 22 - for i, item in enumerate(self.parent.bullets): 23 - for j, jtem in enumerate(self.parent.screen.enemy.bullets): 24 - if self.game.math.distance_between_points(item[0], item[1], jtem[0], jtem[1]) < 30: 25 - self.parent.bullets.pop(i) 26 - self.parent.screen.enemy.bullets.pop(j) 27 - break 28 - 29 - def render(self): 30 - move_speed = 700 * self.game.delta_time 31 - new_bullets = self.parent.bullets 32 - for i, item in enumerate(self.parent.bullets): 33 - item[3] -= 1 34 - if item[3] == 0: 35 - new_bullets.pop(i) 36 - item[0] += self.game.math.lengthdir_x(move_speed, item[2]) 37 - item[1] += self.game.math.lengthdir_y(move_speed, item[2]) 38 - image = pygame.transform.scale(self.image, (50, 25)) 39 - img, rect = self.game.math.rotate_center(image, 180 - item[2] + 180, item[0], item[1]) 40 - self.parent.screen.game_surface.blit(img, rect) 41 - self.parent.bullets = new_bullets 42 - 43 - class bullet_shooty_thingy2: 44 - def __init__(self, game, parent) -> None: 45 - self.game = game 46 - self.parent = parent 47 - 48 - self.parent.bullets = [] 49 - self.image = self.game.image.load("bullet.png") 50 - 51 - def update(self): 52 - if self.game.input.is_mouse_button_just_pressed(): 53 - mx, my = pygame.mouse.get_pos() 54 - self.parent.bullets.append([self.parent.transform.x, self.parent.transform.y, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, mx, my), 400]) 55 - 56 - def render(self): 57 - new_bullets = self.parent.bullets 58 - for i, item in enumerate(self.parent.bullets): 59 - item[3] -= 1 60 - if item[3] == 0: 61 - new_bullets.pop(i) 62 - item[0] += self.game.math.lengthdir_x(1, item[2]) 63 - item[1] += self.game.math.lengthdir_y(1, item[2]) 64 - img, rect = self.game.math.rotate_center(self.image, item[3], item[0], item[1]) 65 - self.game.renderer.screen.blit(pygame.transform.scale(img, (50, 25)), rect) 66 - self.parent.bullets = new_bullets
-113
src/scripts/game/enemy.py
··· 1 - import pygame, math 2 - from src.scripts.modules.entity import * 3 - from .bullet import bullet_shooty_thingy 4 - from src.scripts.modules.gui import * 5 - 6 - class enemy_ai_component: 7 - def __init__(self, game, parent) -> None: 8 - self.game = game 9 - self.parent = parent 10 - 11 - self.state = "movement" 12 - 13 - self.parent.bullets = [] 14 - self.bullet_firerate = 15 15 - self.bullet_firerate_counter = 0 16 - 17 - self.image = self.game.image.load("enemy_bullet.png") 18 - 19 - def update(self): 20 - if self.parent.health > 0: 21 - if self.state == "movement": 22 - move_speed = 200 * self.game.delta_time 23 - self.parent.transform.x += self.game.math.lengthdir_x(move_speed, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, self.game.player.transform.x, self.game.player.transform.y)) 24 - self.parent.transform.y += self.game.math.lengthdir_y(move_speed, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, self.game.player.transform.x, self.game.player.transform.y)) 25 - if self.game.math.distance_between_points(self.parent.transform.x, self.parent.transform.y, self.game.player.transform.x, self.game.player.transform.y) < 500: 26 - self.state = "attack_start" 27 - elif self.state == "attack_start": 28 - self.target_x = self.game.player.transform.x 29 - self.target_y = self.game.player.transform.y 30 - self.state = "attack" 31 - elif self.state == "attack": 32 - if self.game.math.distance_between_points(self.parent.transform.x, self.parent.transform.y, self.game.player.transform.x, self.game.player.transform.y) > 500: 33 - self.state = "movement" 34 - self.bullet_firerate_counter += 100 * self.game.delta_time 35 - if self.bullet_firerate_counter > self.bullet_firerate: 36 - self.bullet_firerate_counter = 0 37 - self.parent.bullets.append([self.parent.transform.x, self.parent.transform.y, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, self.parent.screen.player.transform.x, self.parent.screen.player.transform.y), 300]) 38 - self.parent.bullets.append([self.parent.transform.x, self.parent.transform.y, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, self.parent.screen.player.transform.x, self.parent.screen.player.transform.y) + 90, 300]) 39 - self.parent.bullets.append([self.parent.transform.x, self.parent.transform.y, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, self.parent.screen.player.transform.x, self.parent.screen.player.transform.y) + 180, 300]) 40 - self.parent.bullets.append([self.parent.transform.x, self.parent.transform.y, self.game.math.direction_between_points(self.parent.transform.x, self.parent.transform.y, self.parent.screen.player.transform.x, self.parent.screen.player.transform.y) + 270, 300]) 41 - 42 - def render(self): 43 - move_speed = 700 * self.game.delta_time 44 - new_bullets = self.parent.bullets 45 - for i, item in enumerate(self.parent.bullets): 46 - item[3] -= 1 47 - if item[3] < 0: 48 - new_bullets.pop(i) 49 - item[0] += self.game.math.lengthdir_x(move_speed, item[2]) 50 - item[1] += self.game.math.lengthdir_y(move_speed, item[2]) 51 - image = pygame.transform.scale(self.image, (60, 60)) 52 - img, rect = self.game.math.rotate_center(image, item[2], item[0], item[1]) 53 - self.parent.screen.game_surface.blit(img, rect) 54 - self.parent.bullets = new_bullets 55 - class enemy_renderer_component: 56 - def __init__(self, game, parent) -> None: 57 - self.game = game 58 - self.parent = parent 59 - 60 - self.image = self.game.image.load("enemy.png") 61 - 62 - def update(self): 63 - pass 64 - 65 - def render(self): 66 - if self.parent.health > 0: 67 - image = pygame.transform.scale(self.image, (88, 88)) 68 - img, rect = self.game.math.rotate_center(image, 0, self.parent.transform.x, self.parent.transform.y) 69 - self.parent.screen.game_surface.blit(img, rect) 70 - 71 - class enemy_health_system: 72 - def __init__(self, game, parent) -> None: 73 - self.game = game 74 - self.parent = parent 75 - 76 - self.parent.health = 50 77 - self.cant_get_hit_by = [] 78 - 79 - self.health_bar_rect = gui_rect(game) 80 - self.health_bar_rect.set_y_constraint(percentage_constraint(0.02)) 81 - self.health_bar_rect.set_x_constraint(percentage_constraint(0.02)) 82 - self.health_bar_rect.set_width_constraint(percentage_constraint(0.3)) 83 - self.health_bar_rect.set_height_constraint(pixel_constraint(5)) 84 - self.health_bar_rect.set_border_radius(10) 85 - self.health_bar_rect.set_draw_color(self.game.color_handler.get_rgb('enemy.health_bar')) 86 - 87 - def update(self): 88 - self.health_bar_rect.tween_size(percentage_constraint(0.3 - (0.03 * ((50 - self.parent.health) / 5))), pixel_constraint(5), 24) 89 - self.health_bar_rect.update() 90 - if self.parent.health > 0: 91 - new_bullets = self.game.player.bullets 92 - for i, item in enumerate(self.game.player.bullets): 93 - if self.game.math.distance_between_points(self.parent.transform.x, self.parent.transform.y, item[0], item[1]) < 80: 94 - new_bullets.pop(i) 95 - self.parent.health -= 1 96 - self.cant_get_hit_by.append(item) 97 - self.game.player.bullets = new_bullets 98 - 99 - def render(self): 100 - self.health_bar_rect.render() 101 - 102 - class Enemy(Entity): 103 - def __init__(self, game, screen) -> None: 104 - self.game = game 105 - self.screen = screen 106 - 107 - self.components = [] 108 - 109 - self.transform = Transform() 110 - self.transform.y = 200 111 - self.add_component(enemy_health_system(game, self)) 112 - self.add_component(enemy_renderer_component(game, self)) 113 - self.add_component(enemy_ai_component(game, self))
-83
src/scripts/game/player.py
··· 1 - import pygame, math 2 - from src.scripts.modules.entity import * 3 - from .bullet import * 4 - from src.scripts.modules.gui import * 5 - 6 - class player_movement_component: 7 - def __init__(self, game, parent) -> None: 8 - self.game = game 9 - self.parent = parent 10 - 11 - def update(self): 12 - move_speed = 300 * self.game.delta_time 13 - if self.game.input.is_pressed("a") and self.parent.transform.x > 0 + 32 + move_speed: 14 - self.parent.transform.x -= move_speed 15 - if self.game.input.is_pressed("d") and self.parent.transform.x < self.parent.screen.game_surface.get_width() - move_speed - 32: 16 - self.parent.transform.x += move_speed 17 - if self.game.input.is_pressed("w") and self.parent.transform.y > 0 + 32 + move_speed: 18 - self.parent.transform.y-= move_speed 19 - if self.game.input.is_pressed("s") and self.parent.transform.y < self.parent.screen.game_surface.get_height() - move_speed - 32: 20 - self.parent.transform.y += move_speed 21 - 22 - def render(self): 23 - pass 24 - 25 - class player_renderer_component: 26 - def __init__(self, game, parent) -> None: 27 - self.game = game 28 - self.parent = parent 29 - 30 - self.image = self.game.image.load("player.png") 31 - 32 - def update(self): 33 - pass 34 - 35 - def render(self): 36 - image = pygame.transform.scale(self.image, (64, 64)) 37 - img, rect = self.game.math.rotate_center(image, 0, self.parent.transform.x, self.parent.transform.y) 38 - self.parent.screen.game_surface.blit(img, rect) 39 - 40 - class player_health_system: 41 - def __init__(self, game, parent) -> None: 42 - self.game = game 43 - self.parent = parent 44 - 45 - self.parent.health = 10 46 - self.cant_get_hit_by = [] 47 - 48 - self.health_bar_rect = gui_rect(game) 49 - self.health_bar_rect.set_y_constraint(percentage_constraint(0.02)) 50 - self.health_bar_rect.set_x_constraint(percentage_constraint(0.67)) 51 - self.health_bar_rect.set_width_constraint(percentage_constraint(0.3)) 52 - self.health_bar_rect.set_height_constraint(pixel_constraint(5)) 53 - self.health_bar_rect.set_border_radius(10) 54 - self.health_bar_rect.set_draw_color(self.game.color_handler.get_rgb('player.health_bar')) 55 - 56 - def update(self): 57 - self.health_bar_rect.tween_size(percentage_constraint(0.3 - (0.03 * (10 - self.parent.health))), pixel_constraint(5), 24) 58 - self.health_bar_rect.update() 59 - 60 - for i, item in enumerate(self.parent.screen.enemy.bullets): 61 - if self.game.math.distance_between_points(self.parent.transform.x, self.parent.transform.y, item[0], item[1]) < 60: 62 - self.parent.screen.enemy.bullets.pop(i) 63 - self.parent.health -= 1 64 - 65 - def render(self): 66 - self.health_bar_rect.render() 67 - 68 - class Player(Entity): 69 - def __init__(self, game, screen) -> None: 70 - self.game = game 71 - self.screen = screen 72 - 73 - self.game.player = self 74 - 75 - self.components = [] 76 - 77 - self.transform = Transform() 78 - self.transform.y = 500 79 - 80 - self.add_component(bullet_shooty_thingy(game, self)) 81 - self.add_component(player_health_system(game, self)) 82 - self.add_component(player_movement_component(game, self)) 83 - self.add_component(player_renderer_component(game, self))
+13 -17
src/scripts/game_manager.py
··· 10 10 from .modules.fonts import font_handler 11 11 from .modules.debug import Debug 12 12 13 - from .screens.screen_main_menu import screen_main_menu 14 - from .screens.screen_game import screen_game 15 - from .screens.screen_settings import screen_settins 16 - from .screens.screen_lose import screen_lose 17 - from .screens.screen_win import screen_win 13 + from .screens.screen_main import screen_main 18 14 from .screens.gui_test import gui_test 19 15 20 16 class Game_Manager: ··· 60 56 self.change_title(self.properties["id"]) 61 57 self.input.input_state = "general" 62 58 63 - game_screen = screen_game(self) 64 - main_menu_screen = screen_main_menu(self) 59 + main_screen = screen_main(self) 65 60 screen_gui_test = gui_test(self) 66 - settings_screen = screen_settins(self) 67 - lose_screen = screen_lose(self) 68 - win_screen = screen_win(self) 69 61 self.renderer.load_screen(screen_gui_test, 'gui_test') 70 - self.renderer.load_screen(game_screen, 'game') 71 - self.renderer.load_screen(main_menu_screen, 'main_menu') 72 - self.renderer.load_screen(settings_screen, 'settings') 73 - self.renderer.load_screen(lose_screen, 'lose') 74 - self.renderer.load_screen(win_screen, 'win') 75 - self.renderer.switch_screen('main_menu') 62 + self.renderer.load_screen(main_screen, 'main') 63 + self.renderer.switch_screen('main') 76 64 77 65 def update(self): 78 66 # Calculate Delta Time ··· 81 69 self.previous_time = now 82 70 83 71 self.input.any_key_pressed = False 72 + for i, item in enumerate(self.input.pressed_keys): 73 + self.input.pressed_keys[i] = False 74 + 75 + keys = pygame.key.get_pressed() 84 76 for event in pygame.event.get(): 85 77 if event.type == pygame.QUIT: 86 78 self.stop() 87 79 if event.type == pygame.KEYDOWN: 88 80 self.input.any_key_pressed = True 89 - 81 + for i, key in enumerate(self.input.record_keys): 82 + key_signature = 0 83 + exec("key_signature = pygame.K_" + key) 84 + self.input.pressed_keys[i] = keys[key_signature] 85 + 90 86 # Screens 91 87 self.renderer.update() 92 88
src/scripts/modules/__pycache__/colors.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__/entity.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__/renderer.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.

+4 -2
src/scripts/modules/debug.py
··· 25 25 26 26 self.fps = 0 27 27 28 + self.render_hud = False 29 + 28 30 def send_stats(self, update_time, render_time): 29 31 self.update_time = update_time * 1000 30 32 self.render_time = render_time * 1000 ··· 36 38 self.latest_readings += self.frame_ms 37 39 if self.fps_end_time - self.fps_start_time > 1: 38 40 self.fps_start_time = time.time() 39 - print(self.latest_readings) 40 41 self.latest_readings = 0 41 42 42 43 def render(self): 43 - self.debug_gui.render() 44 + if self.render_hud: 45 + self.debug_gui.render()
+17 -7
src/scripts/modules/input.py
··· 1 1 from re import L 2 - import pygame, keyboard 2 + import pygame 3 3 4 4 class Input: 5 5 6 6 input_state = "main" 7 7 8 + key_signature = False 9 + 8 10 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 11 "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", 10 12 "UP", "DOWN", "LEFT", "RIGHT", 11 - "SPACE", "CTRL", "SHIFT", "ALT", "RETURN", "ESCAPE", "TAB", "BACKSPACE", 12 - "period", "subtract", "'"] 13 + "SPACE", "LCTRL", "LSHIFT", "LALT", "RETURN", "ESCAPE", "TAB", "BACKSPACE", 14 + "PERIOD", "MINUS"] 13 15 14 16 def set_input_state(self, state): 15 17 self.input_state = state ··· 18 20 self.any_key_pressed = False 19 21 20 22 self.last_frame_keys = [] 23 + self.pressed_keys = [] 21 24 for i in self.record_keys: 25 + self.pressed_keys.append(False) 22 26 self.last_frame_keys.append(False) 23 27 24 28 self.mouse_button_last_frame = False 25 29 26 30 def is_pressed(self, key, input_state=""): 31 + keys = pygame.key.get_pressed() 32 + code = "self.key_signature = pygame.K_" + key 33 + exec(code) 27 34 if input_state != "": 28 - return bool(keyboard.is_pressed(key) and pygame.mouse.get_focused() and input_state == self.input_state) 35 + return bool(keys[self.key_signature] and pygame.mouse.get_focused() and input_state == self.input_state) 29 36 else: 30 - return bool(keyboard.is_pressed(key) and pygame.mouse.get_focused()) 37 + return bool(keys[self.key_signature] and pygame.mouse.get_focused()) 31 38 32 39 def check_keys(self): 33 40 for i, key in enumerate(self.record_keys): 34 41 self.last_frame_keys[i] = self.is_pressed(key) 35 42 36 43 def is_just_pressed(self, key, input_state=""): 44 + keys = pygame.key.get_pressed() 45 + key_signature = False 46 + exec("key_signature = pygame.K_" + key) 37 47 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) 48 + return bool(keys[key_signature] and not self.last_frame_keys[self.record_keys.index(key)] and pygame.mouse.get_focused() and input_state == self.input_state) 39 49 else: 40 - return bool(keyboard.is_pressed(key) and not self.last_frame_keys[self.record_keys.index(key)] and pygame.mouse.get_focused()) 50 + return bool(keys[key_signature] and not self.last_frame_keys[self.record_keys.index(key)] and pygame.mouse.get_focused()) 41 51 42 52 def is_any_key_pressed(self): 43 53 return self.any_key_pressed
src/scripts/screens/__pycache__/__init__.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/screens/__pycache__/gui_test.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/screens/__pycache__/screen_game.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/screens/__pycache__/screen_lose.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/screens/__pycache__/screen_main.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/screens/__pycache__/screen_main_menu.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/screens/__pycache__/screen_settings.cpython-39.pyc

This is a binary file and will not be displayed.

src/scripts/screens/__pycache__/screen_win.cpython-39.pyc

This is a binary file and will not be displayed.

-49
src/scripts/screens/screen_game.py
··· 1 - from src.scripts.modules.renderer import Screen 2 - from src.scripts.modules.gui import * 3 - import os 4 - 5 - from src.scripts.game.player import Player 6 - from src.scripts.game.enemy import Enemy 7 - 8 - class screen_game(Screen): 9 - def __init__(self, game): 10 - self.game = game 11 - 12 - self.player = Player(game, self) 13 - self.enemy = Enemy(game, self) 14 - 15 - self.game_surface = pygame.Surface((1280, 720), pygame.SRCALPHA) 16 - 17 - def update(self): 18 - self.player.update() 19 - self.enemy.update() 20 - 21 - if self.player.health < 0: 22 - self.player.health = 10 23 - self.enemy.health = 50 24 - self.game.renderer.switch_screen('lose') 25 - if self.enemy.health < 2: 26 - self.player.health = 10 27 - self.enemy.health = 50 28 - self.game.renderer.switch_screen('win') 29 - 30 - def render(self): 31 - self.game_surface = pygame.Surface((1280, 720), pygame.SRCALPHA) 32 - self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 33 - self.player.render() 34 - self.enemy.render() 35 - width_diff = abs(self.game.renderer.screen.get_width() - self.game.renderer.original_size[0]) 36 - height_diff = abs(self.game.renderer.screen.get_height() - self.game.renderer.original_size[1]) 37 - if width_diff > height_diff: 38 - aspect_ratio = self.game.renderer.screen.get_width() / self.game.renderer.original_size[0] 39 - width = self.game.renderer.screen.get_width() 40 - height = self.game.renderer.original_size[1] * aspect_ratio 41 - else: 42 - aspect_ratio = self.game.renderer.screen.get_height() / self.game.renderer.original_size[1] 43 - width = self.game.renderer.original_size[0] * aspect_ratio 44 - height = self.game.renderer.screen.get_height() 45 - 46 - mx, my = pygame.mouse.get_pos() 47 - self.game.relative_mxmy = (mx / aspect_ratio, my / aspect_ratio) 48 - 49 - self.game.renderer.screen.blit(pygame.transform.scale(self.game_surface, (int(width), int(height))), (0, 0))
-61
src/scripts/screens/screen_lose.py
··· 1 - from src.scripts.modules.renderer import Screen 2 - from src.scripts.modules.gui import * 3 - import os 4 - 5 - from src.scripts.game.player import Player 6 - from src.scripts.game.enemy import Enemy 7 - 8 - class screen_lose(Screen): 9 - def __init__(self, game): 10 - self.game = game 11 - 12 - self.play_button = gui_press_button(game) 13 - self.play_button.rect.set_x_constraint(percentage_constraint(0.03)) 14 - self.play_button.rect.set_y_constraint(percentage_constraint(0.8)) 15 - self.play_button.rect.set_width_constraint(percentage_constraint(0.3)) 16 - self.play_button.rect.set_height_constraint(percentage_constraint(0.15)) 17 - self.play_button.rect.set_border_radius(10) 18 - self.play_button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 19 - 20 - self.play_button_text = gui_text(game) 21 - self.play_button_text.parent = self.play_button.rect 22 - self.play_button_text.text = "Back" 23 - self.play_button_text.set_x_constraint(center_constraint()) 24 - self.play_button_text.set_y_constraint(center_constraint()) 25 - self.play_button_text.set_size_constraint(percentage_constraint(0.8)) 26 - self.play_button_text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 27 - 28 - self.screen = gui_rect(game) 29 - self.screen.set_x_constraint(center_constraint()) 30 - self.screen.set_y_constraint(center_constraint()) 31 - self.screen.set_width_constraint(percentage_constraint(1)) 32 - self.screen.set_height_constraint(percentage_constraint(1)) 33 - self.screen.visible = False 34 - 35 - self.text = gui_text(game) 36 - self.text.parent = self.screen 37 - self.text.text = "You lost" 38 - self.text.set_x_constraint(center_constraint()) 39 - self.text.set_y_constraint(center_constraint()) 40 - self.text.set_size_constraint(percentage_constraint(0.2)) 41 - self.text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 42 - 43 - 44 - def update(self): 45 - self.screen.update() 46 - self.play_button.update() 47 - self.play_button_text.update() 48 - self.text.update() 49 - self.play_button.rect.tween_to(percentage_constraint(0.03), percentage_constraint(0.8), 6) 50 - if self.play_button.hover: 51 - self.play_button.rect.tween_to(percentage_constraint(0.05), percentage_constraint(0.8), 6) 52 - 53 - if self.play_button.pressed: 54 - self.game.renderer.switch_screen('main_menu') 55 - 56 - def render(self): 57 - self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 58 - self.screen.render() 59 - self.play_button.render() 60 - self.play_button_text.render() 61 - self.text.render()
+13
src/scripts/screens/screen_main.py
··· 1 + from src.scripts.modules.renderer import Screen 2 + from src.scripts.modules.gui import * 3 + import os 4 + 5 + class screen_main(Screen): 6 + def __init__(self, game): 7 + self.game = game 8 + 9 + def update(self): 10 + pass 11 + 12 + def render(self): 13 + self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background'))
-102
src/scripts/screens/screen_main_menu.py
··· 1 - from src.scripts.modules.renderer import Screen 2 - from src.scripts.modules.gui import * 3 - import os 4 - 5 - class screen_main_menu(Screen): 6 - def __init__(self, game): 7 - self.game = game 8 - 9 - self.buttons_bg = gui_rect(game) 10 - self.buttons_bg.set_x_constraint(percentage_constraint(0.1)) 11 - self.buttons_bg.set_y_constraint(center_constraint()) 12 - self.buttons_bg.set_width_constraint(percentage_constraint(0.1)) 13 - self.buttons_bg.set_height_constraint(percentage_constraint(0.8)) 14 - self.buttons_bg.set_border_radius(10) 15 - self.buttons_bg.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg_2')) 16 - 17 - self.play_button = gui_press_button(game) 18 - self.play_button.rect.set_x_constraint(percentage_constraint(0.15)) 19 - self.play_button.rect.set_y_constraint(percentage_constraint(0.15)) 20 - self.play_button.rect.set_width_constraint(percentage_constraint(0.3)) 21 - self.play_button.rect.set_height_constraint(percentage_constraint(0.15)) 22 - self.play_button.rect.set_border_radius(10) 23 - self.play_button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 24 - 25 - self.play_button_text = gui_text(game) 26 - self.play_button_text.parent = self.play_button.rect 27 - self.play_button_text.text = "Play" 28 - self.play_button_text.set_x_constraint(center_constraint()) 29 - self.play_button_text.set_y_constraint(center_constraint()) 30 - self.play_button_text.set_size_constraint(percentage_constraint(0.8)) 31 - self.play_button_text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 32 - 33 - self.play_button2 = gui_press_button(game) 34 - self.play_button2.rect.set_x_constraint(percentage_constraint(0.15)) 35 - self.play_button2.rect.set_y_constraint(center_constraint()) 36 - self.play_button2.rect.set_width_constraint(percentage_constraint(0.3)) 37 - self.play_button2.rect.set_height_constraint(percentage_constraint(0.15)) 38 - self.play_button2.rect.set_border_radius(10) 39 - self.play_button2.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 40 - 41 - self.play_button2_text = gui_text(game) 42 - self.play_button2_text.parent = self.play_button2.rect 43 - self.play_button2_text.text = "Settings" 44 - self.play_button2_text.set_x_constraint(center_constraint()) 45 - self.play_button2_text.set_y_constraint(center_constraint()) 46 - self.play_button2_text.set_size_constraint(percentage_constraint(0.8)) 47 - self.play_button2_text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 48 - 49 - self.play_button3 = gui_press_button(game) 50 - self.play_button3.rect.set_x_constraint(percentage_constraint(0.15)) 51 - self.play_button3.rect.set_y_constraint(percentage_constraint(0.7)) 52 - self.play_button3.rect.set_width_constraint(percentage_constraint(0.3)) 53 - self.play_button3.rect.set_height_constraint(percentage_constraint(0.15)) 54 - self.play_button3.rect.set_border_radius(10) 55 - self.play_button3.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 56 - 57 - self.play_button3_text = gui_text(game) 58 - self.play_button3_text.parent = self.play_button3.rect 59 - self.play_button3_text.text = "Exit" 60 - self.play_button3_text.set_x_constraint(center_constraint()) 61 - self.play_button3_text.set_y_constraint(center_constraint()) 62 - self.play_button3_text.set_size_constraint(percentage_constraint(0.8)) 63 - self.play_button3_text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 64 - 65 - def update(self): 66 - self.buttons_bg.update() 67 - self.play_button.update() 68 - self.play_button2.update() 69 - self.play_button3.update() 70 - self.play_button_text.update() 71 - self.play_button2_text.update() 72 - self.play_button3_text.update() 73 - self.play_button.rect.tween_to(percentage_constraint(0.15), percentage_constraint(0.15), 6) 74 - if self.play_button.hover: 75 - self.play_button.rect.tween_to(percentage_constraint(0.175), percentage_constraint(0.15), 6) 76 - 77 - if self.play_button.pressed: 78 - self.game.renderer.switch_screen('game') 79 - 80 - self.play_button2.rect.tween_to(percentage_constraint(0.15), center_constraint(), 6) 81 - if self.play_button2.hover: 82 - self.play_button2.rect.tween_to(percentage_constraint(0.175), center_constraint(), 6) 83 - 84 - if self.play_button2.pressed: 85 - self.game.renderer.switch_screen('settings') 86 - 87 - self.play_button3.rect.tween_to(percentage_constraint(0.15), percentage_constraint(0.7), 6) 88 - if self.play_button3.hover: 89 - self.play_button3.rect.tween_to(percentage_constraint(0.175), percentage_constraint(0.7), 6) 90 - 91 - if self.play_button3.pressed: 92 - self.game.stop() 93 - 94 - def render(self): 95 - self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 96 - self.buttons_bg.render() 97 - self.play_button.render() 98 - self.play_button2.render() 99 - self.play_button3.render() 100 - self.play_button_text.render() 101 - self.play_button2_text.render() 102 - self.play_button3_text.render()
-41
src/scripts/screens/screen_settings.py
··· 1 - from src.scripts.modules.renderer import Screen 2 - from src.scripts.modules.gui import * 3 - import os 4 - 5 - from src.scripts.game.player import Player 6 - from src.scripts.game.enemy import Enemy 7 - 8 - class screen_settins(Screen): 9 - def __init__(self, game): 10 - self.game = game 11 - 12 - self.play_button = gui_press_button(game) 13 - self.play_button.rect.set_x_constraint(percentage_constraint(0.03)) 14 - self.play_button.rect.set_y_constraint(percentage_constraint(0.8)) 15 - self.play_button.rect.set_width_constraint(percentage_constraint(0.3)) 16 - self.play_button.rect.set_height_constraint(percentage_constraint(0.15)) 17 - self.play_button.rect.set_border_radius(10) 18 - self.play_button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 19 - 20 - self.play_button_text = gui_text(game) 21 - self.play_button_text.parent = self.play_button.rect 22 - self.play_button_text.text = "Back" 23 - self.play_button_text.set_x_constraint(center_constraint()) 24 - self.play_button_text.set_y_constraint(center_constraint()) 25 - self.play_button_text.set_size_constraint(percentage_constraint(0.8)) 26 - self.play_button_text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 27 - 28 - def update(self): 29 - self.play_button.update() 30 - self.play_button_text.update() 31 - self.play_button.rect.tween_to(percentage_constraint(0.03), percentage_constraint(0.8), 6) 32 - if self.play_button.hover: 33 - self.play_button.rect.tween_to(percentage_constraint(0.05), percentage_constraint(0.8), 6) 34 - 35 - if self.play_button.pressed: 36 - self.game.renderer.switch_screen('main_menu') 37 - 38 - def render(self): 39 - self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 40 - self.play_button.render() 41 - self.play_button_text.render()
-61
src/scripts/screens/screen_win.py
··· 1 - from src.scripts.modules.renderer import Screen 2 - from src.scripts.modules.gui import * 3 - import os 4 - 5 - from src.scripts.game.player import Player 6 - from src.scripts.game.enemy import Enemy 7 - 8 - class screen_win(Screen): 9 - def __init__(self, game): 10 - self.game = game 11 - 12 - self.play_button = gui_press_button(game) 13 - self.play_button.rect.set_x_constraint(percentage_constraint(0.03)) 14 - self.play_button.rect.set_y_constraint(percentage_constraint(0.8)) 15 - self.play_button.rect.set_width_constraint(percentage_constraint(0.3)) 16 - self.play_button.rect.set_height_constraint(percentage_constraint(0.15)) 17 - self.play_button.rect.set_border_radius(10) 18 - self.play_button.rect.set_draw_color(self.game.color_handler.get_rgb('main_menu.bright_bg')) 19 - 20 - self.play_button_text = gui_text(game) 21 - self.play_button_text.parent = self.play_button.rect 22 - self.play_button_text.text = "Back" 23 - self.play_button_text.set_x_constraint(center_constraint()) 24 - self.play_button_text.set_y_constraint(center_constraint()) 25 - self.play_button_text.set_size_constraint(percentage_constraint(0.8)) 26 - self.play_button_text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 27 - 28 - self.screen = gui_rect(game) 29 - self.screen.set_x_constraint(center_constraint()) 30 - self.screen.set_y_constraint(center_constraint()) 31 - self.screen.set_width_constraint(percentage_constraint(1)) 32 - self.screen.set_height_constraint(percentage_constraint(1)) 33 - self.screen.visible = False 34 - 35 - self.text = gui_text(game) 36 - self.text.parent = self.screen 37 - self.text.text = "You won" 38 - self.text.set_x_constraint(center_constraint()) 39 - self.text.set_y_constraint(center_constraint()) 40 - self.text.set_size_constraint(percentage_constraint(0.2)) 41 - self.text.set_color(self.game.color_handler.get_rgb('main_menu.text')) 42 - 43 - 44 - def update(self): 45 - self.screen.update() 46 - self.play_button.update() 47 - self.play_button_text.update() 48 - self.text.update() 49 - self.play_button.rect.tween_to(percentage_constraint(0.03), percentage_constraint(0.8), 6) 50 - if self.play_button.hover: 51 - self.play_button.rect.tween_to(percentage_constraint(0.05), percentage_constraint(0.8), 6) 52 - 53 - if self.play_button.pressed: 54 - self.game.renderer.switch_screen('main_menu') 55 - 56 - def render(self): 57 - self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 58 - self.screen.render() 59 - self.play_button.render() 60 - self.play_button_text.render() 61 - self.text.render()