Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 2.11 KB

File metadata and controls

34 lines (27 loc) · 2.11 KB

Changes Summary

Here is a simple explanation of how I reorganized the Smart Asteroids codebase to make it cleaner and easier to manage.

1. Organized Files into Folders

The project files were originally all mixed together in one place. I moved them into dedicated folders based on what they do:

  • src/: This folder now contains all the actual Python code (logic).
    • entities/: Things that exist in the game world, like rocket.py, asteroid.py, and bullet.py.
    • core/: The main game logic, like game.py (the game loop) and game_states.py.
    • ui/: User interface stuff, specifically main_menu.py.
    • utils/: Helper tools, like constants.py and the neural_network.py.
    • main.py: The internal entry point for the source code.
  • assets/: This folder holds all the non-code files.
    • images/: Pictures like rocket2.png and asteroid.png.
    • fonts/: Text fonts like ARCADECLASSIC.TTF.
    • themes/: JSON files that control the look of the menus.

2. Cleaner Entry Point

I created a new main.py file in the main folder (root) of the project.

  • Before: You had to run the game using one of the mixed files, and imports were messy.
  • After: You just run python main.py. It's a simple "start button" for the code inside src/.

3. Fixed Imports and Paths

  • Imports: I updated all the code so files know where to find each other in the new folders (e.g., import rocket became import src.entities.rocket).
  • Asset Paths: I added a helper function to automatically find pictures and fonts, no matter where you run the game from. This prevents "File Not Found" errors.

4. Fixed Bugs

  • Dependency Conflict: The project was using conflicting versions of pygame. I switched to pygame-ce which works better with the UI library used.
  • Crash Fix: I fixed a math error in the neural network code that was causing the game to crash immediately.

How to Run It Now

  1. Make sure you are in the project folder.
  2. Run python main.py (or use the virtual environment if you set one up).