1

我正在尝试制作纸牌游戏,但由于某种原因,每次运行代码时,我都会不断收到意外的关键字参数“calculate_hit_box”错误

import arcade

# Screen title and size
SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 768
SCREEN_TITLE = "Bahraini Deal"

# Constants for sizing
CARD_SCALE = 0.6

# How big are the cards?
CARD_WIDTH = 140 * CARD_SCALE
CARD_HEIGHT = 190 * CARD_SCALE

# How big is the mat we'll place the card on?
MAT_PERCENT_OVERSIZE = 1.25
MAT_HEIGHT = int(CARD_HEIGHT * MAT_PERCENT_OVERSIZE)
MAT_WIDTH = int(CARD_WIDTH * MAT_PERCENT_OVERSIZE)

# How much space do we leave as a gap between the mats?
# Done as a percent of the mat size.
VERTICAL_MARGIN_PERCENT = 0.10
HORIZONTAL_MARGIN_PERCENT = 0.10

# The Y of the bottom row (2 piles)
BOTTOM_Y = MAT_HEIGHT / 2 + MAT_HEIGHT * VERTICAL_MARGIN_PERCENT

# The X of where to start putting things on the left side
START_X = MAT_WIDTH / 2 + MAT_WIDTH * HORIZONTAL_MARGIN_PERCENT

# Card constants
CARDS_NAMES = ["City_Center_1" , "Clock_Roundabout_1", "Extra_Play_1", "Its_Friday_1","Just_Say_No_1", "Pay_Me_Rent_BlackGray_1", "Pay_Me_Rent_BrownBlue_1","Pay_Me_Rent_GreenPurple_1",
"Pay_Me_Rent_PinkOrange_1","Pay_Me_Rent_RedYellow_1","Pay_Me_Rent_Mix_1", "Shake_Pockets_1", "Social_Housing_1",
 "Two_More_Cards_1","World_Trade_Center_1", "Zallaq_Sofitel_1"]
CARDS_VALUE = {"City_Center_1" : 4, "Clock_Roundabout_1" : 3, "Extra_Play_1" : 2, "Its_Friday_1":2,"Just_Say_No_1":4, "Pay_Me_Rent_BlackGray_1":1, "Pay_Me_Rent_BrownBlue_1":1,"Pay_Me_Rent_GreenPurple_1":1,
"Pay_Me_Rent_PinkOrange_1":1,"Pay_Me_Rent_RedYellow_1":1,"Pay_Me_Rent_Mix_1":3, "Shake_Pockets_1":3, "Social_Housing_1":2,
 "Two_More_Cards_1":1,"World_Trade_Center_1":4, "Zallaq_Sofitel_1":5}

class Card(arcade.Sprite):
    """ Card sprite """

    def __init__(self, name, scale=1):
        """ Card constructor """

        # Attributes for suit and value
        self.name = name

        # Image to use for the sprite when face up
        self.image_file_name = f":CardsFinal:images/{self.name}.png"

        # Call the parent
        super().__init__(self.image_file_name, scale,calculate_hit_box=False)

class MyGame(arcade.Window):
    """ Main application class. """

    def __init__(self):
        super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

        self.card_list = None

        arcade.set_background_color(arcade.color.FRENCH_SKY_BLUE)


    def setup(self):
        """ Set up the game here. Call this function to restart the game. """
        self.card_list = arcade.SpriteList()

        # Create every card
        for card_name in CARDS_NAMES:
            for card_value in CARDS_VALUE:
                card = Card(card_name, card_value, CARD_SCALE)
                card.position = START_X, BOTTOM_Y
                self.card_list.append(card)

    def on_draw(self):
        """ Render the screen. """
        # Clear the screen
        arcade.start_render()
        # Draw the cards
        self.card_list.draw()

    def on_mouse_press(self, x, y, button, key_modifiers):
        """ Called when the user presses a mouse button. """
        pass

    def on_mouse_release(self, x: float, y: float, button: int,
                         modifiers: int):
        """ Called when the user presses a mouse button. """
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ User moves mouse """
        pass
    




def main():
    """ Main method """
    window = MyGame()
    window.setup()
    arcade.run()


if __name__ == "__main__":
    main()

我已经尝试了多种方法来解决这个问题,但是在修复它的同时,我每次都会把它弄得越来越乱,很明显问题出在 calculate_hit_box 但我不明白为什么?我尝试的每一个灵魂最终都会越来越混乱

4

2 回答 2

1

通过查看 arcade.Sprite源代码,它看起来不像calculate_hit_boxSprite__init__参数之一:

class Sprite:
    def __init__(self,
                 filename: str = None,
                 scale: float = 1,
                 image_x: float = 0, image_y: float = 0,
                 image_width: float = 0, image_height: float = 0,
                 center_x: float = 0, center_y: float = 0,
                 repeat_count_x: int = 1, repeat_count_y: int = 1,
                 flipped_horizontally: bool = False,
                 flipped_vertically: bool = False,
                 flipped_diagonally: bool = False,
                 mirrored: bool = None,
                 hit_box_algorithm: str = "Simple",
                 hit_box_detail: float = 4.5):
# ...

也许它曾经在旧版本的 Arcade 中,如果您遵循旧教程,这将解释混乱。

于 2021-01-27T05:07:24.113 回答
1

calculate_hit_box=False从这里删除:

super().__init__(self.image_file_name, scale,calculate_hit_box=False)

似乎“纸牌”教程中有错误。我为lib创建了一个问题。arcade

于 2021-01-27T10:29:43.473 回答