My Pygame Game Engine

can deese nutz fit in you mouth

WillM 0e64a13b 1ec3e2b8

Changed files
+79 -3
.vscode
src
resources
main
assets
images
scripts
+3
.vscode/settings.json
···
··· 1 + { 2 + "python.pythonPath": "C:\\Users\\wille\\AppData\\Local\\Programs\\Python\\Python39\\python.exe" 3 + }
src/resources/main/assets/images/error.png

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__/player.cpython-39.pyc

This is a binary file and will not be displayed.

+14
src/scripts/game/player.py
···
··· 1 + from src.scripts.modules.entity import * 2 + 3 + class player(Entity): 4 + def __init__(self, game) -> None: 5 + 6 + self.game = game 7 + 8 + self.components = [] 9 + self.transform = Transform() 10 + 11 + self.add_component(Camera_Relative_Component(game, self)) 12 + self.add_component(Sprite_Renderer_Component(game, self)) 13 + self.get_component(Sprite_Renderer_Component).sprite = self.game.image.load('error.png') 14 + self.get_component(Sprite_Renderer_Component).surface = self.game.renderer.main_surface
+3 -1
src/scripts/game_manager.py
··· 19 # Screens 20 21 from .screens.engine_main_screen import engine_main_screen 22 23 ## Game Manager Class 24 ··· 81 self.input.input_state = "general" 82 83 self.renderer.load_screen(engine_main_screen(self), "engine_main") 84 - self.renderer.switch_screen("engine_main") 85 86 ## Main Update Method 87
··· 19 # Screens 20 21 from .screens.engine_main_screen import engine_main_screen 22 + from .screens.game_screen import game_screen 23 24 ## Game Manager Class 25 ··· 82 self.input.input_state = "general" 83 84 self.renderer.load_screen(engine_main_screen(self), "engine_main") 85 + self.renderer.load_screen(game_screen(self), "game_screen") 86 + self.renderer.switch_screen("game_screen") 87 88 ## Main Update Method 89
src/scripts/modules/__pycache__/entity.cpython-39.pyc

This is a binary file and will not be displayed.

+40 -2
src/scripts/modules/entity.py
··· 18 ## Remove component from entity 19 20 def remove_component(self, component): 21 - if component not in self.components: 22 self.components.remove(self.components.index(component)) 23 24 ## Use the update method in all the components 25 26 def update(self): ··· 47 self.parent.camera_relative_y = self.parent.transform.y - self.game.renderer.camera.y 48 49 def render(self): 50 - pass
··· 18 ## Remove component from entity 19 20 def remove_component(self, component): 21 + if component in self.components: 22 self.components.remove(self.components.index(component)) 23 24 + ## Get component 25 + 26 + def get_component(self, component): 27 + yes = False 28 + for index, item in enumerate(self.components): 29 + if type(item) == component: 30 + yes = True 31 + num = index 32 + break 33 + 34 + if yes == True: 35 + return self.components[num] 36 + 37 + ## Contains Component 38 + 39 + def contains_component(self, component): 40 + if component in self.components: 41 + return True 42 + return False 43 + 44 ## Use the update method in all the components 45 46 def update(self): ··· 67 self.parent.camera_relative_y = self.parent.transform.y - self.game.renderer.camera.y 68 69 def render(self): 70 + pass 71 + 72 + class Sprite_Renderer_Component(): 73 + def __init__(self, game, parent) -> None: 74 + self.game = game 75 + self.parent = parent 76 + 77 + self.surface = None 78 + self.sprite = None 79 + 80 + def update(self): 81 + pass 82 + 83 + def render(self): 84 + if self.sprite != None and self.surface != None: 85 + if self.parent.contains_component(Camera_Relative_Component(self.game, self.parent)): 86 + self.surface.blit(self.sprite, (self.parent.camera_relative_x, self.parent.camera_relative_y)) 87 + else: 88 + self.surface.blit(self.sprite, (self.parent.transform.x, self.parent.transform.y))
src/scripts/screens/__pycache__/game_screen.cpython-39.pyc

This is a binary file and will not be displayed.

+19
src/scripts/screens/game_screen.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 + 7 + class game_screen(Screen): 8 + def __init__(self, game): 9 + self.game = game 10 + 11 + self.player = player(game) 12 + 13 + def update(self): 14 + self.player.update() 15 + 16 + def render(self): 17 + self.game.renderer.main_surface.fill((0, 0, 0)) 18 + 19 + self.player.render()