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

Method _parse_events

PythonAPI/examples/no_rendering_mode.py:1401–1457  ·  view source on GitHub ↗

Parses input events. These events are executed only once when pressing a key.

(self)

Source from the content-addressed store, hash-verified

1399 self.parse_input(clock)
1400
1401 def _parse_events(self):
1402 """Parses input events. These events are executed only once when pressing a key."""
1403 self.mouse_pos = pygame.mouse.get_pos()
1404 for event in pygame.event.get():
1405 if event.type == pygame.QUIT:
1406 exit_game()
1407 elif event.type == pygame.KEYUP:
1408 if self._is_quit_shortcut(event.key):
1409 exit_game()
1410 elif event.key == K_h or (event.key == K_SLASH and pygame.key.get_mods() & KMOD_SHIFT):
1411 self._hud.help.toggle()
1412 elif event.key == K_TAB:
1413 # Toggle between hero and map mode
1414 if self._world.hero_actor is None:
1415 self._world.select_hero_actor()
1416 self.wheel_offset = HERO_DEFAULT_SCALE
1417 self.control = carla.VehicleControl()
1418 self._hud.notification('Hero Mode')
1419 else:
1420 self.wheel_offset = MAP_DEFAULT_SCALE
1421 self.mouse_offset = [0, 0]
1422 self.mouse_pos = [0, 0]
1423 self._world.scale_offset = [0, 0]
1424 self._world.hero_actor = None
1425 self._hud.notification('Map Mode')
1426 elif event.key == K_F1:
1427 self._hud.show_info = not self._hud.show_info
1428 elif event.key == K_i:
1429 self._hud.show_actor_ids = not self._hud.show_actor_ids
1430 elif isinstance(self.control, carla.VehicleControl):
1431 if event.key == K_q:
1432 self.control.gear = 1 if self.control.reverse else -1
1433 elif event.key == K_m:
1434 self.control.manual_gear_shift = not self.control.manual_gear_shift
1435 self.control.gear = self._world.hero_actor.get_control().gear
1436 self._hud.notification('%s Transmission' % (
1437 'Manual' if self.control.manual_gear_shift else 'Automatic'))
1438 elif self.control.manual_gear_shift and event.key == K_COMMA:
1439 self.control.gear = max(-1, self.control.gear - 1)
1440 elif self.control.manual_gear_shift and event.key == K_PERIOD:
1441 self.control.gear = self.control.gear + 1
1442 elif event.key == K_p:
1443 # Toggle autopilot
1444 if self._world.hero_actor is not None:
1445 self._autopilot_enabled = not self._autopilot_enabled
1446 self._world.hero_actor.set_autopilot(self._autopilot_enabled)
1447 self._hud.notification('Autopilot %s' % ('On' if self._autopilot_enabled else 'Off'))
1448 elif event.type == pygame.MOUSEBUTTONDOWN:
1449 # Handle mouse wheel for zooming in and out
1450 if event.button == 4:
1451 self.wheel_offset += self.wheel_amount
1452 if self.wheel_offset >= 1.0:
1453 self.wheel_offset = 1.0
1454 elif event.button == 5:
1455 self.wheel_offset -= self.wheel_amount
1456 if self.wheel_offset <= 0.1:
1457 self.wheel_offset = 0.1
1458

Callers 1

parse_inputMethod · 0.95

Calls 7

_is_quit_shortcutMethod · 0.95
exit_gameFunction · 0.85
select_hero_actorMethod · 0.80
VehicleControlMethod · 0.80
getMethod · 0.45
toggleMethod · 0.45
notificationMethod · 0.45

Tested by

no test coverage detected