-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpower_meter.py
42 lines (34 loc) · 1.21 KB
/
power_meter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from cannon import Cannon
import pygame
class PowerMeter:
"""Power meter object to show the current power setting of the cannon"""
def __init__(
self, x: int, y: int, font: str, font_size: int, cannon: Cannon
) -> None:
"""Constructor
Args:
x (int): The x position in pixels
y (int): The y position in pixels
font (str): The name of the desired font
font_size (int): The font size in pixels
cannon (Cannon): Cannon object to read power from
"""
self.x = x
self.y = y
self.font = pygame.font.SysFont(font, font_size)
self.cannon = cannon
def update(self, time_step: float) -> None:
"""Empty update function. Must be here because it is a game object
Args:
time_step (float): Time since last frame
"""
pass
def render(self, window: pygame.display) -> None:
"""Renders the power meter
Args:
window (pygame.display): The window to blit the text to
"""
text = self.font.render(
str(self.cannon.power / 10), 1, pygame.Color(255, 255, 255)
)
window.blit(text, (self.x, self.y))