def draw_gui(self, screen):
     standard_width = options.standard_size()[0]
     standard_height = options.standard_size()[1]
     xoffset = (screen.get_width() - standard_width) / 2
     yoffset = (screen.get_height() - standard_height) / 2
     
     if screen.get_width() > standard_width or screen.get_height() > standard_height:
         # so that in dev mode you can see what the actual screen size would be.
         pygame.draw.rect(screen,(255,0,0), pygame.Rect(xoffset,yoffset,standard_width,standard_height), 1)
     
     level_text = self.font.render("Level: "+str(self.get_level_num() + 1), True, (255, 255, 255))
     level_title = self.font.render(str(self.get_level_manager().current_level.name), True, (255, 255, 255))
     death_text = self.font.render("Deaths: "+str(self.death_count), True, (255, 255, 255))
     text_height = level_text.get_height()
     
     best_total_time = self.get_level_manager().get_best_run_time()
     total_time_text_color = self.get_time_display_color(self.total_time, best_total_time, start_color=(255, 255, 255), end_color=(255, 255, 255))
     total_time_text = self.font.render("Total: " + utilities.format_time(self.total_time), True, total_time_text_color)
     
     best_level_time = self.get_level_manager().get_best_level_time(self.get_level_num())
     level_time_text_color = self.get_time_display_color(self.level_time, best_level_time)
     level_time_text = self.font.render("Level: "+utilities.format_time(self.level_time), True, level_time_text_color)
     
     screen.blit(level_text, (xoffset, yoffset))
     screen.blit(level_title, (xoffset, yoffset + text_height))
     if self.settings.single_level_mode():
         screen.blit(level_time_text, (xoffset + standard_width/2 - level_time_text.get_width()/2, yoffset))
     else:
         screen.blit(total_time_text, (xoffset + standard_width/2 - total_time_text.get_width()/2, yoffset))
         screen.blit(level_time_text, (xoffset + standard_width/2 - level_time_text.get_width()/2, yoffset + text_height))
         screen.blit(death_text, (xoffset + standard_width - death_text.get_width(), yoffset))
 def draw(self, screen):
     screen.fill(self.background_color)
     standard_width = options.standard_size()[0]
     standard_height = options.standard_size()[1]
     xoffset = (screen.get_width() - standard_width) / 2
     yoffset = (screen.get_height() - standard_height) / 2
     
     if screen.get_width() > standard_width or screen.get_height() > standard_height:
         # so that in dev mode you can see what the actual screen size would be.
         pygame.draw.rect(screen, (255, 0, 0), pygame.Rect(xoffset,yoffset,standard_width,standard_height), 1)
     
     y = 0
     for option in self.option_images:
         screen.blit(option, (xoffset + MENU_ICING, yoffset + y + MENU_ICING))
         y += option.get_height()
 def draw(self, screen):
     screen.fill(self.background_color)
     standard_width = options.standard_size()[0]
     standard_height = options.standard_size()[1]
     xoffset = (screen.get_width() - standard_width) / 2
     yoffset = (screen.get_height() - standard_height) / 2
     
     if screen.get_width() > standard_width or screen.get_height() > standard_height:
         # so that in dev mode you can see what the actual screen size would be.
         pygame.draw.rect(screen,(255, 0, 0), pygame.Rect(xoffset,yoffset,standard_width,standard_height), 1)
     
     screen.blit(self.title_image, (xoffset + MENU_ICING, yoffset + MENU_ICING))
     option_heights = [x.get_height() for x in self.option_text_images]
     options_height = sum(option_heights)
     options_width = max([x.get_width() for x in self.option_text_images])
     for i in range(0, len(self.option_text_images)):
         opt = self.option_text_images[i]
         xpos = xoffset + standard_width - options_width - MENU_ICING
         ypos = yoffset + standard_height - options_height + sum(option_heights[0:i]) - MENU_ICING
         screen.blit(opt, (xpos, ypos))
         
     level_pack = self.settings.level_path()
     level_pack_image = NORMAL_TEXT_FONT.render(level_pack, True, self.unselected_color)
     screen.blit(level_pack_image, (xoffset + MENU_ICING, yoffset + self.title_image.get_height() + MENU_ICING))
 def __init__(self, settings):
     GameState.__init__(self, settings)
     self.selected_color = SELECTED_COLOR
     self.unselected_color = UNSELECTED_COLOR
     self.background_color = BACKGROUND_COLOR
     self.title_image = self.get_title_text_image(options.title(), options.standard_size()[0] - 2*MENU_ICING)
     self.option_names = ["start full run", "grind single level", "edit levels", "select level pack", "settings"]
     self.option_actions = [
         lambda: self._launch_full_run_mode(),
         lambda: self.state_manager.set_current_state(GameStateManager.SELECT_SINGLE_LEVEL_STATE),
         lambda: None,
         lambda: None,
         lambda: None
     ]
     self.selected_index = 0
     self.option_text_images = []
     for i in range(0, len(self.option_names)):
         name = self.option_names[i]
         c = self.unselected_color if i != self.selected_index else self.selected_color
         self.option_text_images.append(NORMAL_TEXT_FONT.render(name, True, c))
Esempio n. 5
0
gamestate_manager = GameStateManager(settings)
platformer_inst = PlatformerInstance(settings)
playing = PlayingState(settings, platformer_inst)
editing = EditingState(settings, platformer_inst)
main_menu = MainMenuState(settings)
single_level = SelectSingleLevelState(settings)

gamestate_manager.set_state(GameStateManager.PLAYING_STATE, playing)
gamestate_manager.set_state(GameStateManager.EDITING_STATE, editing)
gamestate_manager.set_state(GameStateManager.MAIN_MENU_STATE, main_menu)
gamestate_manager.set_state(GameStateManager.SELECT_SINGLE_LEVEL_STATE, single_level)


gamestate_manager.set_current_state(GameStateManager.MAIN_MENU_STATE)

size = options.standard_size()
if settings.dev_mode():
    size = options.dev_size()
screen = pygame.display.set_mode(size)

still_running = True
clock = pygame.time.Clock()
FPS = options.fps()

actor = playing.get_player()  # The player's character

def stop_running(): 
    global still_running
    still_running = False
def take_screenshot():
    utilities.take_screenshot(screen)