【日常点滴018】Python画兔年生肖,用arcade游戏库画会动的兔子

用arcade游戏库画迎春接福兔子

    • 教学课程代码(分步教学版)
      • 1、构建全局通用代码结构
      • 2、绘制圆弧
      • 3.1、绘制生肖兔(动态调整绘制)
      • 3.2、绘制生肖兔(简化封装)
      • 3.3、绘制生肖兔(添加背景图片和文字)
      • 4、绘制生肖兔(动态旋风腿)
      • 5、添加背景音乐
      • 6、迎春接福玩法实现
      • 7、迎春接福玩法最终进阶

教学课程代码(分步教学版)

实时同步文件:Arcade绘制兔年生肖教学视频课文件
视频教学地址:浪淘三千
(代码和素材是完整的,对应视频也已更新完毕)
以下是静态样式展示:
【日常点滴018】Python画兔年生肖,用arcade游戏库画会动的兔子_第1张图片

1、构建全局通用代码结构

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade

# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        pass

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        pass

    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        print(f"当前点击的坐标是{x,y}")
        pass

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)

    def on_key_release(self, key, modifiers):
        print("---键盘按下了:--",key,"--剩余修饰键编号的和是:---", modifiers)


def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()


2、绘制圆弧

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade

# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False

        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        pass

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)
        # 绘制填充圆弧
        arcade.draw_arc_filled(
                    center_x=self.start_x,  # 弧圆中心点横坐标
                    center_y=self.start_y,  # 弧圆中心点纵坐标
                    width=100,  # 弧圆的宽度
                    height=80,  # 弧圆的高度
                    color=arcade.color.WHITE,  # 颜色
                    start_angle=0,  # 弧的起始角度
                    end_angle=360,  # 弧的结束角度
                    tilt_angle=0,  # 弧的倾斜角
                    num_segments=128,  # 弧由多少线段构成
         )
        arcade.draw_arc_filled(
            center_x=self.start_x + 200 + self.center_x_add,  # 弧圆中心点横坐标
            center_y=self.start_y + self.center_y_add,  # 弧圆中心点纵坐标
            width=100 + self.width_add,  # 弧圆的宽度
            height=80 + self.height_add,  # 弧圆的高度
            color=arcade.color.PINK,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=145,  # 弧的结束角度
            tilt_angle=0 + self.angle_add,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制圆弧
        arcade.draw_arc_outline(
            center_x=self.window.width // 2,  # 中心点横坐标
            center_y=self.window.height // 2+200,  # 中心点纵坐标
            width=100,  # 弧圆的宽度
            height=80,  # 弧圆的高度
            color=arcade.color.WHITE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        arcade.draw_arc_outline(
            center_x=self.window.width // 2 + 200,  # 中心点横坐标
            center_y=self.window.height // 2 + 200,  # 中心点纵坐标
            width=100,  # 弧圆的宽度
            height=80,  # 弧圆的高度
            color=arcade.color.PINK,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=145,  # 弧的结束角度
            border_width=2,  # 弧圆轮廓宽度
            tilt_angle=90,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.button_up_press:
            self.start_y += 1
        if self.button_down_press:
            self.start_y -= 1
        if self.button_left_press:
            self.start_x -= 1
        if self.button_right_press:
            self.start_x += 1
        pass

    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        pass

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True


    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--",key,"--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False


def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()

3.1、绘制生肖兔(动态调整绘制)

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade

# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False
        # shift 键是否按下
        self.button_shift_press = False

        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        pass

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)

        # 绘制填充圆弧 兔身体
        arcade.draw_arc_filled(self.start_x, self.start_y, 160, 150, arcade.color.WHITE, 0, 360)

        # # 绘制填充圆弧 兔头
        arcade.draw_arc_filled(
                    center_x=self.start_x + 0,  # 弧圆中心点横坐标
                    center_y=self.start_y + 80,  # 弧圆中心点纵坐标
                    width=155,  # 弧圆的宽度
                    height=120,  # 弧圆的高度
                    color=arcade.color.WHITE,  # 颜色
                    start_angle=0,  # 弧的起始角度
                    end_angle=360,  # 弧的结束角度
                    tilt_angle=0,  # 弧的倾斜角
                    num_segments=128,  # 弧由多少线段构成
         )
        # 绘制弧线 兔头轮廓
        arcade.draw_arc_outline(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制填充圆弧 兔左眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -6,  # 弧圆的宽度
            height=35 + -5,  # 弧圆的高度
            color=arcade.color.PINK,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔左眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -6,  # 弧圆的宽度
            height=35 + -5,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

        # 绘制填充圆弧 兔右眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -6,  # 弧圆的宽度
            height=35 + -5,  # 弧圆的高度
            color=arcade.color.PINK,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔右眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -6,  # 弧圆的宽度
            height=35 + -5,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.button_up_press:
            self.start_y += 1
        if self.button_down_press:
            self.start_y -= 1
        if self.button_left_press:
            self.start_x -= 1
        if self.button_right_press:
            self.start_x += 1
        pass

    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        # print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        self.center_x_add = x - self.start_x
        self.center_y_add = y - self.start_y

        print(f"self.center_x_add = {self.center_x_add}")
        print(f"self.center_y_add = {self.center_y_add}")

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        self.print_tune()
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
        """ 监听鼠标滚轮事件. """
        print(x, y, scroll_x, scroll_y)

        if self.button_shift_press:
            self.width_add += scroll_y
        else:
            self.height_add += scroll_y
        self.print_tune()

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = True


        tune = -1 if modifiers == 17 else 1
        if key == arcade.key.A:
            # 按下 键盘 A键 修正角度 self.angle_add 加 1 度,  按下 shift+A 减 1 度
            self.angle_add += tune
        elif key == arcade.key.X:
            # 按下 键盘 X键 修正中心点横坐标 self.center_x_add 加 1, 按下 shift+X 减 1
            self.center_x_add += tune
        elif key == arcade.key.Y:
            # 按下 键盘 Y键 修正中心点纵坐标 self.center_y_add 加 1, 按下 shift+Y 减 1
            self.center_y_add += tune

    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--", key, "--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = False

        self.print_tune()

    def print_tune(self):
        # 打印修正的参数
        print(f"self.center_x_add = {self.center_x_add},self.center_y_add = {self.center_y_add},"
              f"self.width_add = {self.width_add},self.height_add = {self.height_add},"
              f"self.angle_add = {self.angle_add}")


def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()


3.2、绘制生肖兔(简化封装)

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade

# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"

# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False
        # shift 键是否按下
        self.button_shift_press = False

        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        pass

    def rabbit_body(self):
        """"兔身体"""
        # 绘制填充圆弧  主要身体部分
        arcade.draw_arc_filled(self.start_x, self.start_y, 160, 150, arcade.color.WHITE, 0, 360)

    def rabbit_head(self):
        """兔头"""
        arcade.draw_arc_filled(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.WHITE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔头轮廓
        arcade.draw_arc_outline(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_eyes(self):
        """兔眼睛"""
        # 绘制填充圆弧 兔左眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.PINK,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔左眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

        # 绘制填充圆弧 兔右眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.PINK,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔右眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_pupil(self):
        """瞳孔绘制"""
        # 绘制左眼珠修饰
        arcade.draw_arc_filled(self.start_x - 38 + 10,  # 中心点横坐标
                               self.start_y + 64 + 23,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

        # 绘制右眼珠修饰
        arcade.draw_arc_filled(self.start_x + 38 - 10,  # 中心点横坐标
                               self.start_y + 64 + 23,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

    def rabbit_cheek(self):
        """发红的腮"""
        # 绘制填充圆弧  兔左脸腮红
        arcade.draw_arc_filled(
            self.start_x - 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)
        # 绘制填充圆弧  兔右脸腮红
        arcade.draw_arc_filled(
            self.start_x + 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)

    def rabbit_ears(self, outline_color=arcade.color.SKY_BLUE,fill_color=arcade.color.CORNFLOWER_BLUE):
        """"兔耳朵"""
        # 绘制填充圆弧  兔左耳朵
        arcade.draw_arc_filled(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 + 9)
        arcade.draw_arc_outline(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 + 9)
        # 绘制填充圆弧  兔右耳朵
        arcade.draw_arc_filled(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 - 9)
        # 绘制圆弧 兔右耳朵轮廓
        arcade.draw_arc_outline(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 - 9)

    def rabbit_middle_ears(self, outline_color=arcade.color.LIGHT_PINK,fill_color=arcade.color.LIGHT_PINK):
        # 绘制填充圆弧  兔左耳内弧
        arcade.draw_arc_filled(
            self.start_x - 50 + 3 - 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + 9)
        # 绘制填充圆弧  兔右耳内弧
        arcade.draw_arc_filled(
            self.start_x + 50 - 3 + 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + -9)

    def rabbit_mouth(self, outline_color=arcade.color.SKY_BLUE):
        """绘制圆弧线 兔嘴巴 微笑#"""
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + 44 + 11,  # 中心点纵坐标
            50,  # 宽度
            50,  # 高度
            outline_color, -135, -45, 2, 0 + 17)

    def lucky_fu_zi(self, outline_color=arcade.color.MIDNIGHT_BLUE, fill_color=arcade.color.RED):
        # 绘制圆弧 制作福字正方形底板和轮廓
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            outline_color, 0, 360, 4, 0, 4)
        arcade.draw_arc_filled(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            fill_color, 0, 360, 0, 4)

        # 利用绘制矩形的方法 绘制福字正方形底板和轮廓
        # arcade.draw_rectangle_filled(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.RED,  # 填充颜色
        #     45 + self.angle_add  # 旋转角度
        # )
        # arcade.draw_rectangle_outline(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.MIDNIGHT_BLUE,  # 填充颜色
        #     1, # 线条宽度
        #     45 + self.angle_add  # 旋转角度
        # )

        # 绘制福字文字
        arcade.Text(text="福", start_x=self.start_x + 0, start_y=self.start_y - 32,
                    color=arcade.color.BLACK, font_size=50 - 16, width=self.window.width, font_name="站酷快乐体2016修订版",
                    bold=True,
                    align="center", anchor_x="center").draw()

    def rabbit_hand(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE):
        """兔 手掌"""
        # 绘制半圆弧 兔子左手掌
        arcade.draw_arc_outline(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, -135, 135, 4, 0 + 0)
        arcade.draw_arc_filled(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, -135, 135, 0 + 0)

        # 绘制半圆弧 兔子右手掌
        arcade.draw_arc_outline(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, 55, 305, 4, 0 + self.angle_add)
        arcade.draw_arc_filled(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, 55, 305, 0 + 0)

    def rabbit_leg(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        # 兔子左腿
        arcade.draw_arc_outline(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

        # 兔子右腿
        arcade.draw_arc_outline(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

    def rabbit_foot(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        """兔脚"""
        # 轮廓弧 兔子左脚
        arcade.draw_arc_outline(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子左脚
        arcade.draw_arc_filled(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0)

        # 轮廓弧 兔子右脚
        arcade.draw_arc_outline(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子右脚
        arcade.draw_arc_filled(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0 )

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)

        # 绘制顺序: 耳朵、腿、上躯干、头、眼睛、腮红、嘴巴、福字、手、脚
        self.rabbit_ears(outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE)
        self.rabbit_middle_ears()
        self.rabbit_leg()
        self.rabbit_body()
        self.rabbit_head()
        self.rabbit_eyes()
        self.rabbit_pupil()
        self.rabbit_cheek()
        self.rabbit_mouth()
        self.lucky_fu_zi()
        self.rabbit_hand()
        self.rabbit_foot()

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.button_up_press:
            self.start_y += 1
        if self.button_down_press:
            self.start_y -= 1
        if self.button_left_press:
            self.start_x -= 1
        if self.button_right_press:
            self.start_x += 1
        pass

    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        # print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        self.center_x_add = x - self.start_x
        self.center_y_add = y - self.start_y

        print(f"self.center_x_add = {self.center_x_add}")
        print(f"self.center_y_add = {self.center_y_add}")

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        self.print_tune()
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
        """ 监听鼠标滚轮事件. """
        print(x, y, scroll_x, scroll_y)

        if self.button_shift_press:
            self.width_add += scroll_y
        else:
            self.height_add += scroll_y
        self.print_tune()

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = True


        tune = -1 if modifiers == 17 else 1
        if key == arcade.key.A:
            # 按下 键盘 A键 修正角度 self.angle_add 加 1 度,  按下 shift+A 减 1 度
            self.angle_add += tune
        elif key == arcade.key.X:
            # 按下 键盘 X键 修正中心点横坐标 self.center_x_add 加 1, 按下 shift+X 减 1
            self.center_x_add += tune
        elif key == arcade.key.Y:
            # 按下 键盘 Y键 修正中心点纵坐标 self.center_y_add 加 1, 按下 shift+Y 减 1
            self.center_y_add += tune

    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--", key, "--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = False

        self.print_tune()

    def print_tune(self):
        # 打印修正的参数
        print(f"self.center_x_add = {self.center_x_add},self.center_y_add = {self.center_y_add},"
              f"self.width_add = {self.width_add},self.height_add = {self.height_add},"
              f"self.angle_add = {self.angle_add}")


def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()


3.3、绘制生肖兔(添加背景图片和文字)

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade

# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"

arcade.load_font(path="../../字体文件/站酷快乐体.ttf")


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False
        # shift 键是否按下
        self.button_shift_press = False

        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        """功能准备工作"""
        self.up_name = arcade.Text("主讲UP: 浪淘三千", self.window.width // 4 * 3, self.window.height // 4 * 1,
                                   color=arcade.color.SAE, font_size=20, width=500, font_name="站酷快乐体2016修订版",
                                   bold=True, align="center", anchor_x="center", multiline=False)
        self.blessing_word = arcade.Text("迎 春 接 福", self.window.width // 4 * 3, self.window.height // 6 * 2,
                                         color=arcade.color.SAE, font_size=40, width=500, font_name="站酷快乐体2016修订版",
                                         bold=True, align="center", anchor_x="center", multiline=False)
        # 背景图片 当作精灵加载进来
        self.background_image = arcade.Sprite("../../图片文件/烟花背景.jpg")
        # 设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2

    def rabbit_body(self):
        """"兔身体"""
        # 绘制填充圆弧  主要身体部分
        arcade.draw_arc_filled(self.start_x, self.start_y, 160, 150, arcade.color.WHITE, 0, 360)

    def rabbit_head(self):
        """兔头"""
        arcade.draw_arc_filled(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.WHITE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔头轮廓
        arcade.draw_arc_outline(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_eyes(self):
        """兔眼睛"""
        # 绘制填充圆弧 兔左眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔左眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

        # 绘制填充圆弧 兔右眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔右眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_pupil(self):
        """瞳孔绘制"""
        # 绘制左眼珠修饰
        arcade.draw_arc_filled(self.start_x - 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

        # 绘制右眼珠修饰
        arcade.draw_arc_filled(self.start_x + 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

    def rabbit_cheek(self):
        """发红的腮"""
        # 绘制填充圆弧  兔左脸腮红
        arcade.draw_arc_filled(
            self.start_x - 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)
        # 绘制填充圆弧  兔右脸腮红
        arcade.draw_arc_filled(
            self.start_x + 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)

    def rabbit_ears(self, outline_color=arcade.color.SKY_BLUE,fill_color=arcade.color.CORNFLOWER_BLUE):
        """"兔耳朵"""
        # 绘制填充圆弧  兔左耳朵
        arcade.draw_arc_filled(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 + 9)
        arcade.draw_arc_outline(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 + 9)
        # 绘制填充圆弧  兔右耳朵
        arcade.draw_arc_filled(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 - 9)
        # 绘制圆弧 兔右耳朵轮廓
        arcade.draw_arc_outline(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 - 9)

    def rabbit_middle_ears(self, outline_color=arcade.color.LIGHT_PINK,fill_color=arcade.color.LIGHT_PINK):
        # 绘制填充圆弧  兔左耳内弧
        arcade.draw_arc_filled(
            self.start_x - 50 + 3 - 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + 9)
        # 绘制填充圆弧  兔右耳内弧
        arcade.draw_arc_filled(
            self.start_x + 50 - 3 + 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + -9)

    def rabbit_mouth(self, outline_color=arcade.color.SKY_BLUE):
        """绘制圆弧线 兔嘴巴 微笑#"""
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + 44 + 11,  # 中心点纵坐标
            50,  # 宽度
            50,  # 高度
            outline_color, -135, -45, 2, 0 + 17)

    def lucky_fu_zi(self, outline_color=arcade.color.MIDNIGHT_BLUE, fill_color=arcade.color.RED):
        # 绘制圆弧 制作福字正方形底板和轮廓
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            outline_color, 0, 360, 4, 0, 4)
        arcade.draw_arc_filled(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            fill_color, 0, 360, 0, 4)

        # 利用绘制矩形的方法 绘制福字正方形底板和轮廓
        # arcade.draw_rectangle_filled(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.RED,  # 填充颜色
        #     45 + self.angle_add  # 旋转角度
        # )
        # arcade.draw_rectangle_outline(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.MIDNIGHT_BLUE,  # 填充颜色
        #     1, # 线条宽度
        #     45 + self.angle_add  # 旋转角度
        # )

        # 绘制福字文字
        arcade.Text(text="福", start_x=self.start_x + 0, start_y=self.start_y - 32,
                    color=arcade.color.BLACK, font_size=50 - 16, width=self.window.width, font_name="站酷快乐体2016修订版",
                    bold=True,
                    align="center", anchor_x="center").draw()

    def rabbit_hand(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE):
        """兔 手掌"""
        # 绘制半圆弧 兔子左手掌
        arcade.draw_arc_outline(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, -135, 135, 4, 0 + 0)
        arcade.draw_arc_filled(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, -135, 135, 0 + 0)

        # 绘制半圆弧 兔子右手掌
        arcade.draw_arc_outline(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, 55, 305, 4, 0 + self.angle_add)
        arcade.draw_arc_filled(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, 55, 305, 0 + 0)

    def rabbit_leg(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        # 兔子左腿
        arcade.draw_arc_outline(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

        # 兔子右腿
        arcade.draw_arc_outline(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

    def rabbit_foot(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        """兔脚"""
        # 轮廓弧 兔子左脚
        arcade.draw_arc_outline(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子左脚
        arcade.draw_arc_filled(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0)

        # 轮廓弧 兔子右脚
        arcade.draw_arc_outline(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子右脚
        arcade.draw_arc_filled(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0 )

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)
        self.background_image.draw()
        self.up_name.draw()
        self.blessing_word.draw()
        # 绘制顺序: 耳朵、腿、上躯干、头、眼睛、腮红、嘴巴、福字、手、脚
        self.rabbit_ears(outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE)
        self.rabbit_middle_ears()
        self.rabbit_leg()
        self.rabbit_body()
        self.rabbit_head()
        self.rabbit_eyes()
        self.rabbit_pupil()
        self.rabbit_cheek()
        self.rabbit_mouth()
        self.lucky_fu_zi()
        self.rabbit_hand()
        self.rabbit_foot()

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.button_up_press:
            self.start_y += 1
        if self.button_down_press:
            self.start_y -= 1
        if self.button_left_press:
            self.start_x -= 1
        if self.button_right_press:
            self.start_x += 1
        pass

    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        # print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        self.center_x_add = x - self.start_x
        self.center_y_add = y - self.start_y

        print(f"self.center_x_add = {self.center_x_add}")
        print(f"self.center_y_add = {self.center_y_add}")

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        self.print_tune()
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
        """ 监听鼠标滚轮事件. """
        print(x, y, scroll_x, scroll_y)

        if self.button_shift_press:
            self.width_add += scroll_y
        else:
            self.height_add += scroll_y
        self.print_tune()

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = True


        tune = -1 if modifiers == 17 else 1
        if key == arcade.key.A:
            # 按下 键盘 A键 修正角度 self.angle_add 加 1 度,  按下 shift+A 减 1 度
            self.angle_add += tune
        elif key == arcade.key.X:
            # 按下 键盘 X键 修正中心点横坐标 self.center_x_add 加 1, 按下 shift+X 减 1
            self.center_x_add += tune
        elif key == arcade.key.Y:
            # 按下 键盘 Y键 修正中心点纵坐标 self.center_y_add 加 1, 按下 shift+Y 减 1
            self.center_y_add += tune

    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--", key, "--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = False

        self.print_tune()

    def print_tune(self):
        # 打印修正的参数
        print(f"self.center_x_add = {self.center_x_add},self.center_y_add = {self.center_y_add},"
              f"self.width_add = {self.width_add},self.height_add = {self.height_add},"
              f"self.angle_add = {self.angle_add}")


def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()


4、绘制生肖兔(动态旋风腿)

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade

# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"

arcade.load_font(path="../../字体文件/站酷快乐体.ttf")


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False
        # shift 键是否按下
        self.button_shift_press = False
        # 腿在运动时的转动角度
        self.leg_angle = 0

        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        """功能准备工作"""
        self.up_name = arcade.Text("主讲UP: 浪淘三千", self.window.width // 4 * 3, self.window.height // 4 * 1,
                                   color=arcade.color.SAE, font_size=20, width=500, font_name="站酷快乐体2016修订版",
                                   bold=True, align="center", anchor_x="center", multiline=False)
        self.blessing_word = arcade.Text("迎 春 接 福", self.window.width // 4 * 3, self.window.height // 6 * 2,
                                         color=arcade.color.SAE, font_size=40, width=500, font_name="站酷快乐体2016修订版",
                                         bold=True, align="center", anchor_x="center", multiline=False)
        # 背景图片 当作精灵加载进来
        self.background_image = arcade.Sprite("../../图片文件/烟花背景.jpg")
        # 设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2



    def rabbit_body(self):
        """"兔身体"""
        # 绘制填充圆弧  主要身体部分
        arcade.draw_arc_filled(self.start_x, self.start_y, 160, 150, arcade.color.WHITE, 0, 360)

    def rabbit_head(self):
        """兔头"""
        arcade.draw_arc_filled(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.WHITE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔头轮廓
        arcade.draw_arc_outline(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_eyes(self):
        """兔眼睛"""
        # 绘制填充圆弧 兔左眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔左眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

        # 绘制填充圆弧 兔右眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔右眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_pupil(self):
        """瞳孔绘制"""
        # 绘制左眼珠修饰
        arcade.draw_arc_filled(self.start_x - 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

        # 绘制右眼珠修饰
        arcade.draw_arc_filled(self.start_x + 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

    def rabbit_cheek(self):
        """发红的腮"""
        # 绘制填充圆弧  兔左脸腮红
        arcade.draw_arc_filled(
            self.start_x - 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)
        # 绘制填充圆弧  兔右脸腮红
        arcade.draw_arc_filled(
            self.start_x + 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)

    def rabbit_ears(self, outline_color=arcade.color.SKY_BLUE,fill_color=arcade.color.CORNFLOWER_BLUE):
        """"兔耳朵"""
        # 绘制填充圆弧  兔左耳朵
        arcade.draw_arc_filled(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 + 9)
        arcade.draw_arc_outline(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 + 9)
        # 绘制填充圆弧  兔右耳朵
        arcade.draw_arc_filled(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 - 9)
        # 绘制圆弧 兔右耳朵轮廓
        arcade.draw_arc_outline(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 - 9)

    def rabbit_middle_ears(self, outline_color=arcade.color.LIGHT_PINK,fill_color=arcade.color.LIGHT_PINK):
        # 绘制填充圆弧  兔左耳内弧
        arcade.draw_arc_filled(
            self.start_x - 50 + 3 - 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + 9)
        # 绘制填充圆弧  兔右耳内弧
        arcade.draw_arc_filled(
            self.start_x + 50 - 3 + 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + -9)

    def rabbit_mouth(self, outline_color=arcade.color.SKY_BLUE):
        """绘制圆弧线 兔嘴巴 微笑#"""
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + 44 + 11,  # 中心点纵坐标
            50,  # 宽度
            50,  # 高度
            outline_color, -135, -45, 2, 0 + 17)

    def lucky_fu_zi(self, outline_color=arcade.color.MIDNIGHT_BLUE, fill_color=arcade.color.RED):
        # 绘制圆弧 制作福字正方形底板和轮廓
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            outline_color, 0, 360, 4, 0, 4)
        arcade.draw_arc_filled(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            fill_color, 0, 360, 0, 4)

        # 利用绘制矩形的方法 绘制福字正方形底板和轮廓
        # arcade.draw_rectangle_filled(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.RED,  # 填充颜色
        #     45 + self.angle_add  # 旋转角度
        # )
        # arcade.draw_rectangle_outline(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.MIDNIGHT_BLUE,  # 填充颜色
        #     1, # 线条宽度
        #     45 + self.angle_add  # 旋转角度
        # )

        # 绘制福字文字
        arcade.Text(text="福", start_x=self.start_x + 0, start_y=self.start_y - 32,
                    color=arcade.color.BLACK, font_size=50 - 16, width=self.window.width, font_name="站酷快乐体2016修订版",
                    bold=True,
                    align="center", anchor_x="center").draw()

    def rabbit_hand(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE):
        """兔 手掌"""
        # 绘制半圆弧 兔子左手掌
        arcade.draw_arc_outline(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, -135, 135, 4, 0 + 0)
        arcade.draw_arc_filled(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, -135, 135, 0 + 0)

        # 绘制半圆弧 兔子右手掌
        arcade.draw_arc_outline(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, 55, 305, 4, 0 + self.angle_add)
        arcade.draw_arc_filled(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, 55, 305, 0 + 0)

    def rabbit_leg(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        # 兔子左腿
        arcade.draw_arc_outline(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

        # 兔子右腿
        arcade.draw_arc_outline(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

    def rabbit_foot(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        """兔脚"""
        # 轮廓弧 兔子左脚
        arcade.draw_arc_outline(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子左脚
        arcade.draw_arc_filled(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0)

        # 轮廓弧 兔子右脚
        arcade.draw_arc_outline(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子右脚
        arcade.draw_arc_filled(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0 )

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)
        self.background_image.draw()
        self.up_name.draw()
        self.blessing_word.draw()
        # 绘制顺序: 耳朵、腿、上躯干、头、眼睛、腮红、嘴巴、福字、手、脚
        self.rabbit_ears(outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE)
        self.rabbit_middle_ears()
        self.rabbit_leg(angle=self.leg_angle)
        self.rabbit_body()
        self.rabbit_head()
        self.rabbit_eyes()
        self.rabbit_pupil()
        self.rabbit_cheek()
        self.rabbit_mouth()
        self.lucky_fu_zi()
        self.rabbit_hand()
        self.rabbit_foot()

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.button_up_press:
            self.start_y += 1
        if self.button_down_press:
            self.start_y -= 1
        if self.button_left_press:
            self.start_x -= 1
            self.leg_angle += 15
        if self.button_right_press:
            self.start_x += 1
            self.leg_angle -= 10


    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        # print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        self.center_x_add = x - self.start_x
        self.center_y_add = y - self.start_y

        print(f"self.center_x_add = {self.center_x_add}")
        print(f"self.center_y_add = {self.center_y_add}")

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        self.print_tune()
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
        """ 监听鼠标滚轮事件. """
        print(x, y, scroll_x, scroll_y)

        if self.button_shift_press:
            self.width_add += scroll_y
        else:
            self.height_add += scroll_y
        self.print_tune()

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = True


        tune = -1 if modifiers == 17 else 1
        if key == arcade.key.A:
            # 按下 键盘 A键 修正角度 self.angle_add 加 1 度,  按下 shift+A 减 1 度
            self.angle_add += tune
        elif key == arcade.key.X:
            # 按下 键盘 X键 修正中心点横坐标 self.center_x_add 加 1, 按下 shift+X 减 1
            self.center_x_add += tune
        elif key == arcade.key.Y:
            # 按下 键盘 Y键 修正中心点纵坐标 self.center_y_add 加 1, 按下 shift+Y 减 1
            self.center_y_add += tune

    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--", key, "--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = False

        self.print_tune()

    def on_resize(self, width: int, height: int):

        # 重新设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2
        # 重新设置精灵素材宽度和高度
        self.background_image.width = self.window.width
        self.background_image.height = self.window.height

    def print_tune(self):
        # 打印修正的参数
        print(f"self.center_x_add = {self.center_x_add},self.center_y_add = {self.center_y_add},"
              f"self.width_add = {self.width_add},self.height_add = {self.height_add},"
              f"self.angle_add = {self.angle_add}")


def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()


5、添加背景音乐

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade

# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"

arcade.load_font(path="../../字体文件/站酷快乐体.ttf")


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False
        # shift 键是否按下
        self.button_shift_press = False
        # 腿在运动时的转动角度
        self.leg_angle = 0
        # 背景音乐
        self.background_music = None

        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        """功能准备工作"""
        self.up_name = arcade.Text("主讲UP: 浪淘三千", self.window.width // 4 * 3, self.window.height // 4 * 1,
                                   color=arcade.color.SAE, font_size=20, width=500, font_name="站酷快乐体2016修订版",
                                   bold=True, align="center", anchor_x="center", multiline=False)
        self.blessing_word = arcade.Text("迎 春 接 福", self.window.width // 4 * 3, self.window.height // 6 * 2,
                                         color=arcade.color.SAE, font_size=40, width=500, font_name="站酷快乐体2016修订版",
                                         bold=True, align="center", anchor_x="center", multiline=False)
        # 背景图片 当作精灵加载进来
        self.background_image = arcade.Sprite("../../图片文件/烟花背景.jpg")
        # 设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2
        # 背景音乐
        self.background_music = arcade.Sound("../../声音文件/春节背景音乐.mp3", streaming=True)
        # 播放背景音乐
        self.background_music.play(volume=0.01)



    def rabbit_body(self):
        """"兔身体"""
        # 绘制填充圆弧  主要身体部分
        arcade.draw_arc_filled(self.start_x, self.start_y, 160, 150, arcade.color.WHITE, 0, 360)

    def rabbit_head(self):
        """兔头"""
        arcade.draw_arc_filled(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.WHITE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔头轮廓
        arcade.draw_arc_outline(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_eyes(self):
        """兔眼睛"""
        # 绘制填充圆弧 兔左眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔左眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

        # 绘制填充圆弧 兔右眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔右眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_pupil(self):
        """瞳孔绘制"""
        # 绘制左眼珠修饰
        arcade.draw_arc_filled(self.start_x - 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

        # 绘制右眼珠修饰
        arcade.draw_arc_filled(self.start_x + 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

    def rabbit_cheek(self):
        """发红的腮"""
        # 绘制填充圆弧  兔左脸腮红
        arcade.draw_arc_filled(
            self.start_x - 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)
        # 绘制填充圆弧  兔右脸腮红
        arcade.draw_arc_filled(
            self.start_x + 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)

    def rabbit_ears(self, outline_color=arcade.color.SKY_BLUE,fill_color=arcade.color.CORNFLOWER_BLUE):
        """"兔耳朵"""
        # 绘制填充圆弧  兔左耳朵
        arcade.draw_arc_filled(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 + 9)
        arcade.draw_arc_outline(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 + 9)
        # 绘制填充圆弧  兔右耳朵
        arcade.draw_arc_filled(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 - 9)
        # 绘制圆弧 兔右耳朵轮廓
        arcade.draw_arc_outline(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 - 9)

    def rabbit_middle_ears(self, outline_color=arcade.color.LIGHT_PINK,fill_color=arcade.color.LIGHT_PINK):
        # 绘制填充圆弧  兔左耳内弧
        arcade.draw_arc_filled(
            self.start_x - 50 + 3 - 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + 9)
        # 绘制填充圆弧  兔右耳内弧
        arcade.draw_arc_filled(
            self.start_x + 50 - 3 + 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + -9)

    def rabbit_mouth(self, outline_color=arcade.color.SKY_BLUE):
        """绘制圆弧线 兔嘴巴 微笑#"""
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + 44 + 11,  # 中心点纵坐标
            50,  # 宽度
            50,  # 高度
            outline_color, -135, -45, 2, 0 + 17)

    def lucky_fu_zi(self, outline_color=arcade.color.MIDNIGHT_BLUE, fill_color=arcade.color.RED):
        # 绘制圆弧 制作福字正方形底板和轮廓
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            outline_color, 0, 360, 4, 0, 4)
        arcade.draw_arc_filled(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            fill_color, 0, 360, 0, 4)

        # 利用绘制矩形的方法 绘制福字正方形底板和轮廓
        # arcade.draw_rectangle_filled(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.RED,  # 填充颜色
        #     45 + self.angle_add  # 旋转角度
        # )
        # arcade.draw_rectangle_outline(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.MIDNIGHT_BLUE,  # 填充颜色
        #     1, # 线条宽度
        #     45 + self.angle_add  # 旋转角度
        # )

        # 绘制福字文字
        arcade.Text(text="福", start_x=self.start_x + 0, start_y=self.start_y - 32,
                    color=arcade.color.BLACK, font_size=50 - 16, width=self.window.width, font_name="站酷快乐体2016修订版",
                    bold=True,
                    align="center", anchor_x="center").draw()

    def rabbit_hand(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE):
        """兔 手掌"""
        # 绘制半圆弧 兔子左手掌
        arcade.draw_arc_outline(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, -135, 135, 4, 0 + 0)
        arcade.draw_arc_filled(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, -135, 135, 0 + 0)

        # 绘制半圆弧 兔子右手掌
        arcade.draw_arc_outline(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, 55, 305, 4, 0 + self.angle_add)
        arcade.draw_arc_filled(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, 55, 305, 0 + 0)

    def rabbit_leg(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        # 兔子左腿
        arcade.draw_arc_outline(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

        # 兔子右腿
        arcade.draw_arc_outline(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

    def rabbit_foot(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        """兔脚"""
        # 轮廓弧 兔子左脚
        arcade.draw_arc_outline(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子左脚
        arcade.draw_arc_filled(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0)

        # 轮廓弧 兔子右脚
        arcade.draw_arc_outline(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子右脚
        arcade.draw_arc_filled(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0 )

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)
        self.background_image.draw()
        self.up_name.draw()
        self.blessing_word.draw()
        # 绘制顺序: 耳朵、腿、上躯干、头、眼睛、腮红、嘴巴、福字、手、脚
        self.rabbit_ears(outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE)
        self.rabbit_middle_ears()
        self.rabbit_leg(angle=self.leg_angle)
        self.rabbit_body()
        self.rabbit_head()
        self.rabbit_eyes()
        self.rabbit_pupil()
        self.rabbit_cheek()
        self.rabbit_mouth()
        self.lucky_fu_zi()
        self.rabbit_hand()
        self.rabbit_foot()

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.button_up_press:
            self.start_y += 1
        if self.button_down_press:
            self.start_y -= 1
        if self.button_left_press:
            self.start_x -= 1
            self.leg_angle += 15
        if self.button_right_press:
            self.start_x += 1
            self.leg_angle -= 10


    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        # print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        self.center_x_add = x - self.start_x
        self.center_y_add = y - self.start_y

        print(f"self.center_x_add = {self.center_x_add}")
        print(f"self.center_y_add = {self.center_y_add}")

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        self.print_tune()
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
        """ 监听鼠标滚轮事件. """
        print(x, y, scroll_x, scroll_y)

        if self.button_shift_press:
            self.width_add += scroll_y
        else:
            self.height_add += scroll_y
        self.print_tune()

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = True


        tune = -1 if modifiers == 17 else 1
        if key == arcade.key.A:
            # 按下 键盘 A键 修正角度 self.angle_add 加 1 度,  按下 shift+A 减 1 度
            self.angle_add += tune
        elif key == arcade.key.X:
            # 按下 键盘 X键 修正中心点横坐标 self.center_x_add 加 1, 按下 shift+X 减 1
            self.center_x_add += tune
        elif key == arcade.key.Y:
            # 按下 键盘 Y键 修正中心点纵坐标 self.center_y_add 加 1, 按下 shift+Y 减 1
            self.center_y_add += tune

    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--", key, "--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = False

        self.print_tune()

    def on_resize(self, width: int, height: int):

        # 重新设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2
        # 重新设置精灵素材宽度和高度
        self.background_image.width = self.window.width
        self.background_image.height = self.window.height

    def print_tune(self):
        # 打印修正的参数
        print(f"self.center_x_add = {self.center_x_add},self.center_y_add = {self.center_y_add},"
              f"self.width_add = {self.width_add},self.height_add = {self.height_add},"
              f"self.angle_add = {self.angle_add}")

def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()


6、迎春接福玩法实现

"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade
import random
# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"

arcade.load_font(path="../../字体文件/站酷快乐体.ttf")


class LuckyFu:

    def __init__(self):
        self.fuzi_list = arcade.SpriteList()
        self.fuzi_hit_sound = arcade.sound.load_sound(":resources:sounds/coin2.wav")
        self.creat_fu_zi()

    def creat_fu_zi(self,start_x=500,start_y=600):
        for i in range(5):
            fu_zi = arcade.create_text_sprite(
                text="福", start_x=start_x, start_y=start_y, color=arcade.color.LIGHT_PINK,
                font_size=20, width=30, align='left',
                font_name="../../字体文件/站酷快乐体.ttf",bold=False, italic=False,
                anchor_x='left', anchor_y='baseline', rotation=0)
            fu_zi.center_x = random.randint(0, start_x)
            fu_zi.center_y = random.randint(start_y, start_y+200)
            fu_zi.change_y = - random.randint(1, 3)
            fu_zi.change_angle = random.randint(-5, 5)

            self.fuzi_list.append(fu_zi)

    def update(self):
        for fu in self.fuzi_list:
            fu.center_x += fu.change_x
            fu.center_y += fu.change_y
            fu.angle += fu.change_angle


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False
        # shift 键是否按下
        self.button_shift_press = False
        # 腿在运动时的转动角度
        self.leg_angle = 0
        # 背景音乐
        self.background_music = None
        # 福字精灵对象
        self.lucky_fu = None
        # 游戏胜利图片
        self.game_win_pic = None
        # 游戏失败图片
        self.game_over_pic = None
        # 玩家得分
        self.player_score = None
        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        """功能准备工作"""
        self.up_name = arcade.Text("主讲UP: 浪淘三千", self.window.width // 4 * 3, self.window.height // 4 * 1,
                                   color=arcade.color.SAE, font_size=30, width=500, font_name="站酷快乐体2016修订版",
                                   bold=True, align="center", anchor_x="center", multiline=False)
        self.blessing_word = arcade.Text("迎 春 接 福", self.window.width // 4 * 3, self.window.height // 6 * 2,
                                         color=arcade.color.SAE, font_size=40, width=500, font_name="站酷快乐体2016修订版",
                                         bold=True, align="center", anchor_x="center", multiline=False)
        # 背景图片 当作精灵加载进来
        self.background_image = arcade.Sprite("../../图片文件/烟花背景.jpg")
        # 设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2
        # 背景音乐
        self.background_music = arcade.Sound("../../声音文件/春节背景音乐.mp3", streaming=True)
        # 播放背景音乐
        self.background_music.play(volume=0.01)
        # 实例化福字精灵类
        self.lucky_fu = LuckyFu()
        # 玩家得分
        self.player_score = 0

    def rabbit_body(self):
        """"兔身体"""
        # 绘制填充圆弧  主要身体部分
        arcade.draw_arc_filled(self.start_x, self.start_y, 160, 150, arcade.color.WHITE, 0, 360)

    def rabbit_head(self):
        """兔头"""
        arcade.draw_arc_filled(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.WHITE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔头轮廓
        arcade.draw_arc_outline(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_eyes(self):
        """兔眼睛"""
        # 绘制填充圆弧 兔左眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔左眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

        # 绘制填充圆弧 兔右眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔右眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_pupil(self):
        """瞳孔绘制"""
        # 绘制左眼珠修饰
        arcade.draw_arc_filled(self.start_x - 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

        # 绘制右眼珠修饰
        arcade.draw_arc_filled(self.start_x + 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

    def rabbit_cheek(self):
        """发红的腮"""
        # 绘制填充圆弧  兔左脸腮红
        arcade.draw_arc_filled(
            self.start_x - 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)
        # 绘制填充圆弧  兔右脸腮红
        arcade.draw_arc_filled(
            self.start_x + 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)

    def rabbit_ears(self, outline_color=arcade.color.SKY_BLUE,fill_color=arcade.color.CORNFLOWER_BLUE):
        """"兔耳朵"""
        # 绘制填充圆弧  兔左耳朵
        arcade.draw_arc_filled(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 + 9)
        arcade.draw_arc_outline(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 + 9)
        # 绘制填充圆弧  兔右耳朵
        arcade.draw_arc_filled(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 - 9)
        # 绘制圆弧 兔右耳朵轮廓
        arcade.draw_arc_outline(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 - 9)

    def rabbit_middle_ears(self, outline_color=arcade.color.LIGHT_PINK,fill_color=arcade.color.LIGHT_PINK):
        # 绘制填充圆弧  兔左耳内弧
        arcade.draw_arc_filled(
            self.start_x - 50 + 3 - 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + 9)
        # 绘制填充圆弧  兔右耳内弧
        arcade.draw_arc_filled(
            self.start_x + 50 - 3 + 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + -9)

    def rabbit_mouth(self, outline_color=arcade.color.SKY_BLUE):
        """绘制圆弧线 兔嘴巴 微笑#"""
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + 44 + 11,  # 中心点纵坐标
            50,  # 宽度
            50,  # 高度
            outline_color, -135, -45, 2, 0 + 17)

    def lucky_fu_zi(self, outline_color=arcade.color.MIDNIGHT_BLUE, fill_color=arcade.color.RED):
        # 绘制圆弧 制作福字正方形底板和轮廓
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            outline_color, 0, 360, 4, 0, 4)
        arcade.draw_arc_filled(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            fill_color, 0, 360, 0, 4)

        # 利用绘制矩形的方法 绘制福字正方形底板和轮廓
        # arcade.draw_rectangle_filled(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.RED,  # 填充颜色
        #     45 + self.angle_add  # 旋转角度
        # )
        # arcade.draw_rectangle_outline(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.MIDNIGHT_BLUE,  # 填充颜色
        #     1, # 线条宽度
        #     45 + self.angle_add  # 旋转角度
        # )

        # 绘制福字文字
        arcade.Text(text="福", start_x=self.start_x + 0, start_y=self.start_y - 32,
                    color=arcade.color.BLACK, font_size=50 - 16, width=self.window.width, font_name="站酷快乐体2016修订版",
                    bold=True,
                    align="center", anchor_x="center").draw()

    def rabbit_hand(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE):
        """兔 手掌"""
        # 绘制半圆弧 兔子左手掌
        arcade.draw_arc_outline(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, -135, 135, 4, 0 + 0)
        arcade.draw_arc_filled(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, -135, 135, 0 + 0)

        # 绘制半圆弧 兔子右手掌
        arcade.draw_arc_outline(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, 55, 305, 4, 0 + self.angle_add)
        arcade.draw_arc_filled(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, 55, 305, 0 + 0)

    def rabbit_leg(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        # 兔子左腿
        arcade.draw_arc_outline(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

        # 兔子右腿
        arcade.draw_arc_outline(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

    def rabbit_foot(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        """兔脚"""
        # 轮廓弧 兔子左脚
        arcade.draw_arc_outline(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子左脚
        arcade.draw_arc_filled(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0)

        # 轮廓弧 兔子右脚
        arcade.draw_arc_outline(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子右脚
        arcade.draw_arc_filled(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0 )

    def draw_game_info(self,score):
        arcade.Text(str(score), 50, self.window.height - 100,
                   color=arcade.color.WHITE, font_size=30, width=500, font_name="站酷快乐体2016修订版",
                   bold=True, align="center", anchor_x="center", multiline=False).draw()

    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)
        self.background_image.draw()
        self.up_name.draw()
        self.blessing_word.draw()
        # 绘制顺序: 耳朵、腿、上躯干、头、眼睛、腮红、嘴巴、福字、手、脚
        self.rabbit_ears(outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE)
        self.rabbit_middle_ears()
        self.rabbit_leg(angle=self.leg_angle)
        self.rabbit_body()
        self.rabbit_head()
        self.rabbit_eyes()
        self.rabbit_pupil()
        self.rabbit_cheek()
        self.rabbit_mouth()
        self.lucky_fu_zi()
        self.rabbit_hand()
        self.rabbit_foot()
        self.lucky_fu.fuzi_list.draw()
        self.draw_game_info(self.player_score)

    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.button_up_press:
            self.start_y += 3
        if self.button_down_press:
            self.start_y -= 3
        if self.button_left_press:
            self.start_x -= 3
            self.leg_angle += 15
        if self.button_right_press:
            self.start_x += 3
            self.leg_angle -= 10
        self.lucky_fu.update()

        for fu_zi in self.lucky_fu.fuzi_list:
            if fu_zi.center_x in range(self.start_x-80, self.start_x+80) \
                    and (fu_zi.center_y - self.start_y) in range(0, 200):

                self.lucky_fu.fuzi_list.remove(fu_zi)
                print("撞击了", len(self.lucky_fu.fuzi_list))
                self.player_score += 1
                self.lucky_fu.fuzi_hit_sound.play()
            if fu_zi.center_y < 0:
                self.lucky_fu.fuzi_list.remove(fu_zi)
                print("消失了", len(self.lucky_fu.fuzi_list))
            if len(self.lucky_fu.fuzi_list) <= 2:
                self.lucky_fu.creat_fu_zi(self.window.width,self.window.height)


    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        # print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        self.center_x_add = x - self.start_x
        self.center_y_add = y - self.start_y

        print(f"self.center_x_add = {self.center_x_add}")
        print(f"self.center_y_add = {self.center_y_add}")

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        self.print_tune()
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
        """ 监听鼠标滚轮事件. """
        print(x, y, scroll_x, scroll_y)

        if self.button_shift_press:
            self.width_add += scroll_y
        else:
            self.height_add += scroll_y
        self.print_tune()

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = True

        tune = -1 if modifiers == 17 else 1
        if key == arcade.key.A:
            # 按下 键盘 A键 修正角度 self.angle_add 加 1 度,  按下 shift+A 减 1 度
            self.angle_add += tune
        elif key == arcade.key.X:
            # 按下 键盘 X键 修正中心点横坐标 self.center_x_add 加 1, 按下 shift+X 减 1
            self.center_x_add += tune
        elif key == arcade.key.Y:
            # 按下 键盘 Y键 修正中心点纵坐标 self.center_y_add 加 1, 按下 shift+Y 减 1
            self.center_y_add += tune

    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--", key, "--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = False

        self.print_tune()

    def on_resize(self, width: int, height: int):

        # 重新设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2
        # 重新设置精灵素材宽度和高度
        self.background_image.width = self.window.width
        self.background_image.height = self.window.height

    def print_tune(self):
        # 打印修正的参数
        print(f"self.center_x_add = {self.center_x_add},self.center_y_add = {self.center_y_add},"
              f"self.width_add = {self.width_add},self.height_add = {self.height_add},"
              f"self.angle_add = {self.angle_add}")

def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()


7、迎春接福玩法最终进阶


"""
本代码只用一个绘制圆弧的方法, 绘制了兔子所有的部位,十分容易理解
当基础功能学会以后,可以教大家平面地图文件的绘制和使用 制作更丰富精彩的游戏场景
视频教学地址,会陆续更新 https://space.bilibili.com/455954948
"""
import arcade
import random
# 常量 窗口大小和标题
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Arcade 游戏教学"

arcade.load_font(path="../../字体文件/站酷快乐体.ttf")


class LuckyFu:

    def __init__(self):
        self.fuzi_list = arcade.SpriteList()
        self.fuzi_hit_sound = arcade.sound.load_sound(":resources:sounds/coin2.wav")
        self.creat_fu_zi()

    def creat_fu_zi(self,start_x=500,start_y=600):
        for i in range(5):
            fu_zi = arcade.create_text_sprite(
                text="福", start_x=start_x, start_y=start_y, color=arcade.color.LIGHT_PINK,
                font_size=20, width=30, align='left',
                font_name="../../字体文件/站酷快乐体.ttf",bold=False, italic=False,
                anchor_x='left', anchor_y='baseline', rotation=0)
            fu_zi.center_x = random.randint(0, start_x)
            fu_zi.center_y = random.randint(start_y, start_y+200)
            fu_zi.change_y = - random.randint(1, 3)
            fu_zi.change_angle = random.randint(-5, 5)

            self.fuzi_list.append(fu_zi)

    def update(self):
        for fu in self.fuzi_list:
            fu.center_x += fu.change_x
            fu.center_y += fu.change_y
            fu.angle += fu.change_angle

class Qiong:

    def __init__(self):
        self.qiong_zi_list = arcade.SpriteList()
        self.qiong_zi_hit_sound = arcade.sound.load_sound(":resources:sounds/hit4.wav")
        self.creat_qiong_zi()

    def creat_qiong_zi(self,start_x=700,start_y=500):
        for i in range(1):
            qiong_zi = arcade.create_text_sprite(
                text="穷", start_x=start_x, start_y=start_y, color=arcade.color.BLACK,
                font_size=30, width=30, align='left',
                font_name="../../字体文件/站酷快乐体.ttf",bold=False, italic=False,
                anchor_x='left', anchor_y='baseline', rotation=0)
            qiong_zi.center_x = start_x
            qiong_zi.center_y = start_y
            qiong_zi.change_angle = random.randint(-5, 5)
            self.qiong_zi_list.append(qiong_zi)
        print(len(self.qiong_zi_list))

    def update(self,target_x,target_y):
        for qiong in self.qiong_zi_list:
            qiong.center_x += 0.5 if qiong.center_x < target_x else -0.5
            qiong.center_y += 0.5 if qiong.center_y < target_y else -0.5
            qiong.angle += qiong.change_angle


# arcade_game_202301 用基础圆弧绘制兔子
class LuckyRabbit(arcade.View):
    """ 视图程序,用于在窗体内展示. """

    def __init__(self):
        # 初始化父类的属性
        super().__init__()
        # 所有绘制图形的参照点
        self.start_x = 400
        self.start_y = 300
        # 用于绘制过程中的动态修正
        self.center_x_add = 0  # 修正中心点横坐标
        self.center_y_add = 0  # 修正中心点纵坐标
        self.width_add = 0  # 修正宽度
        self.height_add = 0  # 修正高度
        self.angle_add = 0  # 修正倾斜角度

        # 上下左右四个按键是否被按下的状态
        self.button_left_press = False
        self.button_right_press = False
        self.button_up_press = False
        self.button_down_press = False
        # shift 键是否按下
        self.button_shift_press = False
        # 腿在运动时的转动角度
        self.leg_angle = 0
        # 背景音乐
        self.background_music = None
        # 福字精灵对象
        self.lucky_fu = None
        # 游戏胜利图片
        self.game_win_pic = None
        # 游戏胜利音乐
        self.game_win_sound = None
        # 游戏失败图片
        self.game_over_pic = None
        # 游戏失败音乐
        self.game_over_sound = None
        # 玩家得分
        self.player_score = None
        # 玩家用时
        self.player_use_time = None
        # 游戏限时
        self.game_limit_time = None
        # 穷字精灵对象
        self.qiong_class = None # 游戏状态(停止或开始)
        self.game_status = None

        # 在初始化时调用的一些准备工作代码
        self.set_up()

    def set_up(self):
        """ 进行一些游戏准备工作,让游戏主逻辑从这开始,以便于在有需要时重开游戏. """
        """功能准备工作"""
        self.up_name = arcade.Text("主讲UP: 浪淘三千", self.window.width // 4 * 3, self.window.height // 4 * 1,
                                   color=arcade.color.SAE, font_size=30, width=500, font_name="站酷快乐体2016修订版",
                                   bold=True, align="center", anchor_x="center", multiline=False)
        self.blessing_word = arcade.Text("迎 春 接 福", self.window.width // 4 * 3, self.window.height // 6 * 2,
                                         color=arcade.color.SAE, font_size=40, width=500, font_name="站酷快乐体2016修订版",
                                         bold=True, align="center", anchor_x="center", multiline=False)
        # 背景图片 当作精灵加载进来
        self.background_image = arcade.Sprite("../../图片文件/烟花背景.jpg")
        # 设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2
        # 背景音乐
        self.background_music = arcade.Sound("../../声音文件/春节背景音乐.mp3", streaming=True)
        # 播放背景音乐
        self.background_music.play(volume=0.01)
        # 实例化福字精灵类
        self.lucky_fu = LuckyFu()
        # 游戏胜利图片
        self.game_win_pic = arcade.Sprite("../../图片文件/win.png")
        # 游戏胜利音乐
        self.game_win_sound = arcade.sound.load_sound("../../声音文件/shengli.mp3")
        # 游戏失败图片
        self.game_over_pic = arcade.Sprite("../../图片文件/game_over.png")
        # 游戏失败音乐
        self.game_over_sound = arcade.sound.load_sound(":resources:sounds/gameover2.wav")
        # 玩家得分
        self.player_score = 0
        # 玩家用时
        self.player_use_time = 0
        # 游戏限时
        self.game_limit_time = 10
        # 实例化穷字精灵
        self.qiong_class = Qiong()
        # 游戏状态(停止或开始)
        self.game_status = True
        # 有规律的调用time_clock函数,每次调用间隔设置为1秒
        arcade.schedule(self.time_clock, 1)



    def rabbit_body(self):
        """"兔身体"""
        # 绘制填充圆弧  主要身体部分
        arcade.draw_arc_filled(self.start_x, self.start_y, 160, 150, arcade.color.WHITE, 0, 360)

    def rabbit_head(self):
        """兔头"""
        arcade.draw_arc_filled(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.WHITE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔头轮廓
        arcade.draw_arc_outline(
            center_x=self.start_x + 0,  # 弧圆中心点横坐标
            center_y=self.start_y + 80,  # 弧圆中心点纵坐标
            width=155,  # 弧圆的宽度
            height=120,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_eyes(self):
        """兔眼睛"""
        # 绘制填充圆弧 兔左眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔左眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + -40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

        # 绘制填充圆弧 兔右眼睛
        arcade.draw_arc_filled(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.CORNFLOWER_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )
        # 绘制弧线 兔右眼睛轮廓  待填充弧形绘制完后,复制参数即可
        arcade.draw_arc_outline(
            center_x=self.start_x + 40,  # 弧圆中心点横坐标
            center_y=self.start_y + 90,  # 弧圆中心点纵坐标
            width=25 + -12,  # 弧圆的宽度
            height=35 + -10,  # 弧圆的高度
            color=arcade.color.SKY_BLUE,  # 颜色
            start_angle=0,  # 弧的起始角度
            border_width=2,  # 弧圆轮廓宽度
            end_angle=360,  # 弧的结束角度
            tilt_angle=0 + 0,  # 弧的倾斜角
            num_segments=128,  # 弧由多少线段构成
        )

    def rabbit_pupil(self):
        """瞳孔绘制"""
        # 绘制左眼珠修饰
        arcade.draw_arc_filled(self.start_x - 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

        # 绘制右眼珠修饰
        arcade.draw_arc_filled(self.start_x + 40,  # 中心点横坐标
                               self.start_y + 90,  # 中心点纵坐标
                               5,  # 宽度
                               5,  # 高度
                               arcade.color.WHITE, 0, 360, 0 + 0)

    def rabbit_cheek(self):
        """发红的腮"""
        # 绘制填充圆弧  兔左脸腮红
        arcade.draw_arc_filled(
            self.start_x - 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)
        # 绘制填充圆弧  兔右脸腮红
        arcade.draw_arc_filled(
            self.start_x + 51,  # 中心点横坐标
            self.start_y + 64,  # 中心点纵坐标
            12,  # 宽度
            12,  # 高度
            arcade.color.TOMATO, 0, 360, 0)

    def rabbit_ears(self, outline_color=arcade.color.SKY_BLUE,fill_color=arcade.color.CORNFLOWER_BLUE):
        """"兔耳朵"""
        # 绘制填充圆弧  兔左耳朵
        arcade.draw_arc_filled(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 + 9)
        arcade.draw_arc_outline(
            self.start_x - 50 + 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 + 9)
        # 绘制填充圆弧  兔右耳朵
        arcade.draw_arc_filled(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            fill_color, 0, 360, 0 - 9)
        # 绘制圆弧 兔右耳朵轮廓
        arcade.draw_arc_outline(
            self.start_x + 50 - 3,  # 中心点横坐标
            self.start_y + 130 + 28,  # 中心点纵坐标
            60 + -10,  # 宽度
            150 + -38,  # 高度
            outline_color, 0, 360, 2, 0 - 9)

    def rabbit_middle_ears(self, outline_color=arcade.color.LIGHT_PINK,fill_color=arcade.color.LIGHT_PINK):
        # 绘制填充圆弧  兔左耳内弧
        arcade.draw_arc_filled(
            self.start_x - 50 + 3 - 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + 9)
        # 绘制填充圆弧  兔右耳内弧
        arcade.draw_arc_filled(
            self.start_x + 50 - 3 + 1,  # 中心点横坐标
            self.start_y + 130 + 28 + 6,  # 中心点纵坐标
            15 + 2,  # 宽度
            35 + 29,  # 高度
            fill_color, 0, 360, 0 + -9)

    def rabbit_mouth(self, outline_color=arcade.color.SKY_BLUE):
        """绘制圆弧线 兔嘴巴 微笑#"""
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + 44 + 11,  # 中心点纵坐标
            50,  # 宽度
            50,  # 高度
            outline_color, -135, -45, 2, 0 + 17)

    def lucky_fu_zi(self, outline_color=arcade.color.MIDNIGHT_BLUE, fill_color=arcade.color.RED):
        # 绘制圆弧 制作福字正方形底板和轮廓
        arcade.draw_arc_outline(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            outline_color, 0, 360, 4, 0, 4)
        arcade.draw_arc_filled(
            self.start_x + 0,  # 中心点横坐标
            self.start_y + -12,  # 中心点纵坐标
            70,  # 宽度
            70,  # 高度
            fill_color, 0, 360, 0, 4)

        # 利用绘制矩形的方法 绘制福字正方形底板和轮廓
        # arcade.draw_rectangle_filled(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.RED,  # 填充颜色
        #     45 + self.angle_add  # 旋转角度
        # )
        # arcade.draw_rectangle_outline(
        #     self.start_x + 0,  # 中心点横坐标
        #     self.start_y + -12,  # 中心点纵坐标
        #     70 + -15,  # 宽度
        #     70 + -15,  # 高度
        #     arcade.color.MIDNIGHT_BLUE,  # 填充颜色
        #     1, # 线条宽度
        #     45 + self.angle_add  # 旋转角度
        # )

        # 绘制福字文字
        arcade.Text(text="福", start_x=self.start_x + 0, start_y=self.start_y - 32,
                    color=arcade.color.BLACK, font_size=50 - 16, width=self.window.width, font_name="站酷快乐体2016修订版",
                    bold=True,
                    align="center", anchor_x="center").draw()

    def rabbit_hand(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE):
        """兔 手掌"""
        # 绘制半圆弧 兔子左手掌
        arcade.draw_arc_outline(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, -135, 135, 4, 0 + 0)
        arcade.draw_arc_filled(
            self.start_x - 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, -135, 135, 0 + 0)

        # 绘制半圆弧 兔子右手掌
        arcade.draw_arc_outline(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            outline_color, 55, 305, 4, 0 + self.angle_add)
        arcade.draw_arc_filled(
            self.start_x + 46,  # 中心点横坐标
            self.start_y - 11,  # 中心点纵坐标
            35,  # 宽度
            25,  # 高度
            fill_color, 55, 305, 0 + 0)

    def rabbit_leg(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        # 兔子左腿
        arcade.draw_arc_outline(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x - 50 + 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

        # 兔子右腿
        arcade.draw_arc_outline(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            outline_color, 0, 360, 5, 0 + angle, 12)
        arcade.draw_arc_filled(
            self.start_x + 50 - 12,  # 中心点横坐标
            self.start_y - 99 + 11,  # 中心点纵坐标
            40 + 0,  # 宽度
            100 + 25,  # 高度
            fill_color, 0, 360, 0 + angle, 12)

    def rabbit_foot(self, outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE,angle=0):
        """兔脚"""
        # 轮廓弧 兔子左脚
        arcade.draw_arc_outline(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子左脚
        arcade.draw_arc_filled(
            self.start_x - 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0)

        # 轮廓弧 兔子右脚
        arcade.draw_arc_outline(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            outline_color, 0, 360, 2, 0)
        # 填充弧 兔子右脚
        arcade.draw_arc_filled(
            self.start_x + 40 +angle,  # 中心点横坐标
            self.start_y - 140,  # 中心点纵坐标
            50 + 6,  # 宽度
            50 + 0-angle,  # 高度
            fill_color, 0, 360, 0 )

    def draw_game_info(self,score):
        arcade.Text(f"分数:{str(score)}/10", 180, self.window.height - 100,
                   color=arcade.color.WHITE, font_size=30, width=500, font_name="站酷快乐体2016修订版",
                   bold=True, align="center", anchor_x="center", multiline=False).draw()
        arcade.Text(f"剩余时间:{str(self.game_limit_time-self.player_use_time)}/{self.game_limit_time}", 180, self.window.height - 200,
                    color=arcade.color.WHITE, font_size=30, width=500, font_name="站酷快乐体2016修订版",
                    bold=True, align="center", anchor_x="center", multiline=False).draw()

    # 括号里的这个参数必须写,他是一个时间间隔,代表上次调用 到本次调用之间的时间差 不严格等于我们设置的1秒
    def time_clock(self,delta_time):
        # print(delta_time)
        # 因为我们要更改TIME_CLOCK的值,所以使用global 让函数可以改变这个全局变量
        if self.game_status and self.player_use_time<self.game_limit_time:
            self.player_use_time += 1


    # 画面渲染绘制
    def on_draw(self):
        """ 负责渲染画面 速率: 60帧/秒. """
        # 清除上一帧绘制的画面
        self.clear()
        # 设置背景颜色 黑色
        arcade.set_background_color(arcade.color.BLACK)
        self.background_image.draw()
        self.up_name.draw()
        self.blessing_word.draw()
        # 绘制顺序: 耳朵、腿、上躯干、头、眼睛、腮红、嘴巴、福字、手、脚
        self.rabbit_ears(outline_color=arcade.color.SKY_BLUE, fill_color=arcade.color.WHITE)
        self.rabbit_middle_ears()
        self.rabbit_leg(angle=self.leg_angle)
        self.rabbit_body()
        self.rabbit_head()
        self.rabbit_eyes()
        self.rabbit_pupil()
        self.rabbit_cheek()
        self.rabbit_mouth()
        self.lucky_fu_zi()
        self.rabbit_hand()
        self.rabbit_foot()
        self.lucky_fu.fuzi_list.draw()
        self.draw_game_info(self.player_score)
        self.qiong_class.qiong_zi_list.draw()
        if not self.game_status and self.player_score < 10:
            self.game_over_pic.center_x = self.window.width//2
            self.game_over_pic.center_y = self.window.height//2
            self.game_over_pic.draw()
        if self.player_score >= 10:
            self.game_win_pic.center_x = self.window.width//2
            self.game_win_pic.center_y = self.window.height//2
            self.game_win_pic.draw()


    # 控制每次刷新时的变化
    def on_update(self, delta_time: float):
        """ 负责逻辑变化 速率: 60帧/秒. """
        if self.game_status:
            if self.button_up_press:
                self.start_y += 3
            if self.button_down_press:
                self.start_y -= 3
            if self.button_left_press:
                self.start_x -= 3
                self.leg_angle += 15
            if self.button_right_press:
                self.start_x += 3
                self.leg_angle -= 10
            self.lucky_fu.update()

            for fu_zi in self.lucky_fu.fuzi_list:
                if fu_zi.center_x in range(self.start_x-80, self.start_x+80) \
                        and (fu_zi.center_y - self.start_y) in range(0, 200):
                    self.lucky_fu.fuzi_list.remove(fu_zi)
                    print("撞击了", len(self.lucky_fu.fuzi_list))
                    self.player_score += 1
                    self.lucky_fu.fuzi_hit_sound.play()
                if fu_zi.center_y < 0:
                    self.lucky_fu.fuzi_list.remove(fu_zi)
                    print("消失了", len(self.lucky_fu.fuzi_list))
                if len(self.lucky_fu.fuzi_list) <= 2:
                    self.lucky_fu.creat_fu_zi(self.window.width,self.window.height)
            self.qiong_class.update(self.start_x,self.start_y)
            # 穷字的碰撞检测
            for qiong_zi in self.qiong_class.qiong_zi_list:
                if qiong_zi.center_x - self.start_x in range(-80, 80) \
                        and (qiong_zi.center_y - self.start_y) in range(-120, 160):
                    print("撞击了", len(self.qiong_class.qiong_zi_list))
                    self.game_status = False
                    self.qiong_class.qiong_zi_hit_sound.play()
                    self.game_over_sound.play()
                    break
            if self.player_score >= 10:
                self.game_win_sound.play()
                self.game_status = False
            if self.player_use_time - self.game_limit_time >=0:
                self.game_over_sound.play()
                self.game_status = False

    def on_mouse_press(self, x, y, button, modifiers):
        """ 监听鼠标点击事件. """
        mouse_buttons = {1: "左键", 2: "中键", 3: "右键"}
        # print(f"当前点击的坐标是{x, y}")
        # print(f"相对起点(x,y)需要位移:{(x - self.start_x, y - self.start_y)}")
        self.center_x_add = x - self.start_x
        self.center_y_add = y - self.start_y

        print(f"self.center_x_add = {self.center_x_add}")
        print(f"self.center_y_add = {self.center_y_add}")

    def on_mouse_release(self, x: float, y: float, button: int, modifiers: int):
        """ 监听鼠标释放事件. """
        self.print_tune()
        pass

    def on_mouse_motion(self, x: float, y: float, dx: float, dy: float):
        """ 监听鼠标移动事件 """
        pass

    def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
        """ 监听鼠标滚轮事件. """
        print(x, y, scroll_x, scroll_y)

        if self.button_shift_press:
            self.width_add += scroll_y
        else:
            self.height_add += scroll_y
        self.print_tune()

    def on_key_press(self,key, modifiers):
        """监听键盘按键点击事件
        modifiers:None = 16,shift= 1(17) ctrl= 2(18) alt= 4(20) """
        print("---键盘按下了:--",key,"--修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = True
        elif key == arcade.key.RIGHT:
            self.button_right_press = True
        elif key == arcade.key.UP:
            self.button_up_press = True
        elif key == arcade.key.DOWN:
            self.button_down_press = True
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = True

        tune = -1 if modifiers == 17 else 1
        if key == arcade.key.A:
            # 按下 键盘 A键 修正角度 self.angle_add 加 1 度,  按下 shift+A 减 1 度
            self.angle_add += tune
        elif key == arcade.key.X:
            # 按下 键盘 X键 修正中心点横坐标 self.center_x_add 加 1, 按下 shift+X 减 1
            self.center_x_add += tune
        elif key == arcade.key.Y:
            # 按下 键盘 Y键 修正中心点纵坐标 self.center_y_add 加 1, 按下 shift+Y 减 1
            self.center_y_add += tune

    def on_key_release(self, key, modifiers):
        print("---键盘释放了:--", key, "--剩余修饰键编号的和是:---", modifiers)
        if key == arcade.key.LEFT:
            self.button_left_press = False
        elif key == arcade.key.RIGHT:
            self.button_right_press = False
        elif key == arcade.key.UP:
            self.button_up_press = False
        elif key == arcade.key.DOWN:
            self.button_down_press = False
        elif key == arcade.key.LSHIFT:
            self.button_shift_press = False

        self.print_tune()

    def on_resize(self, width: int, height: int):

        # 重新设置精灵素材中心点的位置
        self.background_image.center_x = self.window.width // 2
        self.background_image.center_y = self.window.height // 2
        # 重新设置精灵素材宽度和高度
        self.background_image.width = self.window.width
        self.background_image.height = self.window.height

    def print_tune(self):
        # 打印修正的参数
        print(f"self.center_x_add = {self.center_x_add},self.center_y_add = {self.center_y_add},"
              f"self.width_add = {self.width_add},self.height_add = {self.height_add},"
              f"self.angle_add = {self.angle_add}")


def main():
    # 设置窗体的宽、高、名字、是否支持缩放
    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
    # 设置窗体的 logo 图标
    import pyglet
    window.set_icon(pyglet.image.load('../图片文件/浪淘三千.png'))
    # 实例化定义的某个窗体
    start_view = LuckyRabbit()
    # 设置当前应该显示哪个窗体
    window.show_view(start_view)
    # 保持程序持续运行
    arcade.run()


if __name__ == "__main__":
    main()

你可能感兴趣的:(arcade记录,python,游戏,arcade,兔子,绘图)