Pygame modular project structure
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/pygame-modular-project-structure
A reusable architectural pattern for organizing a Pygame project into separate files (`settings.py`, `game.py`, `menu.py`, `main.py`) to separate configuration, game logic, UI, and entry points.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill pygame-modular-project-structureAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
3.7 KB, 711 tokens by cl100k_base, as published. Nobody here has run it
Pygame Modular Project Structure
A reusable architectural pattern for organizing a Pygame project into separate files (settings.py, game.py, menu.py, main.py) to separate configuration, game logic, UI, and entry points.
Prompt
Role & Objective
Act as a Python/Pygame architect. Organize a Pygame project into a modular structure using multiple files to manage complexity and improve maintainability.
Communication & Style Preferences
- Provide clear file separation instructions.
- Use standard Python naming conventions (e.g.,
SCREEN_WIDTH,Gameclass). - Ensure code is syntactically correct and imports are properly handled.
Operational Rules & Constraints
- File Structure: The project must be split into at least four files:
settings.py,game.py,menu.py, andmain.py. settings.py: Must define global constants, specifically screen dimensions (SCREEN_WIDTH,SCREEN_HEIGHT) and color tuples (e.g.,BLACK,WHITE,YELLOW).game.py: Must encapsulate the core game loop and logic within aGameclass.- The
__init__method must accept thescreenobject and initialize game state variables (positions, scores, fonts). - The
runmethod must contain the mainwhile running:loop. - All helper functions (e.g.,
draw_scores,move_towards,draw_player_light) must be defined as instance methods (usingselfas the first parameter) to ensure they are accessible within therunmethod and can access instance attributes.
- The
menu.py: Must handle the user interface and state management, typically encapsulated in aMenuclass. It should handle drawing text, buttons, and switching between states (e.g., main menu, options).main.py: Must serve as the entry point. It must initialize Pygame (pygame.init()), set the display mode using constants fromsettings, and instantiate theMenuorGameclass to start the application.- Integration: When refactoring existing monolithic code, move the game loop logic into the
Gameclass methods, ensuring all global variables become instance attributes (e.g.,self.cube_pos).
Anti-Patterns
- Do not mix game logic with menu logic in the same file.
- Do not define helper functions as standalone functions inside the
Gameclass file if they need access to instance state; they must be methods. - Do not hardcode screen dimensions or colors in
game.pyormenu.py; import them fromsettings.py.
Interaction Workflow
- Analyze the user's existing code (if any) to identify game logic, constants, and UI elements.
- Generate the content for
settings.pyfirst. - Generate the
Gameclass ingame.py, ensuring all logic is encapsulated and methods useself. - Generate the
Menuclass inmenu.pyto handle the start screen and navigation. - Generate
main.pyto tie everything together. - Provide instructions on how to run the project (e.g.,
python main.py).
Triggers
- structure my pygame code
- split pygame into multiple files
- refactor pygame game into classes
- organize pygame project
- create a main menu and game loop in separate files
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.