Beispiel #1
0
def test_sprites_at_point():

    coin_list = arcade.SpriteList()
    sprite = arcade.SpriteSolidColor(50, 50, arcade.csscolor.RED)
    coin_list.append(sprite)

    # print()
    # print(sprite.points)
    sprite_list = arcade.get_sprites_at_point((0, 0), coin_list)
    assert len(sprite_list) == 1

    sprite.position = (130, 130)
    # print()
    # print(sprite.points)

    sprite_list = arcade.get_sprites_at_point((0, 0), coin_list)
    assert len(sprite_list) == 0

    sprite_list = arcade.get_sprites_at_point((140, 130), coin_list)
    assert len(sprite_list) == 1

    sprite.angle = 90
    # print()
    # print(sprite.points)

    sprite_list = arcade.get_sprites_at_point((0, 0), coin_list)
    assert len(sprite_list) == 0

    sprite_list = arcade.get_sprites_at_point((140, 130), coin_list)
    assert len(sprite_list) == 1
Beispiel #2
0
 def on_mouse_motion(self, x, y, dx, dy):
     print(self.pants_list)
     sprite_list = arcade.get_sprites_at_point((x, y), self.pants_list)
     print(sprite_list)
     sprite_list = arcade.get_sprites_at_point((x, y), self.shirts_list)
     print(sprite_list)
     """ Handle Mouse Motion """
Beispiel #3
0
    def setup(self) -> None:
        self.set_hit_box([(-4.0, -1.0), (4.0, -1.0), (6.0, -3.0), (6.0, -11.0),
                          (4.0, -13.0), (-4.0, -13.0), (-6.0, -11.0),
                          (-6.0, -3.0)])
        self.curr_color = 'red'
        self.selected_ability = Abilities.red.value

        self.mana_bar = ManaBar(
            self.view,
            fill_part_filename="assets/healthbar/mana_fill_part.png",
            fill_part_width=44.0,
            filename="assets/healthbar/mana_bar_border_white.png",
            center_x=420,
            center_y=18,
            scale=1,
            auto_filling_speed=2)
        self.health_bar = PlayerLiveManager(self.view, self.hp)

        while True:
            center = tile_to_pixels(random.randrange(0, s.MAP_SIZE[0]),
                                    random.randrange(0, s.MAP_SIZE[1]))

            if (len(
                    arcade.get_sprites_at_point(
                        center, self.view.collision_list)) == 0 and len(
                            arcade.get_sprites_at_point(
                                center, self.view.map.sprites)) > 0):
                break

        self.center_x = center[0]
        self.center_y = center[1] + s.PLAYER_CENTER_Y_COMPENSATION
Beispiel #4
0
 def set_checkers(self):
     """Creates all checkers and places them in their initial positions"""
     for index, (y, x) in enumerate(CHECKER_POSITIONS):
         point_low = arcade.get_sprites_at_point((x, y), self.point_list)[0]
         point_low.checker_color = CHECKER_COLORS[index]
         point_top = arcade.get_sprites_at_point((x, SCREEN_HEIGHT - y),
                                                 self.point_list)[0]
         point_top.checker_color = 1 - CHECKER_COLORS[index]
         for checker_count in range(CHECKER_PILES[index]):
             checker = Checker(CHECKER_COLORS[index], 1)
             checker.position = x, y + checker_count * CHECKER_PILE_OFFSET[
                 CHECKER_PILES[index]]
             checker.point = point_low
             if CHECKER_PILES[index] == checker_count + 1:
                 checker.is_selectable = True
             point_low.checker_pile.append(checker)
             self.checker_list.append(checker)
             checker = Checker(1 - CHECKER_COLORS[index], 1)
             checker.position = x, SCREEN_HEIGHT - y - checker_count * CHECKER_PILE_OFFSET[
                 CHECKER_PILES[index]]
             checker.point = point_top
             if CHECKER_PILES[index] == checker_count + 1:
                 checker.is_selectable = True
             point_top.checker_pile.append(checker)
             self.checker_list.append(checker)
Beispiel #5
0
    def on_mouse_press(self, x, y, button, modifiers):
        """Se llama cuando el usuario presiana un boton del mouse
        """
        #Revisar si hemos hecho click en la el mazo de cartas.
        cartas = arcade.get_sprites_at_point((x, y), self.lista_cartas)

        #Revisamos si hemos hecho click en el mazo del jugador
        if (not cartas):
            cartas = arcade.get_sprites_at_point((x, y),
                                                 self.piles[PLAYER_PILE])
            cardpile = self.piles[PLAYER_PILE]
            #Actualizar como se muestran las cartas al jugador:
            i = 0
            for carta in self.piles[PLAYER_PILE]:
                carta.position = START_X + i * 25, BOTTOM_Y + 150
                i += 1
        else:
            cardpile = self.lista_cartas

        #Revisamos si hemos clickeado una carta
        if (len(cartas) > 0):
            #Puede que sea una carta en una pila de cartas
            carta_primaria = cartas[-1]
            #En todos los demas casos tomaremos la carta boca arriba
            self.held_cards = [carta_primaria]
            #Guardar la posicion
            self.held_card_original_position = [self.held_cards[0].position]
            #Poner la carta en la cima
            card = self.held_cards[0]

            self.pull_to_top(card, cardpile)
Beispiel #6
0
    def on_mouse_release(self, x: float, y: float, button: int,
                         modifiers: int):
        # Who's turn is it
        # arcade.get_sprites_at_point() returns a python list of sprites at the cursors location
        if self.turn:
            piece = arcade.get_sprites_at_point((x, y), self.black_set)
        else:
            piece = arcade.get_sprites_at_point((x, y), self.white_set)

        # if there is no sprite at my mouse location
        if len(piece) == 0:
            # drop the sprite
            if self.piece_in_hand is not None:
                mat = arcade.get_closest_sprite(self.piece_in_hand, self.board)
                self.piece_in_hand.position = mat[0].position
                self.turn = not self.turn
                self.piece_in_hand = None
            return

        # if there is a sprite at my mouse location
        elif len(piece) == 1:
            # If piece at current position is a dif color then kill it
            if piece[0].bw != self.piece_in_hand.bw:
                mat = arcade.get_closest_sprite(self.piece_in_hand, self.board)
                self.piece_in_hand.position = mat[0].position
                self.turn = not self.turn
                self.piece_in_hand = None
                piece[0].kill()
Beispiel #7
0
    def on_mouse_press(self, x, y, button, key_modifiers):
        """Called when the user presses a mouse button. """
        if self.turn:
            piece = arcade.get_sprites_at_point((x, y), self.white_set)
        else:
            piece = arcade.get_sprites_at_point((x, y), self.black_set)

        if len(piece) > 0:
            self.piece_in_hand = piece[0]
            self.original_location = self.piece_in_hand.position
Beispiel #8
0
    def on_mouse_press(self, x, y, button, key_modifiers):
        """ Called when the user presses a mouse button. """

        # Get list of buttons we've clicked on
        buttons = arcade.get_sprites_at_point((x, y), self.buttons)
        if len(buttons) > 0:
            button = buttons[-1]
            button.buttonPress()

        HelpButtons = arcade.get_sprites_at_point((x, y), self.Help_buttons)
        if len(HelpButtons) > 0:
            button = HelpButtons[-1]
            button.buttonPress()

        # Get list of cards we've clicked on
        cards = arcade.get_sprites_at_point((x, y), self.card_list)

        # Have we clicked on a card?
        if len(cards) > 0:

            # Might be a stack of cards, get the top one
            primary_card = cards[-1]
            # Figure out what pile the card is in
            pile_index = self.get_pile_for_card(primary_card)
            
            # Are we clicking on the bottom deck, to flip three cards?
            if pile_index == BOTTOM_FACE_DOWN_PILE or pile_index == BOTTOM_FACE_DONE  or pile_index == BOTTOM_FACE_UP_PILE:
                #cannot touch this cards
                return False
                #self.Turn

            elif self.pile_mat_list[pile_index].game:
                #cannot touch this cards
                return False
            elif self.Turn == 0 and self.pile_mat_list[pile_index].myCard:
                #cannot touch this cards
                return False
            elif self.Turn == 1 and self.pile_mat_list[pile_index].enemy:
                #cannot touch this cards
                return False
            else:
                # All other cases, grab the face-up card we are clicking on
                self.held_cards = [primary_card]
                # Save the position
                self.held_cards_original_position = [self.held_cards[0].position]
                # Put on top in drawing order
                self.pull_to_top(self.held_cards[0])

                # Is this a stack of cards? If so, grab the other cards too
                card_index = self.piles[pile_index].index(primary_card)
                for i in range(card_index + 1, len(self.piles[pile_index])):
                    card = self.piles[pile_index][i]
                    self.held_cards.append(card)
                    self.held_cards_original_position.append(card.position)
                    self.pull_to_top(card)
Beispiel #9
0
    def on_mouse_press(self, x, y, button, key_modifiers):
        """ Called when the user presses a mouse button. """

        # Get list of cards we've clicked on
        cards = arcade.get_sprites_at_point((x, y), self.card_list)
        piles = arcade.get_sprites_at_point((x, y), self.pile_mat_list)
        if piles and self.pile_mat_list.index(
                piles[0]) == BOTTOM_FACE_DOWN_PILE:
            if self.turn and self.deck == 0 and len(
                    self.piles[BOTTOM_FACE_UP_PILE]) == 1:
                self.backend.write.put('get')
                self.deck = 1

        if piles and self.pile_mat_list.index(piles[0]) == JOCKER_PILE:
            # Remember to add self.turn condition
            if len(self.piles[JOCKER_PILE]) == 0 and not self.turn:
                self.validate()
                if self.natural_set:
                    self.backend.write.put('jocker')
            return

        if piles and self.pile_mat_list.index(piles[0]) == BUTTON:
            result = self.validate()
            if result and self.turn:
                self.backend.write.put('won')
                end = EndView(self.id)
                self.window.show_view(end)
                # self.backend.client.s.close()
                self.backend.end()

        # Have we clicked on a card?
        if len(cards) > 0:

            # Might be a stack of cards, get the top one
            primary_card = cards[-1]
            # Figure out what pile the card is in
            pile_index = self.get_pile_for_card(primary_card)

            # All other cases, grab the face-up card we are clicking on
            self.held_cards = [primary_card]
            # Save the position
            self.held_cards_original_position = [self.held_cards[0].position]
            # Put on top in drawing order
            self.pull_to_top(self.held_cards[0])

            # Is this a stack of cards? If so, grab the other cards too
            card_index = self.piles[pile_index].index(primary_card)
            for i in range(card_index + 1, len(self.piles[pile_index])):
                card = self.piles[pile_index][i]
                self.held_cards.append(card)
                self.held_cards_original_position.append(card.position)
                self.pull_to_top(card)
Beispiel #10
0
def test_sprites_at_point():

    coin_list = arcade.SpriteList()
    sprite = arcade.Sprite("../../arcade/examples/images/coin_01.png")
    sprite.position = (130, 130)
    sprite.set_position(130, 130)
    sprite.angle = 90
    coin_list.append(sprite)

    sprite_list = arcade.get_sprites_at_point((0, 0), coin_list)
    assert len(sprite_list) == 0

    sprite_list = arcade.get_sprites_at_point((140, 130), coin_list)
    assert len(sprite_list) == 1
Beispiel #11
0
def test_sprites_at_point():

    coin_list = arcade.SpriteList()
    sprite = arcade.Sprite(":resources:images/items/coinGold.png")
    sprite.position = (130, 130)
    sprite.set_position(130, 130)
    sprite.angle = 90
    coin_list.append(sprite)

    sprite_list = arcade.get_sprites_at_point((0, 0), coin_list)
    assert len(sprite_list) == 0

    sprite_list = arcade.get_sprites_at_point((140, 130), coin_list)
    assert len(sprite_list) == 1
Beispiel #12
0
    def on_mouse_press(self, x, y, button, key_modifiers):
        """ Called when the user presses a mouse button. """
        self.card_on_press = None
        c_mats = arcade.get_sprites_at_point((x, y), self.pile_mat_list)
        if len(c_mats) > 0:
            c_card_pile = c_mats[0].cardpile

            if button == arcade.MOUSE_BUTTON_RIGHT and (key_modifiers
                                                        & arcade.key.MOD_ALT):
                # with control, sort current piles
                c_card_pile.resort_cards()
            elif button == arcade.MOUSE_BUTTON_RIGHT and (
                    key_modifiers & arcade.key.MOD_CTRL):
                self.clear_a_pile(c_card_pile)
            else:
                cards = arcade.get_sprites_at_point((x, y), c_card_pile)
                if len(cards) > 0:

                    primary_card = cards[-1]
                    if button == arcade.MOUSE_BUTTON_LEFT:
                        self.card_on_press = primary_card

                        if not primary_card.active:

                            if len(self.active_cards) >= 1:
                                # check if the pile being clicked on is the same as the active cards
                                current_pile = self.get_pile_for_card(
                                    self.card_on_press)
                                active_card_pile = self.get_pile_for_card(
                                    self.active_cards[0])

                                if current_pile != active_card_pile:
                                    # if the card being clicked on belongs to a different pile than those active cards. deactive other cards
                                    for card in self.active_cards:
                                        card.active = False
                                    self.active_cards = []
                            # will held this regardless whether its active
                            self.held_cards.append(primary_card)
                            self.held_cards_original_position.append(
                                primary_card.position)

                        # all active card will move together
                        for card in self.active_cards:
                            self.held_cards.append(card)
                            self.held_cards_original_position.append(
                                card.position)

                    elif button == arcade.MOUSE_BUTTON_RIGHT:
                        self.flip_card(primary_card)
Beispiel #13
0
    def on_mouse_release(self, x: float, y: float, button: int,
                         keyModifiers: int):
        """
        Called when the user presses a mouse button.
        """
        self.logger.info(f'{button=} {keyModifiers=}')
        if button == MOUSE_BUTTON_LEFT and keyModifiers == arcadeKey.MOD_CTRL:
            # Try klingons first
            clickedEnemies: List[Sprite] = get_sprites_at_point(
                point=(x, y), sprite_list=self._quadrantMediator.klingonList)

            # The Commanders
            if len(clickedEnemies) == 0:
                clickedEnemies = get_sprites_at_point(
                    point=(x, y),
                    sprite_list=self._quadrantMediator.commanderList)

            # Must be Super Commanders
            if len(clickedEnemies) == 0:
                clickedEnemies = get_sprites_at_point(
                    point=(x, y),
                    sprite_list=self._quadrantMediator.superCommanderList)

            for enemy in clickedEnemies:
                print(f'Delete {enemy}')
                enemy.remove_from_sprite_lists()
        elif button == MOUSE_BUTTON_LEFT:

            if self._selectedGamePiece is None:
                clickedPaletteSprites: List[Sprite] = get_sprites_at_point(
                    point=(x, y), sprite_list=self._staticSprites)

                for paletteSprite in clickedPaletteSprites:
                    paletteSprite.color = color.BLACK
                    self._selectedGamePiece = paletteSprite
            else:
                # A palette sprite is selected
                self._placeSpriteOnBoard(x=x, y=y)

                self.logger.info(f'Clear selected Sprite')
                self._selectedGamePiece.color = color.WHITE
                self._selectedGamePiece = cast(GamePiece, None)

        arcadePoint: ArcadePoint = ArcadePoint(x=x, y=y)
        self._quadrantMediator.handleMousePress(quadrant=self._quadrant,
                                                arcadePoint=arcadePoint,
                                                button=button,
                                                keyModifiers=keyModifiers)
Beispiel #14
0
    def on_mouse_press(self, x, y, button, key_modifiers):
        """ Called when the user presses a mouse button. """

        # Get list of cards we've clicked on
        cards = arcade.get_sprites_at_point((x, y), self.card_list)

        # Have we clicked on a card?
        if len(cards) > 0:

            # Might be a stack of cards, get the top one
            primary_card = cards[-1]
            # Figure out what pile the card is in
            pile_index = self.get_pile_for_card(primary_card)

            if primary_card.is_face_down:
                # Is the card face down? In one of those middle 7 piles? Then flip up
                primary_card.face_up()
            else:
                # All other cases, grab the face-up card we are clicking on
                self.held_cards = [primary_card]
                # Save the position
                self.held_cards_original_position = [
                    self.held_cards[0].position
                ]
                # Put on top in drawing order
                self.pull_to_top(self.held_cards[0])

                # Is this a stack of cards? If so, grab the other cards too
                card_index = self.piles[pile_index].index(primary_card)
                for i in range(card_index + 1, len(self.piles[pile_index])):
                    card = self.piles[pile_index][i]
                    self.held_cards.append(card)
                    self.held_cards_original_position.append(card.position)
                    self.pull_to_top(card)
Beispiel #15
0
 def on_mouse_press(self, x: float, y: float, button: int, modifiers: int):
     if button == arcade.MOUSE_BUTTON_LEFT:
         collide = arcade.get_sprites_at_point(self.cursor.get_pos(),
                                               self.button_list)
         for button in collide:
             button.on_click()
             self.start()
 def convert_mouse_pos_to_board_loc(self, x, y):
     pt = arcade.Point(x, y)
     collision_list = arcade.get_sprites_at_point(pt, self.board)
     if collision_list != []:
         return collision_list[0].cell_id
     else:
         return None
Beispiel #17
0
 def on_mouse_press(self, x, y, button, key_modifiers):
     """
     Called when the user presses a mouse button.
     """
     hit_sprites = arcade.get_sprites_at_point((x, y), self.button_sprites)
     for sprite in hit_sprites:
         sprite.play()
    def on_mouse_press(self, _x, _y, _button, _modifiers):
        # get buttons clicked on
        buttons = [
            button.get_name()
            for button in arcade.get_sprites_at_point((_x,
                                                       _y), self.sprite_list)
        ]
        # buttons = arcade.get_sprites_at_point((_x, _y), self.sprite_list)
        print(buttons)

        if "start" in buttons:
            game_view = QuizView(self.questions)
            game_view.setup()
            self.window.show_view(game_view)

        if "more" in buttons:
            self.questions += 1
        elif "less" in buttons:
            self.questions -= 1
            if self.questions <= 1:
                self.questions = 1

        if "instruct" in buttons:
            instruct_view = InstructionView()
            instruct_view.setup()
            self.window.show_view(instruct_view)
Beispiel #19
0
def has_line_of_sight(point_1: Point,
                      point_2: Point,
                      walls: SpriteList,
                      max_distance: int = -1,
                      check_resolution: int = 2):
    """
    Determine if we have line of sight between two points. Try to make sure
    that spatial hashing is enabled on the wall SpriteList or this will be
    very slow.

    :param Point point_1: Start position
    :param Point point_2: End position position
    :param SpriteList walls: List of all blocking sprites
    :param int max_distance: Max distance point 1 can see
    :param int check_resolution: Check every x pixels for a sprite. Trade-off
                                 between accuracy and speed.
    """
    distance = get_distance(point_1[0], point_1[1], point_2[0], point_2[1])
    steps = int(distance // check_resolution)
    for step in range(steps + 1):
        step_distance = step * check_resolution
        u = step_distance / distance
        midpoint = lerp_vec(point_1, point_2, u)
        if max_distance != -1 and step_distance > max_distance:
            return False
        # print(point_1, point_2, step, u, step_distance, midpoint)
        sprite_list = get_sprites_at_point(midpoint, walls)
        if len(sprite_list) > 0:
            return False
    return True
Beispiel #20
0
 def _get_sprite_at(self, *coords):
     sprites = arcade.SpriteList()
     sprites.sprite_list = self.all_sprites
     sprites = arcade.get_sprites_at_point(coords, sprites)
     if sprites:
         return max(sprites)
     return EMPTY_SPRITE
Beispiel #21
0
    def on_mouse_press(self, x, y, button, key_modifiers):
        """ called when the user presser a mouse button """

        # get piece clicked on, only allow own units
        if self.turn == 'W':
            piece = arcade.get_sprites_at_point((x, y), self.white_piece_list)
        else:
            piece = arcade.get_sprites_at_point((x, y), self.black_piece_list)

        #check that a sprite was clicked
        if len(piece) > 0:

            # get the tile clicked
            current_tile_coord = self.get_tile_for_piece(piece[0], self.tiles)

            # check that the piece existed as tile content
            if current_tile_coord:
                # adjust held piece information
                self.held_piece = piece[0]
                # save origin for returning piece
                self.held_piece_origin = piece[0].position

                acceptable_moves = self.held_piece.move_list
                acceptable_attacks = self.held_piece.attack_list

                #do highlighting
                for movement in acceptable_moves:
                    sprite_index = (7 - movement[0]) * 8 + movement[1]
                    # highlight_tile = arcade.SpriteSolidColor(SQUARE_HEIGHT, SQUARE_WIDTH, (200,200,0))
                    # highlight_tile.position = self.tile_list[sprite_index].position
                    # self.tile_list.pop(sprite_index)
                    # self.tile_list.insert(sprite_index, highlight_tile)
                    if (movement[0] + movement[1]) % 2 == 0:
                        self.tile_list[sprite_index].color = (0, 145, 145)
                    else:
                        self.tile_list[sprite_index].color = (0, 255, 255)
                for movement in acceptable_attacks:
                    sprite_index = (7 - movement[0]) * 8 + movement[1]
                    # highlight_tile = arcade.SpriteSolidColor(SQUARE_HEIGHT, SQUARE_WIDTH, (200,0,0))
                    # highlight_tile.position = self.tile_list[sprite_index].position
                    # self.tile_list.pop(sprite_index)
                    # self.tile_list.insert(sprite_index, highlight_tile)
                    if (movement[0] + movement[1]) % 2 == 0:
                        self.tile_list[sprite_index].color = (145, 0, 0)
                    else:
                        self.tile_list[sprite_index].color = (255, 0, 0)
Beispiel #22
0
 def on_mouse_press(self, x: float, y: float, button: int, modifiers: int):
     """ Handle a mouse press. """
     LOG.debug("Click UIManager")
     matching_ui_elements = arcade.get_sprites_at_point((x, y), self.ui_elements)
     if len(matching_ui_elements) > 0:
         matching_ui_element2 = typing.cast(arcade.experimental.gui.UIElement, matching_ui_elements[0])
         matching_ui_element2.is_mouse_pressed = True
         return matching_ui_element2.on_mouse_press(x, y, button, modifiers)
Beispiel #23
0
 def on_mouse_press(self, x, y, _button, _modifiers):
     choice = arcade.get_sprites_at_point((x, y), self.personagem_list)
     if len(choice) > 0:
         if choice[0].tipo == 1:
             self.window.show_view(
                 self.controlador.card_view(Player('assets/yellow')))
         else:
             self.window.show_view(
                 self.controlador.card_view(Player('assets/blue')))
 def on_mouse_press(self, x, y, button, key_modifiers):
     buttons = arcade.get_sprites_at_point((x, y), self.buttons_list)
     if len(buttons) > 0:
         if buttons[0].go_to == 1:
             choice_view = self.controlador.choice_view()
             choice_view.setup()
             self.window.show_view(choice_view)
         elif buttons[0].go_to == 2:
             self.window.show_view(self.controlador.instru_view())
Beispiel #25
0
 def heal(self, x, y, sprite_list):
     if self.dead:
         return
     if (self.healing_state > 0 ):
         self.info = "Healing in cooldown"
         return
     cat_to_heal = arcade.get_sprites_at_point((x, y), sprite_list)
     if len(cat_to_heal) > 0 and cat_to_heal[0].max_health > cat_to_heal[0].health:
         cat_to_heal[0].health = cat_to_heal[0].health + 1 
         self.healing_state = 100
Beispiel #26
0
 def get_point_of_impact(self, spritelist: arcade.SpriteList):
     end_point = None
     points_to_check = self.get_path()
     for point in points_to_check:
         if arcade.get_sprites_at_point(point, spritelist):
             end_point = point
             break
     if end_point:
         return end_point
     return points_to_check[-1]
    def on_mouse_press(self, x, y, button, key_modifiers):
        """Called when the user presses a mouse button."""
        now = datetime.now()
        print('pressed x:{} y:{} @ {}'.format(x, y, now))

        hit_workers = arcade.get_sprites_at_point((x, y), self.workerSprites)
        if len(hit_workers) == 1 and not hit_workers[0].locked:
            arcade.Sound(MUSIC_PREFIX.format('sfx_interface_click.ogg')).play()
            self.heldWorker = hit_workers[0]
            self.worker_start_pos_x = self.heldWorker.center_x
            self.worker_start_pos_y = self.heldWorker.center_y
Beispiel #28
0
    def on_mouse_press(self, x, y, button, modifiers):
        click_list = arcade.get_sprites_at_point((x, y), self.card_list)

        for card in click_list:
            self.card_change_list = arcade.SpriteList()

            card1 = arcade.Sprite("./Img/card/card" +
                                  str(card_img_list[self.card_list.index(card)]) + ".png", 1)
            card1.center_x = card.center_x
            card1.center_y = card.center_y
            self.card_change_list.append(card1)
def apply_damage(skill, engine, x, y, results):
    position = grid_to_pixel(x, y)
    # print(f"{pixel_x}{pixel_y} apply pixel_x_y")
    sprites = arcade.get_sprites_at_point(
        position, engine.cur_level.actor_sprites)

    for sprite in sprites:
        if sprite.fighter and not sprite.is_dead:
            result = sprite.fighter.skill_process(skill)
            if result:
                results.extend(result)
Beispiel #30
0
    def on_mouse_release(self, x: float, y: float, button: int,
                         modifiers: int):
        """ Called when the user presses a mouse button. """

        # If we don't have any cards, who cares
        if self.card_on_press is None:
            return
        if button == arcade.MOUSE_BUTTON_RIGHT:
            return

        # Find the closest pile, in case we are in contact with more than one
        mat_of_new_pile, distance = clientelements.get_minimum_distance_mat(
            self.card_on_press, self.pile_mat_list)
        reset_position = True

        # See if we are in contact with the closest pile
        if arcade.check_for_collision(self.card_on_press, mat_of_new_pile):

            # What pile is it?
            new_pile = mat_of_new_pile.cardpile  #self.pile_mat_list.index(pile)

            #  Is it the same pile we came from?
            old_pile = self.get_pile_for_card(self.card_on_press)
            if new_pile == old_pile:
                cards = arcade.get_sprites_at_point((x, y), new_pile)
                if len(cards) >= 1:
                    primary_card = cards[-1]
                    if primary_card is not None:
                        if primary_card == self.card_on_press:
                            # did not move position
                            if self.card_on_press.active:
                                # if it were active
                                self.card_on_press.active = False
                                self.active_cards.remove(self.card_on_press)
                            else:
                                self.card_on_press.active = True
                                self.active_cards.append(self.card_on_press)
                            self.card_on_press = None
            else:
                self.move_cards(self.held_cards, new_pile)
                for card in self.active_cards:
                    card.active = False
                self.active_cards = []
                # Success, don't reset position of cards
                reset_position = False
        if reset_position:
            # Where-ever we were dropped, it wasn't valid. Reset the each card's position
            # to its original spot.
            for card_index, card in enumerate(self.held_cards):
                card.position = self.held_cards_original_position[card_index]

        # We are no longer holding cards
        self.held_cards = []
        self.held_cards_original_position = []