May-25-2018, 09:44 PM
(May-25-2018, 09:35 PM)metulburr Wrote: well i dont know what gf.check_events() is doing, so i couldnt say
gf.check_events(b_is_running, pygame) is basically the for loop I had in the while loop before. It was just moved into a function.
game_functions.py
import sys import pygame def check_events(bValue, game): """Respond to keypresses and mouse events.""" for event in game.event.get(): if event.type == game.QUIT: bValue = False def update_screen(ai_settings, screen, ship): screen.fill(ai_settings.bg_color) ship.blitme() pygame.display.flip()alien_invasion.py
# alien_invasion.py import pygame from settings import Settings from ship import Ship import game_functions as gf def run_game(): # Boolean value b_is_running = True # Initialize game and create a screen object. pygame.init() ai_settings = Settings() screen_resolution = (ai_settings.screen_width, ai_settings.screen_height) screen = pygame.display.set_mode(screen_resolution) pygame.display.set_caption("Alien Invasion") # Make a ship. ship = Ship(screen) # Start the main loop for the game. while b_is_running: # gf.check_events(b_is_running, pygame) # Respond to keypresses and mouse events. for event in pygame.event.get(): if event.type == pygame.QUIT: b_is_running = False gf.update_screen(ai_settings,screen,ship) # Redraw the screen during each pass through the loop. # screen.fill(ai_settings.bg_color) # ship.blitme() # Make the most recently drown screen visible. # pygame.display.flip() run_game() pygame.quit()