当前位置:网站首页>小学生学程序---百变服装
小学生学程序---百变服装
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()
边栏推荐
- WOLFLAB一方老师为什么要写网络虚拟化《VMware NSX-T卷2》路由架构-2
- MySQL索引常见面试题(2022版)
- 自动化配置SSH免密登录和取消SSH免密配置脚本
- 广州市应急管理局发布夏季危化品十大安全风险
- 深陷盈利困境,“寒冬”中也要二次递表,北森上市迫切
- [yolov7 series two] positive and negative sample allocation strategy
- 建议尽快优化搜索体验
- 即刻体验 | 借助 CTS-D 进一步提升应用设备兼容性
- AOP实现企业级API访问接口监控(通过Google Guava缓存数据)
- A review of deep learning for beginners!
猜你喜欢

深圳见!云原生加速应用构建专场:来看云原生 FinOps、SRE、高性能计算场景最佳实践

CSP:重庆八中宏帆初级中学校新初二编程社C2024liuyanjia暑假一期集训总结(2/6))

LeetCode·3.无重复字符的最长子串·滑动窗口

即刻体验 | 借助 CTS-D 进一步提升应用设备兼容性

云原生Meetup·广州站举行,共话云原生时代的企业数字化转型

手摸手实现Canal如何接入MySQL实现数据写操作监听

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

双非渣渣的上岸之路!备战60天,三战滴滴侥幸收获Offer

《外太空的莫扎特》

A review of deep learning for beginners!
随机推荐
基于JSP&Servlet实现的众筹平台系统
【LeetCode】1. 两数之和
Introduction to several methods of making custom welcome interface on Weiluntong touch screen
换掉 UUID,更快、更安全!
Linux安装MySQL(超详细)
观光公交题解
【 LeetCode 】 566. Reshape the matrix
The raised platform system based on JSP&Servlet implementation
How to get local json
KDD'22博士论文奖:清华裘捷中成亚洲高校首位获得者,斯坦福Rex Ying获WINNER奖
【LeetCode】350. 两个数组的交集 II
微服务实战|集中配置中心Config非对称加密与安全管理
数据分析(二)
数字孪生万物可视 |联接现实世界与数字空间
C语言 5:bool类型,关系表达式,逻辑表达式,分支语句,函数调用机制,break,continue,goto,return/exit跳转语句
AC自动机笔记与例题整理
微机原理之指令系统和汇编程序设计
分析Nacos配置及源码
突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易
深圳见!云原生加速应用构建专场:来看云原生 FinOps、SRE、高性能计算场景最佳实践