首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

利用Python实现敲击木鱼积累功德效果 功德+N

时下,电子木鱼已经成为年轻人之间流行的“电子拜佛“的方式

赛博佛法之敲电子木鱼可以说得上是打工人的解压利器了。

那,要如何利用python来实现敲木鱼,让我们的”功德“达到最大化?

非常简单,跟着代码走,功德buff叠满!

import pygame

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")

rect1=img1.get_rect()

rect2=img2.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, (-150, -100))

while True:

for event in pygame.event.get():

if pygame.Rect.collidepoint(rect2, (ball_x, ball_y)) and event.type==pygame.MOUSEBUTTONDOWN:

screen.blit(img2, (-150, -100))

muyulucky.play()

pygame.display.flip()

if pygame.Rect.collidepoint(rect1, (ball_x, ball_y)) and event.type==pygame.MOUSEBUTTONUP:

screen.blit(img1, (-150, -100))

pygame.display.flip(),

if event.type==pygame.QUIT:

pygame.quit()

pygame.display.flip()

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20230103A0674A00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券