def run_game(): # initialize pygame and create screen surface pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Alien Invasion") sound.init_sounds() # Make the play button play_button = Button(screen, "Play") # Create an instance to store game statistics and create a scoreboard stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) # Make a ship, a grouop of bullets, and a gorup of aliens ship = Ship(ai_settings, screen) bullets = Group() aliens = Group() # Create the fleet of aliens gf.create_fleet(ai_settings, screen, ship, aliens) # start main loop for the game while True: gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def __init__(self, task_settings, user_settings, debug=False, fmake=True): self.DEBUG = debug make = False if not fmake else ['video'] # ===================================================================== # IMPORT task_settings, user_settings, and SessionPathCreator params # ===================================================================== ts = {i: task_settings.__dict__[i] for i in [x for x in dir(task_settings) if '__' not in x]} self.__dict__.update(ts) us = {i: user_settings.__dict__[i] for i in [x for x in dir(user_settings) if '__' not in x]} self.__dict__.update(us) self = iotasks.deserialize_pybpod_user_settings(self) spc = SessionPathCreator(self.IBLRIG_FOLDER, self.IBLRIG_DATA_FOLDER, self.PYBPOD_SUBJECTS[0], protocol=self.PYBPOD_PROTOCOL, board=self.PYBPOD_BOARD, make=make) self.__dict__.update(spc.__dict__) # ===================================================================== # SUBJECT # ===================================================================== self.SUBJECT_WEIGHT = self.get_subject_weight() # ===================================================================== # OSC CLIENT # ===================================================================== self.OSC_CLIENT_PORT = 7110 self.OSC_CLIENT_IP = '127.0.0.1' self.OSC_CLIENT = udp_client.SimpleUDPClient(self.OSC_CLIENT_IP, self.OSC_CLIENT_PORT) # ===================================================================== # PREVIOUS DATA FILES # ===================================================================== self.LAST_TRIAL_DATA = iotasks.load_data(self.PREVIOUS_SESSION_PATH) self.LAST_SETTINGS_DATA = iotasks.load_settings( self.PREVIOUS_SESSION_PATH) # ===================================================================== # ADAPTIVE STUFF # ===================================================================== self.CALIB_FUNC = adaptive.init_calib_func(self) self.CALIB_FUNC_RANGE = adaptive.init_calib_func_range(self) self.REWARD_VALVE_TIME = adaptive.init_reward_valve_time(self) # ===================================================================== # ROTARY ENCODER # ===================================================================== self.ALL_THRESHOLDS = (self.STIM_POSITIONS + self.QUIESCENCE_THRESHOLDS) self.ROTARY_ENCODER = MyRotaryEncoder(self.ALL_THRESHOLDS, self.STIM_GAIN, self.COM['ROTARY_ENCODER']) # ===================================================================== # SOUNDS # ===================================================================== self.SOUND_SAMPLE_FREQ = sound.sound_sample_freq(self.SOFT_SOUND) self.WHITE_NOISE_DURATION = float(self.WHITE_NOISE_DURATION) self.WHITE_NOISE_AMPLITUDE = float(self.WHITE_NOISE_AMPLITUDE) self.GO_TONE_DURATION = float(self.GO_TONE_DURATION) self.GO_TONE_FREQUENCY = int(self.GO_TONE_FREQUENCY) self.GO_TONE_AMPLITUDE = float(self.GO_TONE_AMPLITUDE) self.SD = sound.configure_sounddevice( output=self.SOFT_SOUND, samplerate=self.SOUND_SAMPLE_FREQ) # Create sounds and output actions of state machine self.UPLOADER_TOOL = None self.GO_TONE = None self.WHITE_NOISE = None self = sound.init_sounds(self) # sets GO_TONE and WHITE_NOISE self.OUT_TONE = ('SoftCode', 1) if self.SOFT_SOUND else None self.OUT_NOISE = ('SoftCode', 2) if self.SOFT_SOUND else None # ===================================================================== # RUN VISUAL STIM # ===================================================================== bonsai.start_visual_stim(self) # ===================================================================== # SAVE SETTINGS FILE AND TASK CODE # ===================================================================== if not self.DEBUG: iotasks.save_session_settings(self) iotasks.copy_task_code(self) iotasks.save_task_code(self) self.bpod_lights(0) self.display_logs()
import sound import background from game import Game pygame.mixer.pre_init(22050, -16, 2, 2048) # idk what this does but apparently I need it pygame.mixer.init() pygame.init() WINDOW = pygame.display.set_mode( (const.WIN_LENGTH, const.WIN_HEIGHT)) # defines the game window pygame.display.set_caption('I Am Not On Fire Yet') SURFACE = pygame.Surface((const.WIN_LENGTH, const.WIN_HEIGHT)) img.init_images() # must be done after setting display mode sound.init_sounds() def run_game(window, surface): clock = pygame.time.Clock() game_bg = background.Background(surface) game = Game(surface) running = True while running: clock.tick() pygame.time.delay(10) ## apparently this helps with inputs game_bg.draw() for event in pygame.event.get(): if event.type == pygame.QUIT: # what happens when X is pressed