Added a .gitignore file, which prevents __pycache__ from being tracked by git (these files shouldn't be tracked)
Ran a linter and code-formatter (ruff) and applied some of its fixes
Prior to this, vectors were stored as float-lists of length 2 (and sometimes 2-tuples of type (float, float)). After a brief numpy-identity-crisis, most vectors now have type pygame.math.Vector2, an adequate type supporting many standard operations.
As a consequence, the calc.py module had a brief identity-crisis into vec.py, and is now gone entirely, which is for the better.
Replaced code of many functions with pygame.math.Vector2-operations, rather than manipulating individual vector-components. This should yield a performance-boost, but more importantly, easier code.
The bug mentioned in working_on.md, about planets not being drawn when no Asteroids are present, is now fixed. Originally, the planets were drawn in the update-function of the Asteroid()-class. Now, they're drawn in their respective part of the main-loop. This should also net a slight performance boost, since every planet is drawn exactly once, rather than number-of-asteroids many times.
Added type-hints to nearly all methods (some can't be type-hinted without significantly restructuring the code, see below)
Many changes I'd still like to see are now in the source-code as # TODO: comments, you can find them all by running git grep "TODO" from the terminal. Many many more changes came to my mind while coding, but I remember only a subset:
At some point, several classes should become subclasses of some superclass. For example, Bullet and Rocket should become subclasses of some Projectile superclass. Asteroid and Planet might be subclasses of some CelestialBody superclass. And maybe CelestialBody and Ship are subclasses of some superclass, too.
I think performance can be improved a lot by replacing comparisons of magnitudes with comparisons of squared magnitudes. There is some code-TODO about that.
Replace as much as possible with pygame.math.Vector2-operations. In particular, we should almost never have to access components of a vector.
I only took a look at a fraction of the code (mostly chasing down type-hinting-errors and replacing pygame.math.Vector2 things), and would like to review the rest at some point.
Changes:
.gitignore
file, which prevents__pycache__
from being tracked by git (these files shouldn't be tracked)(float, float)
). After a brief numpy-identity-crisis, most vectors now have typepygame.math.Vector2
, an adequate type supporting many standard operations.calc.py
module had a brief identity-crisis intovec.py
, and is now gone entirely, which is for the better.pygame.math.Vector2
-operations, rather than manipulating individual vector-components. This should yield a performance-boost, but more importantly, easier code.working_on.md
, about planets not being drawn when no Asteroids are present, is now fixed. Originally, the planets were drawn in the update-function of the Asteroid()-class. Now, they're drawn in their respective part of the main-loop. This should also net a slight performance boost, since every planet is drawn exactly once, rather than number-of-asteroids many times.Many changes I'd still like to see are now in the source-code as
# TODO:
comments, you can find them all by runninggit grep "TODO"
from the terminal. Many many more changes came to my mind while coding, but I remember only a subset:Bullet
andRocket
should become subclasses of someProjectile
superclass.Asteroid
andPlanet
might be subclasses of someCelestialBody
superclass. And maybeCelestialBody
andShip
are subclasses of some superclass, too.pygame.math.Vector2-operations
. In particular, we should almost never have to access components of a vector.pygame.math.Vector2
things), and would like to review the rest at some point.