movingRect
Creates a rectangular object that moves around the screen and bounces off edges.Constructor
Parameters
The pygame surface to which the rect will draw itself
The initial position of the rectangle
The width and height of the rectangle
RGB color tuple for the rectangle
The velocity vector (x, y) determining movement per frame
Gravity parameter (currently unused in implementation)
Usage Example
game.py
Collision Behavior
The rectangle automatically reverses direction when hitting screen boundaries:widgets.py
The collision check considers the full size of the rectangle, so it bounces when any edge touches the boundary.
movingImg
Creates an image that moves around the screen with boundary collision detection.Constructor
Parameters
The pygame surface to which the image will draw itself
Path to the image file to load
The initial position of the image
The velocity vector (x, y) determining movement per frame
Gravity parameter (currently unused in implementation)
Usage Example
game.py
Collision Behavior
Identical to movingRect - the image bounces off screen edges:widgets.py
circles
Creates a simple circular shape that can be drawn on the screen.Constructor
Parameters
The pygame surface to which the circle will draw itself
The center position of the circle
The radius of the circle in pixels
RGB color tuple for the circle
Usage Example
game.py
Drawing
The circle is drawn using pygame’s circle drawing function:widgets.py
Unlike movingRect and movingImg, the circles widget does not have built-in movement or collision detection. It’s described in the source as a “simple useless circle” for static display.
Common Patterns
Adding to World List
Moving objects are typically added to a world list for batch rendering:game.py
Movement Patterns
- Horizontal movement:
speed=vec2d(5, 0) - Vertical movement:
speed=vec2d(0, 5) - Diagonal movement:
speed=vec2d(3, 3) - Stationary:
speed=vec2d(0, 0)
Automatic Updates
Both movingRect and movingImg update their position automatically in theirdraw() method:
widgets.py