基于Python實(shí)現(xiàn)敲擊木魚積累功德效果
示例代碼
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():
# 獲取光標(biāo)位置,2個(gè)值
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()實(shí)現(xiàn)效果

補(bǔ)充
當(dāng)然利用Python語(yǔ)言還可以實(shí)現(xiàn)很多有趣的小項(xiàng)目,小編為大家整理了幾個(gè),感興趣的小伙伴可以嘗試一下
Python代碼實(shí)現(xiàn)信息轟炸
實(shí)現(xiàn)效果:把光標(biāo)放在會(huì)話框里,即可發(fā)送指定的內(nèi)容和信息數(shù)量!
需要下載pyuput庫(kù)----pip install pyuput
代碼如下:
from pynput.keyboard import Key,Controller
import time
keyboard=Controller()
messages=input("請(qǐng)輸入你要轟炸的信息:")
times=eval(input("請(qǐng)輸入你要轟炸的次數(shù):"))
print("數(shù)據(jù)已被后臺(tái)接受,請(qǐng)將光標(biāo)移動(dòng)至?xí)捒?)
time.sleep(2)
for i in range(3):
print("距離信息轟炸還需要%d秒"%(3-i))
time.sleep(1)
for i in range(times):
keyboard.type(messages)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(0.1)
print("信息轟炸已經(jīng)順利完成,已退出!")效果圖

python模擬黑客流星雨
實(shí)現(xiàn)代碼
# -*- coding:utf-8 -*-
# 導(dǎo)入系統(tǒng)文件庫(kù)
import pygame
import random
from pygame.locals import *
from random import randint
# 定義一些窗體參數(shù)及加載字體文件
SCREEN_WIDTH = 900 # 窗體寬度
SCREEN_HEIGHT = 600 # 窗體寬度
LOW_SPEED = 4 # 字體移動(dòng)最低速度
HIGH_SPEED = 20 # 字體移動(dòng)最快速度
FONT_COLOR = (10, 150, 200) # 字體顏色
FONT_SIZE = 15 # 字體尺寸
FONT_NOM = 20 # 顯示字體數(shù)量 從0開始
FONT_NAME = "calibrii.ttf" # 注意字體的文件名必須與真實(shí)文件完全相同(注意ttf的大小寫),且文件名不能是中文
FREQUENCE = 10 # 時(shí)間頻度
times = 0 # 初始化時(shí)間
# 定義隨機(jī)參數(shù)
# 隨機(jī)下降速度
def randomspeed():
return randint(LOW_SPEED, HIGH_SPEED)
def randomposition():
# 隨機(jī)位置
return randint(0, SCREEN_WIDTH), randint(0, SCREEN_HEIGHT)
# 隨機(jī)數(shù)值
def randomvalue():
return randint(0, 100) # this is your own display number range
# class of sprite 定義精靈
class Word(pygame.sprite.Sprite):
def __init__(self, bornposition):
pygame.sprite.Sprite.__init__(self)
self.value = randomvalue()# 精靈數(shù)值
self.font = pygame.font.Font(None, FONT_SIZE)# 精靈字體
self.image = self.font.render(str(self.value), True, FONT_COLOR)# 精靈外觀
self.speed = randomspeed()# 精靈速度
self.rect = self.image.get_rect()# 精靈大小
self.rect.topleft = bornposition# 精靈位置
def update(self):# updata pygame內(nèi)部方法
self.rect = self.rect.move(0, self.speed)
if self.rect.top > SCREEN_HEIGHT:
self.kill()# kill pygame內(nèi)部方法
# init the available modules
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("ViatorSun CodeRain")
clock = pygame.time.Clock()
group = pygame.sprite.Group()
group_count = int(SCREEN_WIDTH / FONT_NOM)
# mainloop
while True:
time = clock.tick(FREQUENCE)
for event in pygame.event.get():
if event.type == QUIT:
import mouse
pygame.quit()
exit()
screen.fill((0, 0, 0))
for i in range(0, group_count):
group.add(Word((i * FONT_NOM, -FONT_NOM)))
group.update()
group.draw(screen)
pygame.display.update()效果圖

到此這篇關(guān)于基于Python實(shí)現(xiàn)敲擊木魚積累功德效果的文章就介紹到這了,更多相關(guān)Python敲擊木魚內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python用selenium實(shí)現(xiàn)自動(dòng)登錄和下單的項(xiàng)目實(shí)戰(zhàn)
本文主要介紹了Python用selenium實(shí)現(xiàn)自動(dòng)登錄和下單的項(xiàng)目實(shí)戰(zhàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
python PyQt5的窗口界面的各種交互邏輯實(shí)現(xiàn)
PyQt5是一個(gè)Python綁定庫(kù),用于Qt C++ GUI框架,它允許開發(fā)者使用Python語(yǔ)言創(chuàng)建跨平臺(tái)的應(yīng)用程序,并利用豐富的Qt圖形用戶界面功能,本文介紹了python中PyQt5窗口界面的各種交互邏輯實(shí)現(xiàn),需要的朋友可以參考下2024-07-07
python中字符串拼接的幾種方法及優(yōu)缺點(diǎn)對(duì)比詳解
在 Python 中,字符串拼接是常見(jiàn)的操作,Python 提供了多種方法來(lái)拼接字符串,每種方法有其優(yōu)缺點(diǎn)和適用場(chǎng)景,以下是幾種常見(jiàn)的字符串拼接方法,需要的朋友可以參考下2025-03-03
Python基礎(chǔ)之pandas數(shù)據(jù)合并
這篇文章主要介紹了Python基礎(chǔ)之pandas數(shù)據(jù)合并,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python基礎(chǔ)的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04
Python實(shí)現(xiàn)針對(duì)中文排序的方法
這篇文章主要介紹了Python實(shí)現(xiàn)針對(duì)中文排序的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Python針對(duì)中文進(jìn)行排序操作出現(xiàn)的問(wèn)題與相關(guān)處理技巧,需要的朋友可以參考下2017-05-05
python:動(dòng)態(tài)路由的Flask程序代碼
今天小編就為大家分享一篇python:動(dòng)態(tài)路由的Flask程序代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11

