python--敲击木鱼积累功德小项目(更新版(2))

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

前言前几天上课闲着没事写了一个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()

截图

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: python