• 小学生学程序---百变服装


    小学生作品:

     

     


    from pgzrun import *
    from random import *
    from ai import *
    music.play("nice.mp3") 

    WIDTH = 960
    HEIGHT = 720

    # 下行代码得到去除背景后的人像
    image_style_trans("图片.png")

    #创建开始界面和按钮
    start = Actor("start.jpg")
    c_girl = Actor("c_girl.png", [715, 580])
    c_boy = Actor("c_boy.png", [245, 580])

    # 修改19行代码坐标,调整头部位置
    head = Actor("新图片.png", [270, 173])
    girl = Actor("girl.png", [478, 383])
    bg = Actor("bg7.png")
    coat = Actor("coat7.png", [479, 311])
    pants = Actor("pants7.png", [476, 462])
    shoes = Actor("shoes7.png", [484, 586])

    # 修改27行代码坐标,调整头部位置
    b_head = Actor("新图片.png", [475, 170])
    boy = Actor("boy.png", [480, 375])
    b_bg = Actor("b_bg7.png")
    b_coat = Actor("b_coat7.png", [481, 313])
    b_pants = Actor("b_pants7.png", [482, 448])
    b_shoes = Actor("b_shoes7.png", [483, 562])

    #定义变量
    state = "begin" #游戏状态
    mode = None #男女模式

    #女生换装
    #{
    #换上衣   
    coat_num = 0
    def girl_coat():
        global coat_num
        coat.image = "coat" + str(coat_num) + ".png"
        coat_num = coat_num + 1
        if coat_num > 7:
            coat_num = 0

    #换裤子
    pants_num = 0
    def girl_pants():
        global pants_num
        pants.image = "pants" + str(pants_num) + ".png"
        pants_num = pants_num + 1
        if pants_num > 7:
            pants_num = 0

    #换鞋
    shoes_num = 0
    def girl_shoes():
        global shoes_num
        shoes.image = "shoes" + str(shoes_num) + ".png"
        shoes_num = shoes_num + 1
        if shoes_num > 7:
            shoes_num = 0

    #换背景
    bg_num = 0
    def girl_bg():
        global bg_num
        bg.image = "bg" + str(bg_num) + ".png"
        bg_num = bg_num + 1
        if bg_num > 7:
            bg_num = 0

    #随机换装
    def girl_change():
        coat.image = "coat" + str(randint(0,7)) + ".png"
        pants.image = "pants" + str(randint(0,7)) + ".png"
        shoes.image = "shoes" + str(randint(0,7)) + ".png"
        bg.image = "bg" + str(randint(0,7)) + ".png"
    #}

    #男生换装
    #{
    #换上衣   
    coat_num = 0
    def boy_coat():
        global coat_num
        print(coat_num)
        b_coat.image = "b_coat" + str(coat_num) + ".png"
        coat_num = coat_num + 1
        if coat_num > 7:
            coat_num = 0

    #换裤子
    pants_num = 0
    def boy_pants():
        global pants_num
        b_pants.image = "b_pants" + str(pants_num) + ".png"
        pants_num = pants_num + 1
        if pants_num > 7:
            pants_num = 0

    #换鞋
    shoes_num = 0
    def boy_shoes():
        global shoes_num
        b_shoes.image = "b_shoes" + str(shoes_num) + ".png"
        shoes_num = shoes_num + 1
        if shoes_num > 7:
            shoes_num = 0

    #换背景
    bg_num = 0
    def boy_bg():
        global bg_num
        b_bg.image = "b_bg" + str(bg_num) + ".png"
        bg_num = bg_num + 1
        if bg_num > 7:
            bg_num = 0

    #随机换装
    def boy_change():
        b_coat.image = "b_coat" + str(randint(0,7)) + ".png"
        b_pants.image = "b_pants" + str(randint(0,7)) + ".png"
        b_shoes.image = "b_shoes" + str(randint(0,7)) + ".png"
        b_bg.image = "b_bg" + str(randint(0,7)) + ".png"
    #}  

    #绘制角色       
    def draw():
        screen.clear()
        if state == "begin":
            start.draw()
            c_girl.draw()
            c_boy.draw()
        if state == "run":
            #任务3作答区域
            if mode == "girl":
                #绘制女生角色
                #{
                bg.draw()
                girl.draw()
                head.draw()
                pants.draw()
                coat.draw()
                shoes.draw()#}
            if mode == "boy":
                #绘制男生角色
                #{
                b_bg.draw()
                boy.draw()
                b_head.draw()
                b_pants.draw()
                b_coat.draw()
                b_shoes.draw()#}

     
    def on_mouse_down(pos):
        global state, mode
        if c_girl.collidepoint(pos):
            state = "run"
            #任务2作答区域
            mode = "girl"
        elif c_boy.collidepoint(pos):
            state = "run"
            mode = "boy"


    #根据模式进行换装
    #{    
        if mode == "girl":
            if coat.collidepoint(pos):
                girl_coat() 
            elif pants.collidepoint(pos):
                girl_pants()
            elif shoes.collidepoint(pos):
                girl_shoes()
            else:
                girl_bg()
        
        if mode == "boy":
            if b_coat.collidepoint(pos):
                boy_coat() 
            elif b_pants.collidepoint(pos):
                boy_pants()
            elif b_shoes.collidepoint(pos):
                boy_shoes()
            else:
                boy_bg()
    #}
        
    def on_key_down():
        #一键换装
        if keyboard.space == True:
            if mode == "girl":
                girl_change()
            if mode == "boy":
                boy_change()
        #保存图片
        if keyboard.s == True:
            save()

    go()

  • 相关阅读:
    【Python】论文中常用的Matplotlib画图(三)
    MySQL事务
    ElasticSearch - 索引库和文档相关命令操作
    施工小能手路边石混凝土成型机的工艺原理
    window.print() 前端页面打印与预览PDF
    三十分钟学会zookeeper
    Navicat历史版本下载及地址组成分析
    VoLTE端到端业务详解 | VoLTE基本概念
    【穿透科技】P2P穿透模块介绍
    python 微信公众号,微信小程序wechatpy的使用
  • 原文地址:https://blog.csdn.net/fqfq123456/article/details/126042276