Python+Pygame實(shí)戰(zhàn)之炫舞小游戲的實(shí)現(xiàn)
導(dǎo)語
昨天去老姐家里蹭飯,進(jìn)門的時(shí)候就看到佳佳妹(我姐的女兒)低頭霹靂吧啦一頓操作猛如虎,飯好了都還在玩兒,什么東西這么好玩?一走進(jìn)就看到這是一款酷似炫舞的小游戲。(死去的回憶突然在攻擊我~沒想到現(xiàn)在還有這款游戲就是不知道升級(jí)了多少次啦)
不知道你們還記不記得曾經(jīng)有個(gè)風(fēng)靡一時(shí)的舞蹈游戲炫舞。
我讀小學(xué)的時(shí)候,大概是09年吧,這個(gè)游戲非常火爆,如果你去網(wǎng)吧,十個(gè)女生里,有十一個(gè)都是在玩炫舞,像我就是其中的一員。那個(gè)時(shí)候還沒有英雄聯(lián)盟王者榮耀,女生玩炫舞,男生玩地下城穿越火線!
提到QQ炫舞,可能很多人想到的第一個(gè)詞是“青春”。恍然間,這個(gè)承載了無數(shù)人回憶與時(shí)光的游戲品牌,已經(jīng)走到了第十幾個(gè)年頭。今天小編就來給大家嘗試做一款簡單的簡陋版的小游戲——《舞動(dòng)青春*炫舞》。(其實(shí)是簡單的五分之一的成品,感覺今天洗頭發(fā)又要掉一堆了)
一、環(huán)境安裝
小編使用的環(huán)境:Python3、Pycharm社區(qū)版、pygame模塊,部分自帶的就不一一 展示啦。
模塊安裝:pip install -i https://pypi.douban.com/simple/+模塊名

背景圖片大家可以自己修改的啦~嘿嘿怎么好看怎么來撒!
二、代碼展示
主程序:
import pygame
import sys
import random
import time
import threading
random.random()
flag=1
# 創(chuàng)建線程對(duì)象
# 初始化pygame
pygame.init()
# 定義變量
size = width, height = 1024,768
bg = (0, 0, 0)
# 加載logo圖
img = pygame.image.load("shang_hong.png")
# 獲取圖像的位置
# 創(chuàng)建一個(gè)主窗口
screen = pygame.display.set_mode(size)
# 標(biāo)題
pygame.display.set_caption("炫舞——簡潔版")
# 創(chuàng)建游戲主循環(huán)
clock = pygame.time.Clock()
sudu=0.5
list=[]
list1=[]
def fuyuan():
x=50
global list1,list
list.clear()
for i in range(1,10):
list.append(list1[i-1])
for i in list1:
if i==1:
img = pygame.image.load("zuo_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
if i==2:
img = pygame.image.load("shang_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
if i==3:
img = pygame.image.load("you_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
if i==4:
img = pygame.image.load("xia_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
x=x+113
x=50
def chushi():
global x
x=50
screen.fill(bg)
global list
global list1
list.clear()
list1.clear()
for i in range(1,9):
i=random.randint(1,4)
list.append(i)
list.append(5)
#print(list)
for i in range(1,10):
list1.append(list[i-1])
#print(list1)
img = pygame.image.load("jindu.jpg")
screen.blit(img, [100,400])
pygame.display.flip()
x=50
for i in list:
if i==1:
img = pygame.image.load("zuo_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
if i==2:
img = pygame.image.load("shang_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
if i==3:
img = pygame.image.load("you_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
if i==4:
img = pygame.image.load("xia_hong.png")
screen.blit(img, [x,500])
pygame.display.flip()
x=x+113
x=50
x1=150
flag=1
def yidong():
#print("sss")
global flag
global list
global x1
global clock
clock.tick(800)
#print(x1)
img = pygame.image.load("jindu.jpg")
screen.blit(img, [100,400])
pygame.draw.circle(screen,(232,0,176),(x1,431),20,1000)
#print(x1)
pygame.display.flip()
x1=x1+sudu
if x1>780:
#print(len(list))
if len(list)==0:
while x1<780:
flag=0
#print(x1)
clock.tick(800)
#print(x1)
img = pygame.image.load("jindu.jpg")
screen.blit(img, [100,400])
pygame.draw.circle(screen,(232,0,176),(x1,431),20,1000)
pygame.display.flip()
x1=x1+sudu
flag=1
#chushi()
#list.clear()
x1=150
if len(list)>0:
screen.fill((0,0,0))
miss()
while x1<780:
flag=0
#print(x1)
clock.tick(800)
#print(x1)
img = pygame.image.load("jindu.jpg")
screen.blit(img, [100,400])
pygame.draw.circle(screen,(232,0,176),(x1,431),20,1000)
pygame.display.flip()
x1=x1+sudu
x1=150
flag=1
chushi()
class task(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.thread_stop = False
def run(self):
while not self.thread_stop:
yidong()
def stop(self):
self.thread_stop = True
t1 = task()
t1.start()
#yidong()
chushi()
x=50
def miss():
font = pygame.font.Font(None, 150)
text = font.render('Miss!', True, (232,0,176), (0, 0, 0))
screen.blit(text, (200, 150))
def chenggong():
global x1
screen.fill((0,0,0))
global x
global flag
x=50
flag=0
if x1<600:
font = pygame.font.Font(None, 150)
text = font.render('Good!', True, (232,0,176), (0, 0, 0))
screen.blit(text, (200, 150))
if x1>625:
font = pygame.font.Font(None, 150)
text = font.render('Good!', True, (232,0,176), (0, 0, 0))
screen.blit(text, (200, 150))
if x1>=600 and x1<=625:
font = pygame.font.Font(None, 150)
text = font.render('Perfict!', True, (232,0,176), (0, 0, 0))
screen.blit(text, (200, 150))
x1=150
while True:
clock.tick(100)
# 設(shè)置初始值
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# 圖像移動(dòng) KEYDOWN 鍵盤按下事件
# 通過 key 屬性對(duì)應(yīng)按鍵
cmd=1
if event.type == pygame.KEYDOWN and flag==1:
#print("sssss")
#if event.key == 27:
# cmd=2
if event.key == pygame.K_ESCAPE:
t1.stop()
sys.exit()
if event.key == pygame.K_UP:
cmd=2
if event.key == pygame.K_DOWN:
cmd=4
if event.key == pygame.K_RIGHT:
cmd=3
if event.key == pygame.K_LEFT:
cmd=1
if event.key == pygame.K_SPACE:
cmd=5
if len(list)==1:
del list[0]
chenggong()
continue
if cmd==list[0]:
if cmd==1:
#print(x)
img = pygame.image.load("zuo_lv.png")
screen.blit(img, [x,500])
pygame.display.flip()
if cmd==2:
#print(x)
img = pygame.image.load("shang_lv.png")
screen.blit(img, [x,500])
pygame.display.flip()
if cmd==3:
#print(x)
img = pygame.image.load("you_lv.png")
screen.blit(img, [x,500])
pygame.display.flip()
if cmd==4:
#print(x)
img = pygame.image.load("xia_lv.png")
screen.blit(img, [x,500])
pygame.display.flip()
x=x+113
del list[0]
else:
print(list1)
#print("Aaaa")
fuyuan()
x=50
#print("sss")
#screen.fill((0,0,0))
'''
# 移動(dòng)圖像
position = position.move(site)
# 填充背景
screen.fill(bg)
# 放置圖片
screen.blit(img, position)
# 更新顯示界面
pygame.display.flip()
'''三、效果展示
1)簡潔版炫舞

?2)隨機(jī)截圖

3)MISS節(jié)拍

以上就是Python+Pygame實(shí)戰(zhàn)之炫舞小游戲的實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Python Pygame炫舞游戲的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Python利用3D引擎寫一個(gè)Pong游戲
- Python+Pygame編寫一個(gè)Pong游戲
- Python+Pygame實(shí)戰(zhàn)之俄羅斯方塊游戲的實(shí)現(xiàn)
- Python Pygame實(shí)戰(zhàn)之實(shí)現(xiàn)經(jīng)營類游戲夢(mèng)想小鎮(zhèn)代碼版
- Python+Pygame實(shí)現(xiàn)接小彈珠游戲
- Python+Pygame實(shí)戰(zhàn)之詩詞填空游戲的實(shí)現(xiàn)
- Python+numpy實(shí)現(xiàn)一個(gè)蜘蛛紙牌游戲
- Python+Pygame實(shí)戰(zhàn)之文字劇情游戲的實(shí)現(xiàn)
- Python之freegames?零代碼的22個(gè)小游戲集合
相關(guān)文章
Python frozenset集合的實(shí)現(xiàn)
frozenset是Python中的不可變集合類型,本文主要介紹了Python frozenset集合的實(shí)現(xiàn), 文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-04-04
Python?CNN卷積神經(jīng)網(wǎng)絡(luò)實(shí)戰(zhàn)教程深入講解
CNN,即卷積神經(jīng)網(wǎng)絡(luò),主要用于圖像識(shí)別,分類。由輸入層,卷積層,池化層,全連接層(Affline層),Softmax層疊加而成。卷積神經(jīng)網(wǎng)絡(luò)中還有一個(gè)非常重要的結(jié)構(gòu):過濾器,它作用于層與層之間(卷積層與池化層),決定了怎樣對(duì)數(shù)據(jù)進(jìn)行卷積和池化2022-12-12
淺談pytorch torch.backends.cudnn設(shè)置作用
今天小編就為大家分享一篇淺談pytorch torch.backends.cudnn設(shè)置作用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02
PyCharm Ctrl+Shift+F 失靈的簡單有效解決操作
這篇文章主要介紹了PyCharm Ctrl+Shift+F 失靈的簡單有效解決操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-01-01

