当前位置:网站首页>小学生学程序---百变服装
小学生学程序---百变服装
2022-07-29 14:56:00 【信息化未来】
小学生作品:




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()
边栏推荐
- The raised platform system based on JSP&Servlet implementation
- NLP自然语言处理-机器学习和自然语言处理介绍(二)
- 数据分析(一)
- 字典树笔记(自用)
- arcpy脚本制作arcgis工具箱注意事项
- 腾讯云数据库负责人林晓斌借1亿炒股:已爆仓破产
- 53 LeetCode 】 【. Most architectural array and
- 令人难以置信的DeepMind数据库现在包括了科学界已知的几乎所有蛋白质
- AVH部署实践 (一) | 在Arm虚拟硬件上部署飞桨模型
- Couldn‘t create temporary file /tmp/apt.conf.uko4Kd for passing config to apt-key
猜你喜欢

Why does APP use the JSON protocol to interact with the server: serialization related knowledge

【IIC通信】Chap.1(I2C)IIC通信原理、IIC读写时序详解

突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易

我裁完兄弟们后,辞职了,转行做了一名小职员

QT通过UDP分包传输大图像(测试可传6M)

LeetCode·739.每日温度·递减栈

深度学习-神经网络

小米法务部:成功打击一处伪造Redmi蓝牙耳机窝点,查扣假冒伪劣产品2032个

NLP自然语言处理-机器学习和自然语言处理介绍(三)

第十九届同济大学程序设计竞赛暨高校网络友谊赛 G-归零(可持久化权值线段树)
随机推荐
uni 的下拉式筛选菜单的功能/图片懒加载
基于C语言仿真实现的粒子火焰系统
基于SSM实现在线聊天系统
【 LeetCode 】 217. Duplicate elements
这个保护数据隐私的赛道,人人都想插一脚,互联网大厂挤破头,连甲方都下场自研了...
自动化配置SSH免密登录和取消SSH免密配置脚本
Numpy
生鲜赛道溃败中存活的本来生活,纠结生存
【 LeetCode 】 566. Reshape the matrix
I/O代码实践
协同多智能体学习的价值分解网络的原理与代码复现
一文详解8086微处理器系统结构
基于C语言实现的LL(1)分析
数字孪生万物可视 |联接现实世界与数字空间
【LeetCode】566. 重塑矩阵
进入中国27年,又一美妆巨头要离场
微服务实战|集中配置中心Config非对称加密与安全管理
从一道面试题说起:GET 请求能传图片吗?
Linux安装MySQL(超详细)
53 LeetCode 】 【. Most architectural array and