猫史档案馆


【Python作品分享】cloakroom2【作品秀】

用户:你的小宝贝srWi你的小宝贝srWi查看:0 回复:1 评论:0 创建时间:2020-06-14T15:45:59


【作品展示】

center_image

 

【作品介绍】

用鼠标点击头发,可以换发型,用鼠标点击衣服,可以换衣服,用鼠标点击鞋子,可以换鞋子,用鼠标点击整套换装,可以换整套,用鼠标点击随机换装,就可以随便换装。

 

【作品源代码】

import pgzrun
import random

WIDTH = 620
HEIGHT = 900

girl = Actor("co")
girl.pos = 300,450

hair_style = ['hair_1', 'hair_2', 'hair_3', 'hair_4']
hair = Actor("hair_1")
hair.pos = 317,369
dress_style = ['dress_1', 'dress_2', 'dress_3', 'dress_4']
dress = Actor('dress_1')
dress.pos = 313, 553
shoes_style = ['shoes_1', 'shoes_2', 'shoes_3', 'shoes_4']
shoes = Actor('shoes_1')
shoes.pos = 313, 680

button1 = Actor("rand")
button1.pos = 500,100
button2 = Actor("match")
button2.pos = 100,100

def draw():
    screen.blit('background',(0,0))
    girl.draw()
    hair.draw()
    dress.draw()
    shoes.draw()
    button1.draw()
    button2.draw()

def changestyle(obj,stylelist):
    style = stylelist.index(obj.image)
    if (style<3):
        obj.image = stylelist[style+1]
    else:
        obj.image = stylelist[0]

def on_mouse_down(pos):
    if dress.collidepoint(pos):
        changestyle(dress,dress_style)
    elif hair.collidepoint(pos):
        changestyle(hair,hair_style)
    elif shoes.collidepoint(pos):
        changestyle(shoes, shoes_style)
    elif button1.collidepoint(pos):
        rand_change()
    elif button2.collidepoint(pos):
        change_all()

def rand_change():
    dress.image = random.choice(dress_style)
    hair.image = random.choice(hair_style)
    shoes.image = random.choice(shoes_style)

def change_all():
    suit = random.randint(0,3)
    dress.image = dress_style[suit]
    hair.image = hair_style[suit]
    shoes.image = shoes_style[suit]


pgzrun.go()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
lsk666666lsk666666

emotion_编程猫_点赞

点赞0


评论