Ошибка: module 'arcade' has no attribute 'recolor_image'

treq

Новичок
Пользователь
Апр 6, 2023
1
0
1
При запуске кода выводится ошибка module 'arcade' has no attribute 'recolor_image'
Python:
import arcade


SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
MOVEMENT_SPEED = 5
JUMP_SPEED = 10

class Platformer(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height, "Platformer")
        arcade.set_background_color(arcade.color.AMAZON)

        self.player_sprite = None
        self.wall_list = None
        self.coin_list = None
        self.score = 0

    def setup(self):
        self.wall_list = arcade.SpriteList()
        self.coin_list = arcade.SpriteList()
        self.score = 0

        # Загрузка изображений для спрайтов
        self.player_sprite = arcade.Sprite("images/player.png", 0.5)
        self.player_sprite.center_x = 100
        self.player_sprite.center_y = 100

        # Создание "стен"
        wall_coordinates = [
            (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 - 150, 400, 20),
            (SCREEN_WIDTH // 2 - 300, SCREEN_HEIGHT // 2 - 50, 20, 100),
            (SCREEN_WIDTH // 2 + 200, SCREEN_HEIGHT // 2 - 50, 20, 100),
            (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 100, 400, 20)
        ]
        for x, y, width, height in wall_coordinates:
            wall = arcade.SpriteSolidColor(width, height, arcade.color.BLACK)
            wall.center_x = x
            wall.center_y = y
            self.wall_list.append(wall)

        # Создание "монеток"
        coin_coordinates = [
            (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2 + 50),
            (SCREEN_WIDTH // 2 - 150, SCREEN_HEIGHT // 2 - 100),
            (SCREEN_WIDTH // 2 + 150, SCREEN_HEIGHT // 2 - 100),
        ]
        for x, y in coin_coordinates:
            coin = arcade.Sprite("images/coin.png", 0.5)
            coin.center_x = x
            coin.center_y = y
            self.coin_list.append(coin)

        self.physics_engine = arcade.PhysicsEnginePlatformer(
            self.player_sprite, self.wall_list, gravity_constant=1.2
        )

    def on_draw(self):
        arcade.start_render()
        self.wall_list.draw()
        self.coin_list.draw()
        self.player_sprite.draw()
        arcade.draw_text(
            f"Score: {self.score}", SCREEN_WIDTH - 70, SCREEN_HEIGHT - 30,
            arcade.color.WHITE, 22
        )

    def on_key_press(self, key, modifiers):
        if key == arcade.key.LEFT:
            self.player_sprite.change_x = -MOVEMENT_SPEED
        elif key == arcade.key.RIGHT:
            self.player_sprite.change_x = MOVEMENT_SPEED
        elif key == arcade.key.SPACE and self.physics_engine.can_jump():
            self.player_sprite.change_y = JUMP_SPEED

    def on_key_release(self, key, modifiers):
        if key == arcade.key.LEFT or key == arcade.key.RIGHT:
            self.player_sprite.change_x = 0

    def update(self, delta_time):
        self.physics_engine.update()

        coins_hit_list = arcade.check_for_collision_with_list(
            self.player_sprite, self.coin_list
        )
        for coin in coins_hit_list:
            coin.remove_from_sprite_lists()
            self.score += 1

        if self.player_sprite.bottom < 0:
            arcade.recolor_image(
                "images/player.png", arcade.color.RED, [32, 255, 32]
            )
            arcade.play_sound(arcade.sound.BEEP, 0.5)
            self.setup()
        elif arcade.check_for_collision_with_list(
            self.player_sprite, self.wall_list
        ):
            arcade.recolor_image(
                "images/player.png", arcade.color.RED, [32, 255, 32]
            )
            arcade.play_sound(arcade.sound.BEEP, 0.5)
            self.setup()

        if self.score == 3:
            arcade.recolor_image(
                "images/player.png", arcade.color.YELLOW, [32, 255, 32]
            )
            arcade.play_sound(arcade.sound.POWERUP, 0.5)
            self.setup()


def main():
    game = Platformer(SCREEN_WIDTH, SCREEN_HEIGHT)
    game.setup()
    arcade.run()

if __name__ == "__main__":
    main()
Операционная система windows, python версия 3.10.4, версия arcade 2.6.17
 

Форум IT Специалистов