camera
Implementation of the game's camera
Camera Objects
class Camera()
Class to draw different camera angles
__init__
| __init__(cx, cy, mode='default')
Initializes the game camera
The game camera has 3 modes:
- default: Follows the ball while showing surrounding players
- zoomed: Follows the ball closely
- full: Displays the entire field
Attributes:
cx
float - Camera's x coordinatecy
float - Camera's y coordinatemode
str - The camera mode
params
| @property
| params()
Helper method to reduce code redundancy
set_mode
| set_mode(mode)
Set the camera's mode. Mode must be one of ['full', 'default', 'zoomed']
move
| move(bx, by, alpha=P(0.9,0.9))
Move the camera to the given coordinates (Camera can't go over the field boundary)
Uses exponential smoothing to minimize jittering
pt
| pt(p)
Transform any 2-D point with respect to the camera
rect_in_view
| rect_in_view(r1)
Check if given rectangle is within the camera's view
circle_in_view
| circle_in_view(x, y, rad)
Check if given circle is within the camera's view
rect
| rect(win, col, coords, width=0)
Draw a rectangle according to the cameras mode (attributes are same as pygame.draw.rect
)
circle
| circle(win, col, p, r, width=0)
Draw a circle according to the cameras mode (attributes are same as pygame.draw.cirlce
)
polygon
| polygon(win, col, pts)
Draw a polygon according to the cameras mode (attributes are same as pygame.draw.polygon
)
blit
| blit(win, path, pt, size)
Blit a given sprite to the surface according to the cameras mode
Attributes:
win
pygame.Window - window for drawingpath
pygame.Image - path to the spritept
P - center of the spritesize
P - size of the sprite