def draw(self): self.bar.draw() text = CenterText(self.window, self.window.width - self.bar.width / 2 - 8, 40, text=self.points) text.draw()
class GameOverScene(SceneInterface): def __init__(self, hud: HudManager): self.hud = hud self.window = hud.get_window() self.background = GameImage(BACKGROUND_HOME_OVER) self.text = CenterText(self.window, self.window.width / 2, 50, WHITE, text="Você perdeu!") self.voltar_button = Button(self.window, self.window.width / 2, self.window.height / 2, "VOLTAR") def handle_event(self, fps, state): if self.voltar_button.is_button_pressed(): self.window.main_scene.change_scene('Main') def draw(self, state): self.background.draw() self.text.draw() self.voltar_button.draw() def update(self, state): self.voltar_button.update()
def draw(self): self.bar.draw() self.time = self.time - self.window.delta_time() seconds = self.time if int(seconds) == 0: self.window.main_scene.change_scene('City') text = CenterText(self.window, self.window.width / 2, 46, text=int(seconds)) text.draw()
def draw(self): self.button.draw() color = NEAR_BLACK if self.mouse.is_over_object(self.button): color = ORANGE text = CenterText(self.window, self.x + self.button.width / 2, self.y + self.button.height / 2, color=color, size=80, text=self.text_str) text.draw() self.update()
class SelectPlaneScene(SceneInterface): def __init__(self, hud: HudManager): self.hud = hud self.window = hud.get_window() self.mouse = hud.get_window().get_mouse() self.fundo = GameImage(BACKGROUND_HOME) self.time = 0 self.select = False points_background = pygame.transform.scale( GameImage(SOUND_BACKGROUND).image, (1100, 800)) self.point_background = GameImage(SOUND_BACKGROUND) self.point_background.image = points_background self.point_background.set_position( self.window.width / 2 - points_background.get_width() / 2, 0) self.text = CenterText(hud.get_window(), WIDTH_DIV, 300, text="Escolha qual será sua próxima nave") self.jet_g_bool = False self.jet_green = Sprite(*JET_GREEN_FLY) self.jet_green.set_position( WIDTH_DIV - WIDTH_DIV / 2 - self.jet_green.width + 200, 350) self.jet_y_bool = False self.jet_yellow = Sprite(*JET_YELLOW_FLY) self.jet_yellow.set_position(WIDTH_DIV + WIDTH_DIV / 2 - 200, 350) def handle_event(self, speed: int, scene: bool): if self.mouse.is_over_object(self.jet_green): self.jet_g_bool = True self.jet_y_bool = False if self.mouse.is_button_pressed(mouse.BUTTON_LEFT): self.hud.set_ship_look(JET_GREEN_FLY) self.select = True elif self.mouse.is_over_object(self.jet_yellow): self.jet_y_bool = True self.jet_g_bool = False if self.mouse.is_button_pressed(mouse.BUTTON_LEFT): self.hud.set_ship_look(JET_YELLOW_FLY) self.select = True else: self.time = 2 self.jet_g_bool = False self.jet_y_bool = False def __draw_jet(self, jet: Sprite, enabled: bool): if enabled: if self.time >= 0.0: self.time -= self.window.delta_time() if 1.7 <= self.time <= 2.0: jet.draw() elif 1.1 <= self.time <= 1.4: jet.draw() elif 0.5 <= self.time <= 0.8: jet.draw() elif self.time <= 0.0: jet.draw() else: jet.draw() def draw(self, state: bool): self.fundo.draw() self.point_background.draw() self.__draw_jet(self.jet_yellow, self.jet_y_bool) self.__draw_jet(self.jet_green, self.jet_g_bool) self.text.draw() def update(self, state: bool): if self.select: self.window.main_scene.change_scene('Desert')
class ShopHud: def __init__(self, window): self.window = window self.mouse = window.get_mouse() self.button = GameImage(SHOP_HUD) self.button.set_position(10, self.window.height - 130) self.shop_screen = GameImage(SHOP_SCREEN) self.shop_screen.set_position( self.window.width / 2 - self.shop_screen.width / 2, 85) self.blue_fire_shop = GameImage(BLUE_FIRE_SHOP) self.blue_fire_shop.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.blue_fire_shop_b = GameImage(BLUE_FIRE_SHOP_B) self.blue_fire_shop_b.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.blue_text = CenterText(self.window, self.window.width / 2 + 20, 294, color=SKY_BLUE, size=46, text="10 C") self.pink_fire_shop = GameImage(PINK_FIRE_SHOP) self.pink_fire_shop.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.pink_fire_shop_b = GameImage(PINK_FIRE_SHOP_B) self.pink_fire_shop_b.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.pink_text = CenterText(self.window, self.window.width / 2 + 20, 370, color=PURPLE, size=46, text="10 C") self.torpedo_shop = GameImage(TORPEDO_SHOP) self.torpedo_shop.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.torpedo_shop_b = GameImage(TORPEDO_SHOP_B) self.torpedo_shop_b.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.torpedo_text = CenterText(self.window, self.window.width / 2 + 20, 446, color=FOREST_GREEN, size=46, text="10 C") self.torpedo_black_shop = GameImage(TORPEDO_BLACK_SHOP) self.torpedo_black_shop.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.torpedo_black_shop_b = GameImage(TORPEDO_BLACK_SHOP_B) self.torpedo_black_shop_b.set_position( self.window.width / 2 - self.shop_screen.width / 2, 140) self.torpedo_black_text = CenterText(self.window, self.window.width / 2 + 20, 522, color=BLACK, size=46, text="10 C") self.choose_skin = [True, False, False, False] self.time_delay = 0 self.points = 0 self.show_shop = False def draw_shop(self): if self.choose_skin[0]: self.blue_fire_shop_b.draw() self.pink_fire_shop.draw() self.torpedo_shop.draw() self.torpedo_black_shop.draw() elif self.choose_skin[1]: self.blue_fire_shop.draw() self.pink_fire_shop_b.draw() self.torpedo_shop.draw() self.torpedo_black_shop.draw() elif self.choose_skin[2]: self.blue_fire_shop.draw() self.pink_fire_shop.draw() self.torpedo_shop_b.draw() self.torpedo_black_shop.draw() elif self.choose_skin[3]: self.blue_fire_shop.draw() self.pink_fire_shop.draw() self.torpedo_shop.draw() self.torpedo_black_shop_b.draw() self.blue_text.draw() self.pink_text.draw() self.torpedo_text.draw() self.torpedo_black_text.draw() def draw(self): self.button.draw() if self.show_shop: self.shop_screen.draw() self.draw_shop() def update(self): if self.__is_clicking(self.button): BUTTON_SOUND.play() self.window.main_scene.running = not self.window.main_scene.running self.show_shop = not self.show_shop elif self.window.get_keyboard().key_pressed("ESCAPE"): self.window.main_scene.running = True self.show_shop = False elif self.__is_clicking_shop(0): if self.window.main_scene.get_hud().set_special_look(0): self.choose_skin = [True, False, False, False] elif self.__is_clicking_shop(1): if self.window.main_scene.get_hud().set_special_look(1): self.choose_skin = [False, True, False, False] elif self.__is_clicking_shop(2): if self.window.main_scene.get_hud().set_special_look(2): self.choose_skin = [False, False, True, False] elif self.__is_clicking_shop(3): if self.window.main_scene.get_hud().set_special_look(3): self.choose_skin = [False, False, False, True] def __is_clicking(self, button: GameImage): self.time_delay -= self.window.delta_time() if self.mouse.is_over_object(button) and self.mouse.is_button_pressed( self.mouse.BUTTON_LEFT): if self.time_delay <= 0: self.time_delay = 0.5 return True return False def __is_clicking_shop(self, pos: int): if self.choose_skin[pos]: return False if pos == 0: if self.mouse.is_over_area( (480, 250), (800, 330)) and self.mouse.is_button_pressed( self.mouse.BUTTON_LEFT): return True elif pos == 1: if self.mouse.is_over_area( (480, 331), (800, 410)) and self.mouse.is_button_pressed( self.mouse.BUTTON_LEFT): return True elif pos == 2: if self.mouse.is_over_area( (480, 411), (800, 480)) and self.mouse.is_button_pressed( self.mouse.BUTTON_LEFT): return True else: if self.mouse.is_over_area( (480, 481), (800, 560)) and self.mouse.is_button_pressed( self.mouse.BUTTON_LEFT): return True return False
class MenuScene(SceneInterface): def __init__(self, window): self.hud = HudManager(window) self.window = window self.fundo = GameImage(BACKGROUND_HOME_TITLE) self.sound_background = GameImage(SOUND_BACKGROUND) self.sound_background.set_position( 500 - self.sound_background.width / 2, 540) self.is_option = False self.sound_enable_button = ButtonClick(SOUND_ENABLE, self.window, 96, 600) self.sound_disabled_button = ButtonClick(SOUND_DISABLED, self.window, 96, 600) self.jogar_button = Button(self.window, 250, self.window.height - 96, "JOGAR") self.sair_button = Button(self.window, self.window.width - 250, self.window.height - 96, "SAIR") self.opcoes_button = Button(self.window, self.window.width / 2, self.window.height - 96, "OPÇÕES") self.voltar_button = Button(self.window, self.window.width - 250, 600, "VOLTAR") self.text = CenterText(window, 500, 600, color=GOLD, text="SONS E MÚSICAS") self.time = 0.0 def handle_event(self, speed, state): self.time -= self.window.delta_time() if not self.is_option: if self.time > 0: return if self.jogar_button.is_button_pressed(): self.window.main_scene.change_scene('FirstHistory') elif self.sair_button.is_button_pressed(): pygame.display.quit() pygame.quit() exit() elif self.opcoes_button.is_button_pressed(): self.is_option = not self.is_option else: if self.voltar_button.is_button_pressed(): self.time = 0.5 self.is_option = not self.is_option if self.window.sound.get_sound_state(): if self.sound_enable_button.is_button_pressed(): self.window.sound.change_sound_state() elif not self.window.sound.get_sound_state(): if self.sound_disabled_button.is_button_pressed(): self.window.sound.change_sound_state() def draw(self, state): self.fundo.draw() if not self.is_option: self.jogar_button.draw() self.sair_button.draw() self.opcoes_button.draw() else: self.voltar_button.draw() self.sound_background.draw() self.text.draw() if self.window.sound.get_sound_state(): self.sound_enable_button.draw() else: self.sound_disabled_button.draw() def update(self, state): self.jogar_button.update() self.voltar_button.update() self.sair_button.update() self.opcoes_button.update()