My Pygame Game Engine

asd

WillM 2a65ea81 81feeae7

Changed files
+60 -53
src
scripts
game
modules
screens
src/scripts/game/__pycache__/player.cpython-39.pyc

This is a binary file and will not be displayed.

-49
src/scripts/game/player.py
··· 1 - import pygame 2 - from src.scripts.modules.entity import * 3 - 4 - class player_movement_component: 5 - def __init__(self, game, parent) -> None: 6 - self.game = game 7 - self.parent = parent 8 - 9 - 10 - def update(self): 11 - move_speed = 350 * self.game.delta_time 12 - if self.game.input.is_pressed('w'): 13 - self.parent.transform.y -= move_speed 14 - if self.game.input.is_pressed('s'): 15 - self.parent.transform.y += move_speed 16 - if self.game.input.is_pressed('a'): 17 - self.parent.transform.x -= move_speed 18 - if self.game.input.is_pressed('d'): 19 - self.parent.transform.x += move_speed 20 - 21 - def render(self): 22 - pass 23 - 24 - class player_renderer_component: 25 - def __init__(self, game, parent) -> None: 26 - self.game = game 27 - self.parent = parent 28 - 29 - 30 - def update(self): 31 - pass 32 - 33 - def render(self): 34 - pygame.draw.rect(self.game.renderer.screen, (255, 255, 255), ((self.parent.transform.x, self.parent.transform.y), (50, 50))) 35 - 36 - class player(Entity): 37 - def __init__(self, game, screen) -> None: 38 - self.game = game 39 - self.screen = screen 40 - 41 - self.components = [] 42 - self.game.player = self 43 - 44 - self.transform = Transform() 45 - self.transform.y = 500 46 - 47 - self.add_component(player_movement_component(game, self)) 48 - self.add_component(player_renderer_component(game, self)) 49 -
src/scripts/modules/__pycache__/gui.cpython-39.pyc

This is a binary file and will not be displayed.

+13
src/scripts/modules/gui.py
··· 46 46 tween_height = 0 47 47 tween_s_mult = 0 48 48 49 + tween_c = False 50 + tween_color_rgb = (0, 0, 0) 51 + 49 52 tmp_width = 0 50 53 tmp_height = 0 51 54 ··· 107 110 self.tween_width = width 108 111 self.tween_height = height 109 112 self.tween_s_mult = mult 113 + 114 + def tween_color(self, colorrgb, mult): 115 + self.tween_c = True 116 + self.tween_color_rgb = colorrgb 117 + self.tween_color_mult = mult 110 118 111 119 def __init__(self, game) -> None: 112 120 self.game = game ··· 276 284 277 285 self.width += (self.tmp_width - self.width) / self.tween_s_mult 278 286 self.height += (self.tmp_height - self.height) / self.tween_s_mult 287 + 288 + if self.tween_c: 289 + self.color = (self.color[0] + (self.tween_color_rgb[0] - self.color[0]) / self.tween_color_mult, 290 + self.color[1] + (self.tween_color_rgb[1] - self.color[1]) / self.tween_color_mult, 291 + self.color[2] + (self.tween_color_rgb[2] - self.color[2]) / self.tween_color_mult) 279 292 280 293 def render(self): 281 294 if self.visible:
src/scripts/screens/__pycache__/screen_main.cpython-39.pyc

This is a binary file and will not be displayed.

+47 -4
src/scripts/screens/screen_main.py
··· 1 1 from src.scripts.modules.renderer import Screen 2 2 from src.scripts.modules.gui import * 3 - from src.scripts.game.player import player 4 3 import os 5 4 6 5 class screen_main(Screen): 7 6 def __init__(self, game): 8 7 self.game = game 9 8 10 - self.Player = player(game, self) 9 + self.rect1 = gui_rect(game) 10 + self.rect1.set_x_constraint(percentage_constraint(0.1)) 11 + self.rect1.set_y_constraint(percentage_constraint(0.9)) 12 + self.rect1.set_height_constraint(aspect_constraint(1)) 13 + self.rect1.set_width_constraint(percentage_constraint(0.05)) 14 + 15 + self.rect2 = gui_rect(game) 16 + self.rect2.set_x_constraint(percentage_constraint(0.17)) 17 + self.rect2.set_y_constraint(percentage_constraint(0.9)) 18 + self.rect2.set_height_constraint(aspect_constraint(1)) 19 + self.rect2.set_width_constraint(percentage_constraint(0.05)) 20 + 21 + self.rect3 = gui_rect(game) 22 + self.rect3.set_x_constraint(percentage_constraint(0.25)) 23 + self.rect3.set_y_constraint(percentage_constraint(0.9)) 24 + self.rect3.set_height_constraint(aspect_constraint(1)) 25 + self.rect3.set_width_constraint(percentage_constraint(0.05)) 26 + 27 + self.rect4 = gui_rect(game) 28 + self.rect4.set_x_constraint(percentage_constraint(0.32)) 29 + self.rect4.set_y_constraint(percentage_constraint(0.9)) 30 + self.rect4.set_height_constraint(aspect_constraint(1)) 31 + self.rect4.set_width_constraint(percentage_constraint(0.05)) 11 32 12 33 def update(self): 13 - self.Player.update() 34 + self.rect1.tween_color((20, 20, 20), 24) 35 + self.rect2.tween_color((20, 20, 20), 24) 36 + self.rect3.tween_color((20, 20, 20), 24) 37 + self.rect4.tween_color((20, 20, 20), 24) 38 + if self.game.input.is_pressed('d'): 39 + self.rect1.tween_color((255, 255, 255), 4) 40 + 41 + if self.game.input.is_pressed('f'): 42 + self.rect2.tween_color((255, 255, 255), 4) 43 + 44 + if self.game.input.is_pressed('j'): 45 + self.rect3.tween_color((255, 255, 255), 4) 46 + 47 + if self.game.input.is_pressed('k'): 48 + self.rect4.tween_color((255, 255, 255), 4) 49 + 50 + self.rect1.update() 51 + self.rect2.update() 52 + self.rect3.update() 53 + self.rect4.update() 14 54 15 55 def render(self): 16 56 self.game.renderer.screen.fill(self.game.color_handler.get_rgb('main_menu.background')) 17 - self.Player.render() 57 + self.rect1.render() 58 + self.rect2.render() 59 + self.rect3.render() 60 + self.rect4.render()