def escort(self, mission, seed=0): globalvars.disable_menu = True #Disable the standard menu for now. rd.seed(seed) #Fix the seed for the random number generator. '''Escort (infinite space) - player must escort a friendly NPC ship to the destination''' wipeOldScenario(); resetDust() #Reset the player's location to 0,0 and his speed to zero globalvars.player.loc = (0.0, 0.0) globalvars.player.speed = 0.0 globalvars.player.targetSpeed = 0.0 finish_line = (6000, 0) #Protect this little dude on his way to the finish line. npc_friend = hudHelpers.getNewEnemy(25.0,25.0,'ship',2,2,0,0,0) npc_friend.setDestination(finish_line) npc_friend.state = ship.GOTO_STATE hudHelpers.addNewEnemyToWorld(npc_friend, add_to_team=globalvars.team_manager.player_team) #Display arrow to finish line globalvars.intangibles_top.add(displayUtilities.ArrowToDestination(npc_friend)) #Display finish bullseye globalvars.intangibles_top.add(objInstances.FinishBullsEye(npc_friend, finish_line)) #determine what sorts of obstacles to put on the race course. numbers = dict() numbers['enemy'] = 3 numbers['crystal'] = 5 numbers['large_asteroid'] = 20 numbers['medium_asteroid'] = 30 numbers['small_asteroid'] = 40 numbers['gold_metal'] = 5 numbers['silver_metal'] = 6 numbers['health'] = 7 numbers['capital_ship'] = 0 #Populate space in a semi narrow corridor between the player and the finish line course_length = 6000 #pixels course_height = 1000 #pixels #Midway between player and destination midway = (course_length/2, 0) hudHelpers.populateSpace(objects=numbers, width=course_length, \ height=course_height, center=midway, seed=rd.random()) time_limit = 60 #time limit in seconds text = ['ESCORT MISSION COMPLETED'] #Display timer and score count with the following: globalvars.score_keeper = displayUtilities.TimeLimitDisplay(text, \ points_to_win=1000000, time_limit=time_limit, mission=mission) globalvars.intangibles_top.add(globalvars.score_keeper) #Draw the new background and flip the whole screen. globalvars.screen.fill(globalvars.BGCOLOR) pygame.display.flip() #Display the intro to the mission globalvars.menu.setBasicTextPanel(['You have '+str(time_limit)+' seconds to escort the friendly NPC to the finish.', 'If you lose your NPC ally, look for the yellow arrow.'])
def update(self): self.countdown -= 1 globalvars.player.destination = self.player_destination #print globalvars.player.theta if globalvars.player.closest_sprite != self.most_recent_closest: self.most_recent_closest = globalvars.player.closest_sprite print 'Closest is now: '+str(self.most_recent_closest) if self.countdown < 0: #reset countdown self.countdown = globalvars.FPS*15 #clears all sprite groups again. wipeOldScenario() #Add self back in globalvars.intangibles_bottom.add(self) #Draw the new background and flip the whole screen. globalvars.screen.fill(globalvars.BGCOLOR) pygame.display.flip() resetDust() globalvars.player.theta = 0.0 #globalvars.player.speed = 2.0 #globalvars.player.targetSpeed = 2.0 #globalvars.player.maxSpeed = 2.0 #puts in rocks at fixed places. numbers = dict() numbers['enemy'] = 0 numbers['crystal'] = 5 numbers['large_asteroid'] = 20 numbers['medium_asteroid'] = 30 numbers['small_asteroid'] = 40 numbers['gold_metal'] = 5 numbers['silver_metal'] = 6 numbers['health'] = 7 numbers['capital_ship'] = 0 #Populate space in a semi narrow corridor between the player and the finish line course_length = 8000 #pixels course_height = 1000 #pixels #Midway between player and destination midway = (course_length/2, 0) hudHelpers.populateSpace(objects=numbers,\ width=course_length, \ height=course_height,\ center=globalvars.player.rect.center,\ seed=self.phase) self.phase += 1
def race(self, mission, seed=0): globalvars.disable_menu = True #Disable the standard menu for now. rd.seed(seed) #Fix the seed for the random number generator. '''Race (infinite space) - player is given a destination and the clock starts ticking. Space is populated pseudo randomly (deterministically) with obstacles, enemies, gems.''' wipeOldScenario(); resetDust() #Reset the player's location to 0,0 and his speed to zero globalvars.player.loc = (0.0, 0.0) globalvars.player.speed = 0.0 globalvars.player.targetSpeed = 0.0 finish_line = (6000, 0) bulls_eye = objInstances.FinishBullsEye(globalvars.player, finish_line) #Display arrow to finish line globalvars.intangibles_top.add(displayUtilities.ArrowToDestination(bulls_eye)) #Display finish bullseye globalvars.intangibles_top.add(bulls_eye) #determine what sorts of obstacles to put on the race course. numbers = dict() numbers['enemy'] = 3 numbers['crystal'] = 5 numbers['large_asteroid'] = 20 numbers['medium_asteroid'] = 30 numbers['small_asteroid'] = 40 numbers['gold_metal'] = 5 numbers['silver_metal'] = 6 numbers['health'] = 7 numbers['capital_ship'] = 0 #Populate space in a semi narrow corridor between the player and the finish line course_length = 6000 #pixels course_height = 1000 #pixels #Midway between player and destination midway = (course_length/2, 0) hudHelpers.populateSpace(objects=numbers, width=course_length, \ height=course_height, center=midway, seed=rd.random()) time_limit = 30 #time limit in seconds text = ['RACE COMPLETED'] #Display timer and score count with the following: globalvars.score_keeper = displayUtilities.TimeLimitDisplay(text, \ points_to_win=1000000, time_limit=time_limit, mission=mission) globalvars.intangibles_top.add(globalvars.score_keeper) #Draw the new background and flip the whole screen. globalvars.screen.fill(globalvars.BGCOLOR) pygame.display.flip() #Display the intro to the mission globalvars.menu.setBasicTextPanel(['You have '+str(time_limit)+' seconds to reach the finish.', 'Follow the yellow arrow and reach the finish bullseye before time runs out in order to win.'])
def update(self): self.countdown -= 1 globalvars.player.destination = self.player_destination if self.countdown < 0: #reset countdown self.countdown = globalvars.FPS*5 #Transition to next phase if self.phase == 0: #Puts in dust and gives player ship motion. resetDust() globalvars.player.theta = 0.0 globalvars.player.speed = 10.0 globalvars.player.targetSpeed = 10.0 self.phase += 1 elif self.phase == 1: #puts in rocks at fixed places. numbers = dict() numbers['enemy'] = 0 numbers['crystal'] = 5 numbers['large_asteroid'] = 20 numbers['medium_asteroid'] = 30 numbers['small_asteroid'] = 40 numbers['gold_metal'] = 5 numbers['silver_metal'] = 6 numbers['health'] = 7 numbers['capital_ship'] = 0 #Populate space in a semi narrow corridor between the player and the finish line course_length = 8000 #pixels course_height = 1000 #pixels #Midway between player and destination midway = (course_length/2, 0) hudHelpers.populateSpace(objects=numbers,\ width=course_length, \ height=course_height,\ center=globalvars.player.rect.center,\ seed=0) self.phase += 1 elif self.phase == 2: #puts in ships at fixed places. #puts in rocks at fixed places. numbers = dict() numbers['enemy'] = 10 numbers['crystal'] = 0 numbers['large_asteroid'] = 0 numbers['medium_asteroid'] = 0 numbers['small_asteroid'] = 0 numbers['gold_metal'] = 0 numbers['silver_metal'] = 0 numbers['health'] = 0 numbers['capital_ship'] = 1 #Populate space in a semi narrow corridor between the player and the finish line course_length = 8000 #pixels course_height = 1000 #pixels #Midway between player and destination midway = (course_length/2, 0) hudHelpers.populateSpace(objects=numbers,\ width=course_length, \ height=course_height,\ center=globalvars.player.rect.center,\ seed=0) self.phase += 1 elif self.phase == 3: #clears all sprite groups again. wipeOldScenario() #Add self back in globalvars.intangibles_bottom.add(self) #Draw the new background and flip the whole screen. globalvars.screen.fill(globalvars.BGCOLOR) pygame.display.flip() resetDust() #5 seconds of lots of explosions everywhere. self.phase += 1 elif self.phase == 4: #prints graphical data straight to file. if sys.platform != 'darwin': #This is not working on my mac for some reason import matplotlib.pyplot as plt plt.plot(globalvars.dirty_rect_size) plt.xlabel('Frames') plt.ylabel('Number of dirty rects') plt.savefig('profiling/dirty_rect_size.jpeg') #plt.show() plt.clf() plt.plot(globalvars.time_lapses, 'ro') plt.xlabel('Frames') plt.ylabel('Tick length') plt.savefig('profiling/tick_lengths.jpeg') #plt.show() plt.clf() exit() if self.phase == 4: x,y = getCoordsNearLoc(globalvars.player.rect.center, 50, globalvars.WIDTH, globalvars.WIDTH) globalvars.intangibles_top.add(objInstances.Explosion(x=x,y=y))