MCPcopy Create free account
hub / github.com/AdaCompNUS/summit / HUD

Class HUD

PythonAPI/examples/no_rendering_mode.py:260–377  ·  view source on GitHub ↗

Class encharged of rendering the HUD that displays information about the world and the hero vehicle

Source from the content-addressed store, hash-verified

258
259
260class HUD (object):
261 """Class encharged of rendering the HUD that displays information about the world and the hero vehicle"""
262
263 def __init__(self, name, width, height):
264 """Initializes default HUD params and content data parameters that will be displayed"""
265 self.name = name
266 self.dim = (width, height)
267 self._init_hud_params()
268 self._init_data_params()
269
270 def start(self):
271 """Does nothing since it does not need to use other modules"""
272
273 def _init_hud_params(self):
274 """Initialized visual parameters such as font text and size"""
275 font_name = 'courier' if os.name == 'nt' else 'mono'
276 fonts = [x for x in pygame.font.get_fonts() if font_name in x]
277 default_font = 'ubuntumono'
278 mono = default_font if default_font in fonts else fonts[0]
279 mono = pygame.font.match_font(mono)
280 self._font_mono = pygame.font.Font(mono, 14)
281 self._header_font = pygame.font.SysFont('Arial', 14, True)
282 self.help = HelpText(pygame.font.Font(mono, 24), *self.dim)
283 self._notifications = FadingText(
284 pygame.font.Font(pygame.font.get_default_font(), 20),
285 (self.dim[0], 40), (0, self.dim[1] - 40))
286
287 def _init_data_params(self):
288 """Initializes the content data structures"""
289 self.show_info = True
290 self.show_actor_ids = False
291 self._info_text = {}
292
293 def notification(self, text, seconds=2.0):
294 """Shows fading texts for some specified seconds"""
295 self._notifications.set_text(text, seconds=seconds)
296
297 def tick(self, clock):
298 """Updated the fading texts each frame"""
299 self._notifications.tick(clock)
300
301 def add_info(self, title, info):
302 """Adds a block of information in the left HUD panel of the visualizer"""
303 self._info_text[title] = info
304
305 def render_vehicles_ids(self, vehicle_id_surface, list_actors, world_to_pixel, hero_actor, hero_transform):
306 """When flag enabled, it shows the IDs of the vehicles that are spawned in the world. Depending on the vehicle type,
307 it will render it in different colors"""
308
309 vehicle_id_surface.fill(COLOR_BLACK)
310 if self.show_actor_ids:
311 vehicle_id_surface.set_alpha(150)
312 for actor in list_actors:
313 x, y = world_to_pixel(actor[1].location)
314
315 angle = 0
316 if hero_actor is not None:
317 angle = -hero_transform.rotation.yaw - 90

Callers 1

game_loopFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected