def __init__(self): self.bg = pygame.image.load(WOOD) self.frame = pygame.image.load(FRAME) self.frame = pygame.transform.scale(self.frame, (400, 100)) self.accept_button = RectButton( 550 - 75, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 25), "Accept", Color.GREEN2)) self.accept_button.change_bg_image(WOOD) self.accept_button.add_frame(FRAME) self.deny_button = RectButton( 550 + 200, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 25), "Deny", Color.GREEN2)) self.deny_button.change_bg_image(WOOD) self.deny_button.add_frame(FRAME) self.accept_button.on_click(self._accept_on_click) self.deny_button.on_click(self._deny_on_click) self.background = RectLabel( 550, 300, 200, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 25), "Dodge?", Color.GREEN2)) self.background.change_bg_image(WOOD) self.background.add_frame(FRAME) self.enabled = False self.disable()
def _init_slots(self): """ Initialize the profile slots :return: """ # margin between two buttons margin = 30 width = (self.width / self._limit) - margin height = self.height - 40 for i in range(self._limit): # draw the profile button for each profile x = self.x + ((width + margin) * i) + (margin / 2) y = self.y + 20 btn = RectButton( x, y, width, height, color.STANDARDBTN, 0, Text(pygame.font.SysFont('Agency FB', 25), "Empty", color.BLACK)) remove_btn = RectButton( btn.x, (btn.y + self.height - 80) + 10, btn.width, 30, color.YELLOW, 0, Text(pygame.font.SysFont('Agency FB', 16), "Remove", color.BLACK)) s = RectLabel( btn.x, (btn.y + self.height - 120), btn.width, 30, color.STANDARDBTN, 0, Text(pygame.font.SysFont('Agency FB', 16), "dadsad", color.BLACK)) s.set_transparent_background(True) self._stats_list.append(s) self._remove_btn_list.append(remove_btn) self._btn_list.append(btn) self._profile_list.add(btn)
def init_error_message(self, msg): label_width = 400 label_left = (pygame.display.get_surface().get_size()[0] / 2) - (label_width / 2) label_top = (pygame.display.get_surface().get_size()[1] / 6) * 2 error_msg_label = RectLabel(label_left, label_top, label_width, label_width, (255, 255, 255), txt_obj=(Text(pygame.font.SysFont('Agency FB', 24), msg, Color.RED))) error_msg_label.set_transparent_background(True) self.error_msg = error_msg_label
def _init_background_player(self, rect): if not self._game.rules == GameKindEnum.FAMILY and self._current_player.role: role_path = self.get_path_from_character_enum( self._current_player.role) user_box = RectLabel(rect[0], rect[1], rect[2], rect[3], role_path) else: user_box = RectLabel(rect[0], rect[1], rect[2], rect[3], MEDIA_CONSTS.FAMILY) return user_box
def driver_menu_popup(self, tile_model: TileModel): decision: int = 0 targetTile: TileModel = self._set_target_tile() red_dice = targetTile.row black_dice = targetTile.column boardSprite: GameBoard = GameBoard.instance().top_ui self.label = RectLabel( 200, 400, 600, 200, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), f"Roll: {red_dice}, {black_dice}", Color.GREEN2)) self.label.change_bg_image(WOOD) self.label.add_frame(FRAME) self.input1 = RectButton( 200, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Accept Roll", Color.GREEN2)) self.input1.change_bg_image(WOOD) self.input1.add_frame(FRAME) self.input2 = RectButton( 350, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Black Dice", Color.GREEN2)) self.input2.change_bg_image(WOOD) self.input2.add_frame(FRAME) self.input3 = RectButton( 500, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Red Dice", Color.GREEN2)) self.input3.change_bg_image(WOOD) self.input3.add_frame(FRAME) self.input4 = RectButton( 650, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Both Die", Color.GREEN2)) self.input4.change_bg_image(WOOD) self.input4.add_frame(FRAME) self.input1.on_click(self.input1_process, tile_model, red_dice, black_dice) self.input2.on_click(self.input2_process, tile_model, red_dice, black_dice) self.input3.on_click(self.input3_process, tile_model, red_dice, black_dice) self.input4.on_click(self.input4_process, tile_model, red_dice, black_dice) boardSprite.add(self.label) boardSprite.add(self.input1) boardSprite.add(self.input2) boardSprite.add(self.input3) boardSprite.add(self.input4)
def __init__(self, x: int, y: int, width: int, height: int, background: Union[Tuple[int, int, int], str] = (0, 0, 0), outer_width: int = 0, txt_obj: Optional[Text] = None, txt_pos: Text.Position = Text.Position.CENTER): __doc__ = RectLabel.__doc__ RectLabel.__init__(self, x, y, width, height, background, outer_width, txt_obj, txt_pos) Interactable.__init__(self, self.rect)
def _init_back_box(self, x_pos: int, y_pos: int, text: str, color: Color, color_text: Color): user_box = RectLabel( x_pos, y_pos, 500, 500, color, 0, Text(pygame.font.SysFont('Agency FB', 25), text, color_text)) self.sprite_grp.add(user_box)
def _init_text_box(self, position, text, color): box_size = (position[2], position[3]) user_box = RectLabel( position[0], position[1], box_size[0], box_size[1], color, 0, Text(pygame.font.SysFont('Agency FB', 20), text, (0, 255, 0, 0))) return user_box
def _init_message_box(self): message_box_x = self.offset message_box_w = self.chat_history_bg.rect.w - 2 * self.offset message_box_h = TEXT_BOX_FONT_SIZE + 2 chat_hist_bottom = self.chat_history_bg.rect.h max_messages = math.floor(self.chat_history_bg.rect.h / message_box_h) count = 0 self.to_be_renamed = [] for old_message in reversed(self.chat_history): if count < max_messages: message_box_y = chat_hist_bottom - (message_box_h * (count + 1)) old_message_box = RectLabel( message_box_x, message_box_y, message_box_w, message_box_h, background=Color.WHITE, txt_pos=Text.Position.LEFT, txt_obj=Text(font=pg.font.SysFont("Agency FB", TEXT_BOX_FONT_SIZE - 2), text=f"{old_message[1]}: {old_message[0]}")) self.to_be_renamed.append(old_message_box) count += 1 else: break
def _init_log_box(self): box_size = (self.resolution[0] / 2, self.resolution[1] / 2) x_pos = self.resolution[0] / 2 - box_size[0] / 2 y_pos = self.resolution[1] / 2 - box_size[1] / 2 log_box = RectLabel(x_pos, y_pos, box_size[0], box_size[1], Color.GREEN) self.sprite_grp.add(log_box)
def not_enough_players_ready_prompt(self): """Prompt to the host that there are not enough players to join the game.""" label_width = 400 label_height = 30 label_left = 1050 - 100 label_top = (pygame.display.get_surface().get_size()[1] - 50) - (label_height / 2) message = f"Not all players are ready!" prompt_label = RectLabel(label_left, label_top, label_width, label_height, Color.WHITE, txt_obj=Text( pygame.font.SysFont('Agency FB', 24), message)) prompt_label.set_transparent_background(True) self.players_not_ready_prompt = prompt_label
def __init__(self): self._source = None self._target = None self._notification = RectLabel( 500, 0, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), f"Commanding: None", Color.GREEN2)) self._notification.change_bg_image(WOOD) self._notification.add_frame(FRAME) self._wait_command = RectLabel( 500, 400, 300, 50, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), f"Commanded by: None", Color.GREEN2)) self._wait_command.change_bg_image(WOOD) self._wait_command.add_frame(FRAME) self._init_end_command_btn() self._is_source = False self._is_target = False
def player_role_changed(self, role: PlayerRoleEnum): if self._game.state == GameStateEnum.READY_TO_JOIN: logger.info(f"new role: {role}") role_path = self.get_path_from_character_enum(role) logger.info(f"Role Path is: {role_path}") self.background = (RectLabel(self.background_position[0], self.background_position[1], self.background_position[2], self.background_position[3], role_path))
def _init_chatbox(self): """ Chat box dimensions """ self.offset = 5 chat_box_x = 0 chat_box_y = int(0.6 * SCREEN_RESOLUTION[1]) chat_box_w = 250 chat_box_h = SCREEN_RESOLUTION[1] - chat_box_y """ Chat history dimensions """ chat_hist_x = chat_box_x + self.offset chat_hist_y = chat_box_y + self.offset chat_hist_w = chat_box_w - 2 * self.offset chat_hist_h = 0.85 * chat_box_h """ Chat textbox dimensions """ chat_textbox_x = chat_box_x + self.offset chat_textbox_y = chat_hist_y + chat_hist_h + self.offset chat_textbox_w = chat_hist_w chat_textbox_h = chat_box_h - chat_hist_h - 15 self.chat_box = RectLabel(chat_box_x, chat_box_y, chat_box_w, chat_box_h, background=Color.BLACK) self.chat_history_bg = RectLabel(chat_hist_x, chat_hist_y, chat_hist_w, chat_hist_h, background=Color.WHITE) self.chat_history_bg.set_transparent_background(True) self.chat_textbox = InputBox(x=chat_textbox_x, y=chat_textbox_y, w=chat_textbox_w, h=chat_textbox_h, fsize=20) self.group.add( [self.chat_box, self.chat_history_bg, self.chat_textbox])
def __init__(self, text_position, background_position, username: str, player: PlayerModel, color: Color): super().__init__() self._game: GameStateModel = GameStateModel.instance() self._assoc_player = player self._assoc_player.add_observer(self) self.player_username = username self.txt_pos = text_position self.background_position = background_position self.text_box = self._init_text_box(color) self.background = RectLabel( self.background_position[0], self.background_position[1], self.background_position[2], self.background_position[3], ) self.background.change_bg_image(MEDIA_CONSTS.WOOD) self.background.add_frame( self.get_path_from_character_enum(self._assoc_player.role)) self.background.add_frame(MEDIA_CONSTS.FRAME)
def draw(self, screen): self.button.draw(screen) x_offset1 = 0 y_offset1 = 0 if self.menu_shown: if self.button_input.enabled: screen.blit(self.button_input.image, self.button_input.rect) if self.orientation == "vertical": x_offset1 = -22 y_offset1 = 40 if self.orientation == "horizontal": x_offset1 = 34 y_offset1 = -18 if self.destroyed: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Threat_Markers/damageMarker.png") self.marker.draw(screen) if self.open: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Door_Markers/Open_Door.png") self.marker.draw(screen) if self.closed: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Door_Markers/Closed_Door.png") self.marker.draw(screen)
def __init__(self, current_player: PlayerModel): super().__init__(current_player) if VehiclePlacementController._instance: self._current_player = current_player # raise Exception(f"{VehiclePlacementController.__name__} is a singleton!") self.choose_engine_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Engine Position", Color.GREEN2)) self.choose_engine_prompt.change_bg_image(WOOD) self.choose_engine_prompt.add_frame(FRAME) self.choose_ambulance_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Ambulance Position", Color.GREEN2)) self.choose_ambulance_prompt.change_bg_image(WOOD) self.choose_ambulance_prompt.add_frame(FRAME) self.wait_prompt = RectLabel( 500, 580, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Host Is Placing Vehicles...", Color.GREEN2)) self.wait_prompt.change_bg_image(WOOD) self.wait_prompt.add_frame(FRAME) self.game_board_sprite = GameBoard.instance() self.ambulance_placed = False self.engine_placed = False VehiclePlacementController._instance = self
def input3_process(self, tile: TileModel, red_dice: int, black_dice: int): self.max_input += 1 board_sprite: GameBoard = GameBoard.instance().top_ui self.kill_all() new_tile: TileModel = self._set_target_tile(-1, black_dice) if self.max_input == 2: self.max_input = 0 self.send_event_and_close_menu(tile, self.input1, new_tile.row, new_tile.column) else: red_dice = new_tile.row self.label = RectLabel( 200, 400, 600, 200, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), f"Roll: {red_dice}, {black_dice}", Color.GREEN2)) self.label.change_bg_image(WOOD) self.label.add_frame(FRAME) self.input1 = RectButton( 200, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Accept Roll", Color.GREEN2)) self.input1.change_bg_image(WOOD) self.input1.add_frame(FRAME) self.input2 = RectButton( 350, 350, 150, 50, Color.BLACK, 0, Text(pygame.font.SysFont('Agency FB', 25), "Re-Roll Black Dice", Color.GREEN2)) self.input2.change_bg_image(WOOD) self.input2.add_frame(FRAME) self.input1.on_click(self.input1_process, tile, new_tile.row, black_dice) self.input2.on_click(self.input2_process, tile, new_tile.row, black_dice) board_sprite.add(self.label) board_sprite.add(self.input1) board_sprite.add(self.input2)
def _init_log_box(self, clr): box_size = (self.resolution[0] / 2, self.resolution[1] / 2) x_pos = self.resolution[0] / 2 - box_size[0] / 2 y_pos = self.resolution[1] / 2 - box_size[1] / 2 log_box = RectLabel(x_pos, y_pos, box_size[0], box_size[1], clr) log_box.change_bg_image(WOOD) log_box.add_frame(FRAME) self.sprite_grp.add(log_box)
def _init_load_menu(self, x_pos: int, y_pos: int, text: str, color: color, color_text: color): user_box = RectLabel( x_pos, y_pos, 500, 500, color, 0, Text(pygame.font.SysFont('Agency FB', 25), text, color_text)) user_box.change_bg_image(WOOD) user_box.add_frame(FRAME) self.sprite_grp.add(user_box)
def _init_text_box(self, x_pos, y_pos, w, h, text, color, color_text): box_size = (w, h) user_box = RectLabel(x_pos, y_pos, box_size[0], box_size[1], color, 0, Text(pygame.font.SysFont('Agency FB', 25), text, color_text)) user_box.change_bg_image(WOOD) user_box.add_frame(FRAME) self.sprite_grp.add(user_box)
def create_label(self, x_pos: int, y_pos: int, width: int, height: int, count: int): role: PlayerRoleEnum = self.decide_enum(count) accept = True if any([player.role == role for player in self._game.players]): accept = False if not accept: label = RectLabel(x_pos - 15, y_pos - 15, width + 30, height + 30, Color.RED) label.change_bg_image(MEDIA_CONSTS.WOOD) return label else: label = RectLabel(x_pos - 15, y_pos - 15, width + 30, height + 30, Color.GREEN) label.change_bg_image(MEDIA_CONSTS.WOOD) return label
def __init__(self): self.accept_button = RectButton( 500 - 75, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 20), "Accept", Color.GREEN2)) self.accept_button.change_bg_image(WOOD) self.accept_button.add_frame(FRAME) self.deny_button = RectButton( 500 + 300, 310, 75, 50, Color.ORANGE, 0, Text(pygame.font.SysFont('Agency FB', 20), "Deny", Color.GREEN2)) self.deny_button.change_bg_image(WOOD) self.deny_button.add_frame(FRAME) self.accept_button.on_click(self._accept_on_click) self.deny_button.on_click(self._deny_on_click) self._source = None self._target = None self.background = RectLabel( 500, 300, 300, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 20), "Permission?", Color.GREEN2)) self.background.change_bg_image(WOOD) self.background.add_frame(FRAME) self._enabled = False
def __init__(self, current_player: PlayerModel): super().__init__(current_player) if ChooseStartingPositionController._instance: self._current_player = current_player # raise Exception("ChooseStartingPositionController is a singleton") self.current_player = current_player self.game_board_sprite = GameBoard.instance() self.choose_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Starting Position", Color.GREEN2)) self.choose_prompt.change_bg_image(WOOD) self.choose_prompt.add_frame(FRAME) self.wait_prompt = RectLabel( 500, 400, 300, 50, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Wait for your turn!", Color.GREEN2)) self.wait_prompt.change_bg_image(WOOD) self.wait_prompt.add_frame(FRAME) self.game_board_sprite.top_ui.add(self.choose_prompt) self.game_board_sprite.top_ui.add(self.wait_prompt) ChooseStartingPositionController._instance = self
def _init_your_turn(self): rct = RectLabel(880, 600, 250, 50, background=Color.ORANGE, txt_obj=Text(pygame.font.SysFont('Agency FB', 30), "YOUR TURN", Color.GREEN2)) rct.change_bg_image(WOOD) rct.add_frame(FRAME) return rct
def _init_text_box(self, color: Color): box_size = (self.txt_pos[2], self.txt_pos[3]) user_box = RectLabel( self.txt_pos[0], self.txt_pos[1], box_size[0], box_size[1], color, 0, Text(pygame.font.SysFont('Agency FB', 27), self.player_username, color)) user_box.change_bg_image(MEDIA_CONSTS.WOOD) user_box.add_frame(MEDIA_CONSTS.FRAME) return user_box
def _init_ip_addr(self): if Networking.get_instance().is_host: ip_addr = f"Your IP address: {Networking.get_instance().get_ip()}" label_width = 400 label_left = (pygame.display.get_surface().get_size()[0] / 2) - (label_width / 2) ip_addr_label = RectLabel(label_left, 20, label_width, 50, (255, 255, 255), txt_obj=(Text( pygame.font.SysFont('Agency FB', 26), ip_addr, Color.GREEN2))) ip_addr_label.change_bg_image(MEDIA_CONSTS.WOOD) ip_addr_label.add_frame(MEDIA_CONSTS.FRAME) #ip_addr_label.set_transparent_background(True) self.sprite_grp.add(ip_addr_label)
def _init_background(self): box_size = (self.resolution[0], self.resolution[1]) background_box = RectLabel(0, 0, box_size[0], box_size[1], FLASHPOINT_BACKGROUND) self.sprite_grp.add(background_box)
class VehiclePlacementController(Controller): """Class for controlling inputs during the placing vehicles phase. Displays prompts.""" _instance = None def __init__(self, current_player: PlayerModel): super().__init__(current_player) if VehiclePlacementController._instance: self._current_player = current_player # raise Exception(f"{VehiclePlacementController.__name__} is a singleton!") self.choose_engine_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Engine Position", Color.GREEN2)) self.choose_engine_prompt.change_bg_image(WOOD) self.choose_engine_prompt.add_frame(FRAME) self.choose_ambulance_prompt = RectLabel( 500, 30, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Choose Ambulance Position", Color.GREEN2)) self.choose_ambulance_prompt.change_bg_image(WOOD) self.choose_ambulance_prompt.add_frame(FRAME) self.wait_prompt = RectLabel( 500, 580, 350, 75, Color.GREY, 0, Text(pygame.font.SysFont('Agency FB', 30), "Host Is Placing Vehicles...", Color.GREEN2)) self.wait_prompt.change_bg_image(WOOD) self.wait_prompt.add_frame(FRAME) self.game_board_sprite = GameBoard.instance() self.ambulance_placed = False self.engine_placed = False VehiclePlacementController._instance = self @classmethod def instance(cls): return cls._instance def run_checks(self, tile_model: TileModel) -> bool: game: GameStateModel = GameStateModel.instance() if game.state != GameStateEnum.PLACING_VEHICLES: return False if not Networking.get_instance().is_host: return False if tile_model.space_kind == SpaceKindEnum.INDOOR: return False return True def send_event_and_close_menu(self, tile_model: TileModel, menu_to_close: Interactable): game_board: GameBoardModel = GameStateModel.instance().game_board spot_list = game_board.engine_spots if self.ambulance_placed else game_board.ambulance_spots parking_spot = [spot for spot in spot_list if tile_model in spot] if not parking_spot: return parking_spot = parking_spot[0] vehicle = game_board.engine if self.ambulance_placed else game_board.ambulance event = VehiclePlacedEvent(vehicle, parking_spot) if Networking.get_instance().is_host: Networking.get_instance().send_to_all_client(event) else: Networking.get_instance().client.send(event) if not self.ambulance_placed: self.ambulance_placed = True elif not self.engine_placed: self.engine_placed = True def _check_highlight(self, tile_model: TileModel, vehicle_type: str): if vehicle_type == "AMBULANCE": return tile_model.space_kind == SpaceKindEnum.AMBULANCE_PARKING elif vehicle_type == "ENGINE": return tile_model.space_kind == SpaceKindEnum.ENGINE_PARKING def _apply_highlight(self, vehicle_type: str): game_state = GameStateModel.instance() for i in range(len(self.game_board_sprite.grid.grid)): for j in range(len(self.game_board_sprite.grid.grid[i])): tile_model = game_state.game_board.get_tile_at(j, i) tile_sprite = self.game_board_sprite.grid.grid[i][j] success = self._check_highlight(tile_model, vehicle_type) if success and not tile_sprite.highlight_color: tile_sprite.highlight_color = Color.GREEN elif not success: tile_sprite.highlight_color = None def process_input(self, tile_sprite: TileSprite): game_state: GameStateModel = GameStateModel.instance() tile_model = game_state.game_board.get_tile_at(tile_sprite.row, tile_sprite.column) if not self.run_checks(tile_model): return self.send_event_and_close_menu(tile_model, None) def enable_prompts(self): if Networking.get_instance().is_host: self.game_board_sprite.top_ui.add(self.choose_engine_prompt) self.game_board_sprite.top_ui.add(self.choose_ambulance_prompt) else: self.game_board_sprite.top_ui.add(self.wait_prompt) def update(self, event_queue: EventQueue): game: GameStateModel = GameStateModel.instance() if not game.state == GameStateEnum.PLACING_VEHICLES: return if self.engine_placed: self.choose_engine_prompt.kill() if self.ambulance_placed: self.choose_ambulance_prompt.kill() ambulance: VehicleModel = GameStateModel.instance( ).game_board.ambulance engine: VehicleModel = GameStateModel.instance().game_board.engine if ambulance.orientation != VehicleOrientationEnum.UNSET and engine.orientation != VehicleOrientationEnum.UNSET: self.wait_prompt.kill() self.choose_ambulance_prompt.kill() self.choose_engine_prompt.kill() vehicle_type = "ENGINE" if self.ambulance_placed else "AMBULANCE" self._apply_highlight(vehicle_type)
class DoorSprite(pygame.sprite.Sprite, DoorObserver): def __init__(self, door_model: DoorModel, orientation: str, tile_sprite: TileSprite, tile_model: TileModel, id: Tuple[int, int, str]): super().__init__() self.orientation = orientation self._game: GameStateModel = GameStateModel.instance() self._current_player = self._game.players_turn self._button = None self.tile_model = tile_model self.id = id self.door_model = door_model self.door_model.add_observer(self) self.open = self.door_model.door_status == DoorStatusEnum.OPEN self.closed = self.door_model.door_status == DoorStatusEnum.CLOSED self.destroyed = self.door_model.door_status == DoorStatusEnum.DESTROYED self.marker = None self.tile_sprite = tile_sprite self._prev_x = self.tile_sprite.rect.x self._prev_y = self.tile_sprite.rect.y self.button_input = RectButton( self.tile_sprite.rect.x + 100, self.tile_sprite.rect.y + 100, 100, 25, Color.WOOD, 0, Text(pygame.font.SysFont('Agency FB', 15), "Interact", Color.GREEN2)) pygame.draw.rect(self.button_input.image, Color.YELLOW, [0, 0, 100, 25], 3) self.button_input.disable() self.menu_shown = False @property def direction(self) -> str: return self.id[2] @property def player(self) -> PlayerModel: return self._current_player @property def button(self): return self._button @button.setter def button(self, button): self._button = button def update(self, event_queue): diff_x = self.tile_sprite.rect.x - self._prev_x diff_y = self.tile_sprite.rect.y - self._prev_y self._button.rect.move_ip((diff_x, diff_y)) self._prev_x = self.tile_sprite.rect.x self._prev_y = self.tile_sprite.rect.y self.button_input.rect.x = self.tile_sprite.rect.x + 100 self.button_input.rect.y = self.tile_sprite.rect.y + 100 for event in event_queue: if event.type == pygame.MOUSEBUTTONUP: if not ((self.button_input.rect.x <= pygame.mouse.get_pos()[0] <= self.button_input.rect.x + 100) and (self.button_input.rect.y <= pygame.mouse.get_pos()[1] <= self.button_input.rect.y + 25)): self.button_input.disable() self._button.update(event_queue) self.button_input.update(event_queue) def door_status_changed(self, status: DoorStatusEnum): if status == DoorStatusEnum.DESTROYED: self.destroyed = True self.open = False self.closed = False elif status == DoorStatusEnum.CLOSED: self.closed = True self.open = False self.destroyed = False elif status == DoorStatusEnum.OPEN: self.open = True self.closed = False self.destroyed = False else: raise Exception("Door status ERROR") def draw(self, screen): self.button.draw(screen) x_offset1 = 0 y_offset1 = 0 if self.menu_shown: if self.button_input.enabled: screen.blit(self.button_input.image, self.button_input.rect) if self.orientation == "vertical": x_offset1 = -22 y_offset1 = 40 if self.orientation == "horizontal": x_offset1 = 34 y_offset1 = -18 if self.destroyed: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Threat_Markers/damageMarker.png") self.marker.draw(screen) if self.open: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Door_Markers/Open_Door.png") self.marker.draw(screen) if self.closed: self.marker = RectLabel(self.button.rect.x + x_offset1, self.button.rect.y + y_offset1, 50, 50, "media/Door_Markers/Closed_Door.png") self.marker.draw(screen)