AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/pygame-modular-project-structure" ~/.claude/skills/ecnu-icalk-autoskill-pygame-modular-project-structure && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/pygame-modular-project-structure/SKILL.mdsource content
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
class).Game - 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
, andmenu.py
.main.py
: Must define global constants, specifically screen dimensions (settings.py
,SCREEN_WIDTH
) and color tuples (e.g.,SCREEN_HEIGHT
,BLACK
,WHITE
).YELLOW
: Must encapsulate the core game loop and logic within agame.py
class.Game- The
method must accept the__init__
object and initialize game state variables (positions, scores, fonts).screen - The
method must contain the mainrun
loop.while running: - All helper functions (e.g.,
,draw_scores
,move_towards
) must be defined as instance methods (usingdraw_player_light
as the first parameter) to ensure they are accessible within theself
method and can access instance attributes.run
- The
: Must handle the user interface and state management, typically encapsulated in amenu.py
class. It should handle drawing text, buttons, and switching between states (e.g., main menu, options).Menu
: Must serve as the entry point. It must initialize Pygame (main.py
), set the display mode using constants frompygame.init()
, and instantiate thesettings
orMenu
class to start the application.Game- Integration: When refactoring existing monolithic code, move the game loop logic into the
class methods, ensuring all global variables become instance attributes (e.g.,Game
).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
class file if they need access to instance state; they must be methods.Game - Do not hardcode screen dimensions or colors in
orgame.py
; import them frommenu.py
.settings.py
Interaction Workflow
- Analyze the user's existing code (if any) to identify game logic, constants, and UI elements.
- Generate the content for
first.settings.py - Generate the
class inGame
, ensuring all logic is encapsulated and methods usegame.py
.self - Generate the
class inMenu
to handle the start screen and navigation.menu.py - Generate
to tie everything together.main.py - 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