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

Function game_loop

PythonAPI/examples/no_rendering_mode.py:1505–1556  ·  view source on GitHub ↗

Initialized, Starts and runs all the needed modules for No Rendering Mode

(args)

Source from the content-addressed store, hash-verified

1503
1504
1505def game_loop(args):
1506 """Initialized, Starts and runs all the needed modules for No Rendering Mode"""
1507 try:
1508 # Init Pygame
1509 pygame.init()
1510 display = pygame.display.set_mode(
1511 (args.width, args.height),
1512 pygame.HWSURFACE | pygame.DOUBLEBUF)
1513
1514 # Place a title to game window
1515 pygame.display.set_caption(args.description)
1516
1517 # Show loading screen
1518 font = pygame.font.Font(pygame.font.get_default_font(), 20)
1519 text_surface = font.render('Rendering map...', True, COLOR_WHITE)
1520 display.blit(text_surface, text_surface.get_rect(center=(args.width / 2, args.height / 2)))
1521 pygame.display.flip()
1522
1523 # Init
1524 input_control = InputControl(TITLE_INPUT)
1525 hud = HUD(TITLE_HUD, args.width, args.height)
1526 world = World(TITLE_WORLD, args, timeout=2.0)
1527
1528 # For each module, assign other modules that are going to be used inside that module
1529 input_control.start(hud, world)
1530 hud.start()
1531 world.start(hud, input_control)
1532
1533 # Game loop
1534 clock = pygame.time.Clock()
1535 while True:
1536 clock.tick_busy_loop(60)
1537
1538 # Tick all modules
1539 world.tick(clock)
1540 hud.tick(clock)
1541 input_control.tick(clock)
1542
1543 # Render all modules
1544 display.fill(COLOR_ALUMINIUM_4)
1545 world.render(display)
1546 hud.render(display)
1547 input_control.render(display)
1548
1549 pygame.display.flip()
1550
1551 except KeyboardInterrupt:
1552 print('\nCancelled by user. Bye!')
1553
1554 finally:
1555 if world is not None:
1556 world.destroy()
1557
1558
1559def exit_game():

Callers 1

mainFunction · 0.70

Calls 13

renderMethod · 0.95
startMethod · 0.95
startMethod · 0.95
startMethod · 0.95
tickMethod · 0.95
tickMethod · 0.95
tickMethod · 0.95
renderMethod · 0.95
renderMethod · 0.95
destroyMethod · 0.95
InputControlClass · 0.85
HUDClass · 0.70

Tested by

no test coverage detected