当前位置:网站首页>小学生学程序---百变服装
小学生学程序---百变服装
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()
边栏推荐
- 文本处理之xml
- 基于C语言实现一个社交系统
- 稳稳当当的生活
- 数据挖掘场景-发票虚开
- 53 LeetCode 】 【. Most architectural array and
- Flink SQL Hudi 实战
- Why does APP use the JSON protocol to interact with the server: serialization related knowledge
- 数据中台建设(四):企业构建数据中台评估
- 双线机房、多线机房、BGP机房的关系和对比
- Zhaoqi Technology creates a platform for overseas high-level talent introduction, corporate project docking, and event roadshows
猜你喜欢
随机推荐
使用Xshell和Xftp7跑学校服务器记录
深陷盈利困境,“寒冬”中也要二次递表,北森上市迫切
SkiaSharp 之 WPF 自绘 弹动小球(案例版)
小米法务部:成功打击一处伪造Redmi蓝牙耳机窝点,查扣假冒伪劣产品2032个
即时通讯-改变社交与工作状态的新型软件
协同多智能体学习的价值分解网络的原理与代码复现
MySQL Index Common Interview Questions (2022 Edition)
超好用的PC端录屏软件推荐
手摸手实现Canal如何接入MySQL实现数据写操作监听
MySQL索引常见面试题(2022版)
数据中台建设(四):企业构建数据中台评估
这个保护数据隐私的赛道,人人都想插一脚,互联网大厂挤破头,连甲方都下场自研了...
文本处理之xml
数据分析(一)
工作效率-十五分钟让你快速学习Markdown语法到精通排版实践备忘
ArcGIS Molder Builder模型构建器基本知识
LeetCode·3.无重复字符的最长子串·滑动窗口
Mysql数据库及表的建立
Flink SQL Hudi 实战
【深度学习】深度学习刷SOTA的一堆trick









