class StartLevelView(LogoView): def __init__(self, graphics, model): super().__init__(graphics, model) self.level_num = 0 self.apple_count = 0 self.menu_view = MenuView(graphics, model) self.x = self.center_axis(0, self.width, self.menu_view.width) fp = graphics.get_font_params('green_light') offset_y = fp.get_lines_height(4) self.y = self.center_axis(self.logo_height, self.height, self.menu_view.height + offset_y) self.menu_view.set_pos(self.x, self.y + offset_y) def render(self): super().render() g = self.graphics g.set_font('white') str_level = 'LEVEL ' + str(self.level_num) str_level_width = g.font_params.get_str_width(str_level) str_level_x = self.center_axis(0, self.width, str_level_width) self.graphics.draw_text(str_level, str_level_x, self.y) g.set_font('green_light') str_apples = 'COLLECT ' + str(self.apple_count) + ' APPLES' str_apples_width = g.font_params.get_str_width(str_apples) str_apples_x = self.center_axis(0, self.width, str_apples_width) self.graphics.draw_text(str_apples, str_apples_x, self.y + g.font_params.get_lines_height(2)) self.menu_view.render()
class EnterNameView(LogoView): MSG = 'ENTER YOUR NAME' def __init__(self, graphics, model): super().__init__(graphics, model) self.menu_view = MenuView(graphics, model) fp = graphics.get_font_params('white') self.prompt_x = self.center_axis(0, self.width, fp.get_str_width(self.MSG)) self.prompt_y = self.logo_height + 2 * fp.char_height self.x = self.center_axis(0, self.width, self.menu_view.width) self.y = self.center_axis(self.logo_height, graphics.height, self.menu_view.height) self.menu_view.set_pos(self.x, self.y + 100) self.user_name = '' def render(self): super().render() self.update_ticks() g = self.graphics g.set_font('green_light') fp = g.font_params y = self.prompt_y g.draw_text(self.MSG, self.prompt_x, y) y += fp.char_height * 2 g.draw_rect(self.prompt_x - fp.char_spacing, y - fp.char_spacing, fp.get_str_width(self.MSG) + fp.char_spacing * 2, fp.char_height + fp.char_spacing * 2, (30,80,0)) g.set_font('white') g.draw_text(self.user_name, self.prompt_x, y) if self.ticks <= self.MAX_TICKS // 2: g.draw_rect(self.prompt_x + fp.get_str_width(self.user_name) + fp.char_spacing, y + fp.char_height - 8, fp.char_width / 2, 8, (255,255,255)) self.menu_view.render()
class MainMenuView(LogoView): def __init__(self, graphics, model): super().__init__(graphics, model) self.menu_view = MenuView(graphics, model) self.x = (self.graphics.width - self.menu_view.width) // 2 self.y = self.logo_height + (self.graphics.height - self.logo_height - self.menu_view.height) // 2 self.menu_view.set_pos(self.x, self.y) def render(self): super().render() self.menu_view.render()
class UserTableView(LogoView): MSG = 'HALL_OF FAME' def __init__(self, graphics, model, menu_model): super().__init__(graphics, model) self.menu_view = MenuView(graphics, menu_model) fp = graphics.font_params self.title_x = self.center_axis(0, self.width, fp.get_str_width(self.MSG)) self.x = self.center_axis(0, self.width, fp.get_len_width(28)) self.y = self.center_axis(0, self.height, fp.get_lines_height(14, 4)) self.menu_view.x = self.center_axis(0, self.width, self.menu_view.width) def render(self): super().render() g = self.graphics g.set_font('white') fp = g.font_params y = self.y step_y = fp.char_height + 4 step_x = fp.char_width + fp.char_spacing g.draw_text(self.MSG, self.title_x, y) y += step_y + step_y i = 1 for user_data in self.model: x = self.x g.set_font('green_dark') s = str(i) + '.' if i < 10: x += step_x g.draw_text(s, x, y) x = self.x + step_x * 3 s = user_data.name g.set_font('green_light') g.draw_text(s, x, y) count = len(s) x += step_x * count g.set_font('green_dark') score = str(user_data.score) target_count = 18 + 6 - len(score) while count < target_count: g.draw_text('.', x, y) count += 1 x += step_x g.set_font('digits_gradient') g.draw_text(str(user_data.score), x, y) y += step_y i += 1 self.menu_view.y = y + step_y self.menu_view.render()
class GameOverView(ModalView): def __init__(self, graphics, model): super().__init__(graphics, model) self.menu_view = MenuView(graphics, model) self.menu_x = self.back_x + self.center_axis( 0, self.img_back.get_width(), self.menu_view.width) self.menu_y = self.back_y + self.center_axis( 66, self.img_back.get_height(), self.menu_view.height) self.menu_view.set_pos(self.menu_x, self.menu_y) def render(self): super().render() self.graphics.set_font('white') self.graphics.draw_text('GAME OVER', self.menu_x + self.menu_view.selector_dx, self.back_y + 12) self.menu_view.render()
class FinishView(LogoView): MSG_CONGRATS = 'CONGRATULATIONS!' MSG_FINISHED = 'YOU HAVE FINISHED THE GAME' MSG_MAX_LENGTH = 'MAX PYTHON LENGTH ' MSG_APPLES = 'APPLES EATEN ' def __init__(self, graphics, model): super().__init__(graphics, model) self.length = 0 self.apples = 0 self.menu_view = MenuView(graphics, model) self.x = self.center_axis(0, self.width, self.menu_view.width) fp = graphics.get_font_params('green_light') offset_y = fp.get_lines_height(6) self.y = self.center_axis(self.logo_height, self.height, self.menu_view.height + offset_y) self.menu_view.set_pos(self.x, self.y + offset_y) self.step_y = fp.char_height + fp.line_spacing self.congrats_x = self.center_axis(0, self.width, fp.get_str_width(self.MSG_CONGRATS)) self.finished_x = self.center_axis(0, self.width, fp.get_str_width(self.MSG_FINISHED)) def render(self): super().render() g = self.graphics g.set_font('white') y = self.y self.graphics.draw_text(self.MSG_CONGRATS, self.congrats_x, y) y += self.step_y self.graphics.draw_text(self.MSG_FINISHED, self.finished_x, y) y += self.step_y * 2 g.set_font('green_light') str_len = self.MSG_MAX_LENGTH + str(self.length) str_len_width = g.font_params.get_str_width(str_len) str_len_x = self.center_axis(0, self.width, str_len_width) self.graphics.draw_text(str_len, str_len_x, y) y += self.step_y str_apples = self.MSG_APPLES + str(self.apples) str_apples_width = g.font_params.get_str_width(str_apples) str_apples_x = self.center_axis(0, self.width, str_apples_width) self.graphics.draw_text(str_apples, str_apples_x, y) self.menu_view.render()
class PauseView(ModalView): def __init__(self, graphics, model): super().__init__(graphics, model) self.img_esc = graphics.load_image('data/img/modal_esc_x.png') self.menu_view = MenuView(graphics, model) self.menu_x = self.back_x + (self.img_back.get_width() - self.menu_view.width) // 2 self.menu_y = 66 + self.back_y + (self.img_back.get_height() - 66 - self.menu_view.height) // 2 self.menu_view.set_pos(self.menu_x, self.menu_y) def render(self): super().render() self.graphics.draw_image(self.img_esc, self.back_x + 440, self.back_y + 11) self.graphics.set_font('white') self.graphics.draw_text('PAUSE', self.menu_x + self.menu_view.selector_dx, self.back_y + 12) self.menu_view.render()
class SetupView(LogoView): def __init__(self, graphics, model): super().__init__(graphics, model) self.level_num = 0 self.apple_count = 0 self.menu_view = MenuView(graphics, model) self.x = self.center_axis(0, self.width, self.menu_view.width) fp = graphics.get_font_params('green_light') offset_y = fp.get_lines_height(2) self.y = self.center_axis(self.logo_height, self.height, self.menu_view.height + offset_y) self.menu_view.set_pos(self.x, self.y + offset_y) def render(self): super().render() g = self.graphics g.set_font('white') str_title = 'SETUP' str_title_width = g.font_params.get_str_width(str_title) str_title_x = self.center_axis(0, self.width, str_title_width) self.graphics.draw_text(str_title, str_title_x, self.y) self.menu_view.render()