Python实现敲击木鱼积累功德小项目

11-17 22阅读 0评论

?=前言:前几天上课闲着没事写了一个Python敲击木鱼积累功德的小项目,当时纯粹就是写着玩,回顾一下鼠标事件的东西还记不记得,发现这个博客的点赞和收藏量还挺高的,我当时也没有把它当回事,后面也有很多人问怎么实现的,想让我再添加一些其他功能

随着点赞量和关注量不断增高,我又重新看了一下博客,感觉过于简单了,实在不配当当时python热榜的第一,所以我又把代码给稍微大改了一下,在原来总体实现的基础上添加了如下功能!

我们先看原来的效果:

1:实现了点击鼠标会弹出切换功德+1的surface界面,鼠标松开回复原先界面!

2:随着鼠标按键的按下同时也会伴随木鱼敲击的空灵的声音!

本次更新之后的功能有:

1:点击鼠标按键会出现功德+1和累计敲击多少次,积累了多少功德的新画面

2:优化了声音的play,降噪处理

3:增加较强的互动性能,在不断的积累功德的过程中,会不定时随机出现意想不到的的互动效果,极大程度增加了该程序的趣味性!

ps:下次更新可能会在半个月后了,届时会使用tk的模块添加登录注册,以及网络编程的使用用户功德的统计排行榜!最近期末,还请谅解!

好了,话不多说,直接上代码:

import Pygame from locale import * pygame.init() pygame.mixer.init() screen=pygame.DIsplay.set_mode((700,500)) pygame.display.set_captiON("木鱼功德")  img1=pygame.image.load("images/muyuluck1.jpg") # img2=pygame.image.load("images/muyulucky2.png") img2=pygame.image.load("images/zan.jpg") img3=pygame.image.load("images/qw.png") rect1=img1.Get_rect()  muyulucky = pygame.mixer.Sound('sound/muyu.WAV') muyulucky.set_volume(0.4) if pygame.mouse.get_focused(): # 获取光标位置,2个值 ball_x, ball_y = pygame.mouse.get_pos() screen.blit(img1, (-180, -100)) count=0 f = pygame.font.SysFont('华文楷体',50) f1 = pygame.font.SysFont('华文楷体',30) # 生成文本信息,第一个参数文本内容;第二个参数,字体是否平滑; # 第三个参数,RGB模式的字体颜色;第四个参数,RGB模式字体背景颜色; # text = f.render("功德+1",True,(255,0,0),(0,0,0)) # text1=f1.render("今日积累功德"+str(count)+"次",True,(255,0,0),(0,0,0)) #获得显示对象的rect区域坐标 # textRect =text.get_rect() # text1Rect =text1.get_rect() # 设置显示对象居中 # textRect.topleft = (30,30) # text1Rect.topleft = (450,30) flag = False while True: for event in pygame.event.get(): if pygame.Rect.collIDepoint(rect1, (ball_x, ball_y)) and event.type==pygame.MOUSEBUTTONDOWN: muyulucky.play() flag=True count = count + 1 text = f.render("功德+1", True, (255, 0, 0), (0, 0, 0)) textRect = text.get_rect() textRect.topleft = (30, 30) text1 = f1.render("今日积累功德" + str(count) + "次", True, (255, 0, 0), (0, 0, 0)) text1Rect = text1.get_rect() text1Rect.topleft = (450, 30) screen.blit(text1, text1Rect) screen.blit(text,textRect) if count==8: f2 = pygame.font.SysFont("华文楷体", 25) text2 = f2.render("今日积累功德8次,去表白应该不会被拒绝太难堪哦", True, (255, 0, 20)) text2Rect = text.get_rect() text2Rect.topleft = (60, 150) screen.blit(text2, text2Rect) if count==10: text = f.render("功德+1", True, (255, 0, 0), (0, 0, 0)) textRect = text.get_rect() textRect.topleft = (30, 30) text1 = f1.render("今日积累功德" + str(count) + "次", True, (255, 0, 0)) text1Rect = text1.get_rect() text1Rect.topleft = (450, 30) screen.blit(img1, (-180, -100)) screen.blit(text1, text1Rect) screen.blit(text, textRect) if count==20: f2 = pygame.font.SysFont("华文楷体", 25) text3 = f2.render("手速这么快干嘛,这是敲木鱼积功德,不是你dfj", True, (230, 90, 80)) text3Rect = text.get_rect() text3Rect.topleft = (60, 150) screen.blit(text3, text3Rect) if count==22: text = f.render("功德+1", True, (255, 0, 0), (0, 0, 0)) textRect = text.get_rect() textRect.topleft = (30, 30) text1 = f1.render("今日积累功德" + str(count) + "次", True, (255, 0, 0), (0, 0, 0)) text1Rect = text1.get_rect() text1Rect.topleft = (450, 30) screen.blit(img1, (-180, -100)) screen.blit(text1, text1Rect) screen.blit(text, textRect) if count==28: f2 = pygame.font.SysFont("华文楷体", 25) text3 = f2.render("tmd,我看你不是敲木鱼,是泄火吧", True, (255, 200, 20)) text3Rect = text.get_rect() text3Rect.topleft = (60, 150) screen.blit(text3, text3Rect) if count==30: text = f.render("功德+1", True, (255, 0, 0), (0, 0, 0)) textRect = text.get_rect() textRect.topleft = (30, 30) text1 = f1.render("今日积累功德" + str(count) + "次", True, (255, 0, 0), (0, 0, 0)) text1Rect = text1.get_rect() text1Rect.topleft = (450, 30) screen.blit(img1, (-180, -100)) screen.blit(text1, text1Rect) screen.blit(text, textRect) if count==40: screen.blit(img2, (-210,10)) if count==41: text = f.render("功德+1", True, (255, 0, 0), (0, 0, 0)) textRect = text.get_rect() textRect.topleft = (30, 30) text1 = f1.render("今日积累功德" + str(count) + "次", True, (255, 0, 0), (0, 0, 0)) text1Rect = text1.get_rect() text1Rect.topleft = (450, 30) screen.blit(img1, (-180, -100)) screen.blit(text1, text1Rect) screen.blit(text, textRect) if count==50: f2 = pygame.font.SysFont("华文楷体", 25) text3 = f2.render("今日功德累计50次了,小熊后台奖励你一只女朋友!", True, (255, 0, 0)) text3Rect = text.get_rect() text3Rect.topleft = (60, 150) screen.blit(text3, text3Rect) screen.blit(img3, (-300, 0)) if count==51: text = f.render("功德+1", True, (255, 0, 0), (0, 0, 0)) textRect = text.get_rect() textRect.topleft = (30, 30) text1 = f1.render("今日积累功德" + str(count) + "次", True, (255, 0, 0), (0, 0, 0)) text1Rect = text1.get_rect() text1Rect.topleft = (450, 30) screen.blit(img1, (-180, -100)) screen.blit(text1, text1Rect) screen.blit(text, textRect)    pygame.display.flip() if pygame.Rect.collidepoint(rect1, (ball_x, ball_y)) and event.type==pygame.MOUSEBUTTONUP: flag = False  text = f.render("功德+1", True, (0, 0, 0), (0, 0, 0)) textRect = text.get_rect() textRect.topleft = (30, 30) screen.blit(text, textRect) if count==40: screen.blit(img2, (-210, 10)) if count==50: f2 = pygame.font.SysFont("华文楷体", 25) text3 = f2.render("功德积累是好事,凡事有个度!", True, (255, 0, 0)) text4 = f2.render("小熊后台检测到你今日功德累计50次,看张照片放松一下吧!!", True, (255, 0, 0)) text3Rect = text.get_rect() text4Rect = text.get_rect() text3Rect.topleft = (60, 150) text4Rect.topleft = (0, 180) screen.blit(img3, (-300, 0)) screen.blit(text3, text3Rect) screen.blit(text4, text4Rect)    pygame.display.flip() if event.type==pygame.QUIT: import mouse pygame.quit() pygame.display.flip()

截图:

Python实现敲击木鱼积累功德小项目

Python实现敲击木鱼积累功德小项目

到此这篇关于Python实现敲击木鱼积累功德小项目的文章就介绍到这了,更多相关Python敲击木鱼内容请搜索云初冀北以前的文章或继续浏览下面的相关文章希望大家以后多多支持云初冀北!

免责声明
本站提供的资源,都来自网络,版权争议与本站无关,所有内容及软件的文章仅限用于学习和研究目的。不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负,我们不保证内容的长久可用性,通过使用本站内容随之而来的风险与本站无关,您必须在下载后的24个小时之内,从您的电脑/手机中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。侵删请致信E-mail:Goliszhou@gmail.com
$

发表评论

表情:
评论列表 (暂无评论,22人围观)

还没有评论,来说两句吧...