def draw_satellite_overlay(self, universe): cursor_pos = pygame.mouse.get_pos() satellite_list = universe.get_all_satellites() for s in satellite_list: s_pos = to_ints(to_screen(scale_pos(s.get_pos(), universe.get_zoom_factor()))) if get_distance_between(s_pos, cursor_pos) < 30*universe.get_zoom_factor(): HUD_pos = (s_pos[0]+20, s_pos[1]+5) HUD_block = pygame.Surface((245, 70)) HUD_block.fill((100,100,100)) if s.get_nationality() == "Roscosmos1" or s.get_nationality() == "Roscosmos2" or s.get_nationality() == "Roscosmos3" or s.get_nationality() == "Roscosmos": HUD_block.blit(self.RUS_logo, (50-self.RUS_logo.get_width()/2,35-self.RUS_logo.get_height()/2)) elif s.get_nationality() == "ESA1" or s.get_nationality() == "ESA2": HUD_block.blit(self.ESA_logo, (50-self.ESA_logo.get_width()/2,35-self.ESA_logo.get_height()/2)) elif s.get_nationality() == "NASA1"or s.get_nationality() == "NASA2"or s.get_nationality() == "NASA": HUD_block.blit(self.USA_logo, (40-self.USA_logo.get_width()/2,35-self.USA_logo.get_height()/2)) elif s.get_nationality() == "Alien" or s.get_nationality() == "ALIEN1" or s.get_nationality() == "ALIEN2"or s.get_nationality() == "ALIEN3" or s.get_nationality() == "ALIEN4": HUD_block.blit(self.ALIEN_logo, (40-self.USA_logo.get_width()/2,35-self.USA_logo.get_height()/2)) elif s.get_nationality() == "Space Rock" or s.get_nationality() == "ROCK1" or s.get_nationality() == "ROCK2"or s.get_nationality() == "ROCK3" or s.get_nationality() == "ROCK4": HUD_block.blit(self.QUESTION_logo, (40-self.USA_logo.get_width()/2,35-self.USA_logo.get_height()/2)) font = pygame.font.SysFont("Courier", 12) HUD_block.blit(font.render("Name: %s"%(s.get_name()), True, (255,255,255)), (90,5)) HUD_block.blit(font.render("Agency: %s"%(s.get_nationality()), True, (255,255,255)), (90,20)) HUD_block.blit(font.render("Altitude: %s"%(s.get_altitude()), True, (255,255,255)), (90,35)) HUD_block.blit(font.render("Right-click to target", True, (255,255,255)), (90,50)) pygame.draw.rect(HUD_block, (255,255,255), HUD_block.get_rect(), 1) HUD_block.set_alpha(150) self.screen.blit(HUD_block, HUD_pos)
def draw(self, screen): if not self.init_view: self.view_manager.set_target(0, self.planet.get_launcher(), screen) self.init_view = True if self.rocket_shot: self.view_manager.set_target(0, self.rockets[-1], screen) self.rocket_shot = False if self.reset_view: self.view_manager.set_target(0, self.get_launcher(), screen) self.reset_view = False if pygame.mouse.get_pressed()[2]: for satellite in self.planet.get_satellites(): s_pos = to_ints(to_screen(scale_pos(satellite.get_pos(), self.zoom_factor))) if get_distance_between(s_pos, pygame.mouse.get_pos()) < 30*self.zoom_factor: self.view_manager.set_target(0, satellite, screen) for rocket in self.planet.get_rockets(): rocket_pos = to_ints(to_screen(scale_pos(rocket.get_pos(), self.zoom_factor))) if get_distance_between(rocket_pos, pygame.mouse.get_pos()) < 30*self.zoom_factor: self.view_manager.set_target(0, rocket, screen) launcher = self.get_launcher() launcher_pos = to_ints(to_screen(scale_pos(launcher.get_pos(), self.zoom_factor))) if get_distance_between(launcher_pos, pygame.mouse.get_pos()) < 30*self.zoom_factor: self.view_manager.set_target(0, launcher, screen) planet_pos = to_ints(to_screen(scale_pos(self.planet.get_pos(), self.zoom_factor))) if get_distance_between(planet_pos, pygame.mouse.get_pos()) < 30*self.zoom_factor: self.view_manager.set_target(0, self.planet, screen) self.draw_stars(screen, self.stars) self.planet.draw(screen, self.zoom_factor) for rocket in self.rockets: rocket.draw(screen, self.zoom_factor) for explosion in self.explosions: explosion.draw(screen, self.zoom_factor) self.view_manager.draw(screen, self.planet, self.rockets, 1.25)
def draw_launcher_overlay(self, universe): cursor_pos = pygame.mouse.get_pos() launcher = universe.get_launcher() launcher_pos = to_ints(to_screen(scale_pos(launcher.get_pos(), universe.get_zoom_factor()))) if get_distance_between(launcher_pos, cursor_pos) < 30*universe.get_zoom_factor(): HUD_pos = (launcher_pos[0]+20, launcher_pos[1]+5) HUD_block = pygame.Surface((245, 70)) HUD_block.fill((100,100,100)) HUD_block.blit(self.launcher_sprite, (40-self.launcher_sprite.get_width()/2,35-self.launcher_sprite.get_height()/2)) font = pygame.font.SysFont("Courier", 12) HUD_block.blit(font.render("Agency: %s"%(launcher.get_nationality()), True, (255,255,255)), (90,5)) HUD_block.blit(font.render("Rockets left: %s"%(launcher.get_rockets_left()), True, (255,255,255)), (90,20)) HUD_block.blit(font.render("Right-click to target", True, (255,255,255)), (90,50)) pygame.draw.rect(HUD_block, (255,255,255), HUD_block.get_rect(), 1) HUD_block.set_alpha(150) self.screen.blit(HUD_block, HUD_pos)
def draw_rocket_overlay(self, universe): cursor_pos = pygame.mouse.get_pos() for rocket in universe.get_rockets(): rocket_pos = to_ints(to_screen(scale_pos(rocket.get_pos(), universe.get_zoom_factor()))) if get_distance_between(rocket_pos, cursor_pos) < 30*universe.get_zoom_factor(): HUD_pos = (rocket_pos[0]+20, rocket_pos[1]+5) HUD_block = pygame.Surface((245, 70)) HUD_block.fill((100,100,100)) HUD_block.blit(self.rocket_icon, (50-self.rocket_icon.get_width()/2,35-self.rocket_icon.get_height()/2)) font = pygame.font.SysFont("Courier", 12) HUD_block.blit(font.render("Fuel left: %s"%(rocket.get_fuel()), True, (255,255,255)), (90,5)) HUD_block.blit(font.render("Space to self-destruct", True, (255,255,255)), (90,35)) HUD_block.blit(font.render("Right-click to target", True, (255,255,255)), (90,50)) pygame.draw.rect(HUD_block, (255,255,255), HUD_block.get_rect(), 1) HUD_block.set_alpha(150) self.screen.blit(HUD_block, HUD_pos)
def draw_planet_overlay(self, universe): cursor_pos = pygame.mouse.get_pos() planet = universe.get_planet() planet_pos = to_ints(to_screen(scale_pos(planet.get_pos(), universe.get_zoom_factor()))) if get_distance_between(planet_pos, cursor_pos) < 30*universe.get_zoom_factor(): HUD_pos = (planet_pos[0]+20, planet_pos[1]+5) HUD_block = pygame.Surface((245, 70)) HUD_block.fill((100,100,100)) if planet.get_name() == "Earth": HUD_block.blit(self.Earth_icon, (40-self.Earth_icon.get_width()/2,35-self.Earth_icon.get_height()/2)) if planet.get_name() == "Moon": HUD_block.blit(self.Moon_icon, (40-self.Moon_icon.get_width()/2,35-self.Moon_icon.get_height()/2)) if planet.get_name() == "Jupiter": HUD_block.blit(self.Jupiter_icon, (40-self.Jupiter_icon.get_width()/2,35-self.Jupiter_icon.get_height()/2)) if planet.get_name() == "Unknown Meteor": HUD_block.blit(self.Comet_icon, (40-self.Comet_icon.get_width()/2,35-self.Comet_icon.get_height()/2)) if planet.get_name() == "Neptune": HUD_block.blit(self.Neptune_icon, (40-self.Neptune_icon.get_width()/2,35-self.Neptune_icon.get_height()/2)) if planet.get_name() == "Exoplanet I": HUD_block.blit(self.Exoplanet1_icon, (40-self.Exoplanet1_icon.get_width()/2,35-self.Exoplanet1_icon.get_height()/2)) if planet.get_name() == "Exoplanet II": HUD_block.blit(self.Exoplanet2_icon, (40-self.Exoplanet2_icon.get_width()/2,35-self.Exoplanet2_icon.get_height()/2)) if planet.get_name() == "Exoplanet III": HUD_block.blit(self.Exoplanet3_icon, (40-self.Exoplanet3_icon.get_width()/2,35-self.Exoplanet3_icon.get_height()/2)) if planet.get_name() == "Unkown Exometeor": HUD_block.blit(self.Comet2_icon, (40-self.Comet2_icon.get_width()/2,35-self.Comet2_icon.get_height()/2)) if planet.get_name() == "Exoplanet IV": HUD_block.blit(self.Exoplanet4_icon, (40-self.Exoplanet4_icon.get_width()/2,35-self.Exoplanet4_icon.get_height()/2)) font = pygame.font.SysFont("Courier", 12) HUD_block.blit(font.render("Name: %s"%(planet.get_name()), True, (255,255,255)), (90,5)) HUD_block.blit(font.render("Right-click to target", True, (255,255,255)), (90,50)) pygame.draw.rect(HUD_block, (255,255,255), HUD_block.get_rect(), 1) HUD_block.set_alpha(150) self.screen.blit(HUD_block, HUD_pos)