May-25-2018, 08:49 PM
(This post was last modified: May-25-2018, 08:49 PM by Midnight_Sparkle3344.)
I moved the loop in a file called "game_functions.py"
alien_invasion.py:
import sys import pygame def check_events(bValue, pygame): """Respond to keypresses and mouse events.""" for event in pygame.event.get(): if event.type == pygame.QUIT: bValue = FalseI'm not sure where I should have passed the pygame object also, but I thought that was the way to get it to work. Here is my main file:
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) gf.update_screen(ai_settings,screen,ship) # Respond to keypresses and mouse events. # for event in pygame.event.get(): # if event.type == pygame.QUIT: # b_is_running = False # 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()The ship gets drawn, so the function update_screen works. It's the function check_events that does that seem to work. Any thoughts?