Python趣味挑戰(zhàn)之用pygame實(shí)現(xiàn)簡單的金幣旋轉(zhuǎn)效果
step1、保存圖像到list列表。step2、在主窗口每次顯示一張list列表中的對象。
呵呵,好像就這么簡單。所以,主要還是要有圖片。這里也分享一下圖片給大家。
(一)加載圖像到list列表
def init_image(): path = ’./score/’ files = [] dirs = os.listdir(path) for diretion in dirs:files.append(path + diretion) for file in files:bglist.append(pygame.image.load(file).convert_alpha())
(二)循環(huán)函數(shù)run實(shí)現(xiàn)
def run(): i = 0 while True:for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.K_F1:pygame.quit()sys.exit() if event.type == pygame.KEYDOWN:if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit()screen.fill((0, 0, 0)) # 設(shè)置背景為白色screen.blit(bglist[i % 7], (50, 50))print(bglist[i % 7].get_size())i += 1fcclock.tick(fps)pygame.display.flip() # 刷新窗口
(三)相關(guān)庫引入及變量初始化
import sys, pygameimport osimport randomimport timepygame.init() # 初始化pygame類screen = pygame.display.set_mode((600, 600)) # 設(shè)置窗口大小pygame.display.set_caption(’金幣翻轉(zhuǎn)小游戲V1.0’) # 設(shè)置窗口標(biāo)題tick = pygame.time.Clock()fps = 10 # 設(shè)置刷新率,數(shù)字越大刷新率越高fcclock = pygame.time.Clock()bglist = []
(四)main主入口實(shí)現(xiàn)
if __name__ == ’__main__’: init_image() run()三、完整代碼
import sys, pygameimport osimport randomimport timepygame.init() # 初始化pygame類screen = pygame.display.set_mode((600, 600)) # 設(shè)置窗口大小pygame.display.set_caption(’金幣翻轉(zhuǎn)小游戲V1.0’) # 設(shè)置窗口標(biāo)題tick = pygame.time.Clock()fps = 10 # 設(shè)置刷新率,數(shù)字越大刷新率越高fcclock = pygame.time.Clock()bglist = []def init_image(): path = ’./score/’ files = [] dirs = os.listdir(path) for diretion in dirs:files.append(path + diretion) for file in files:bglist.append(pygame.image.load(file).convert_alpha())def run(): i = 0 while True:for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.K_F1:pygame.quit()sys.exit() if event.type == pygame.KEYDOWN:if event.key == pygame.K_ESCAPE: pygame.quit() sys.exit()screen.fill((0, 0, 0)) # 設(shè)置背景為白色screen.blit(bglist[i % 7], (50, 50))print(bglist[i % 7].get_size())i += 1fcclock.tick(fps)pygame.display.flip() # 刷新窗口if __name__ == ’__main__’: init_image() run()四、運(yùn)行效果
OK,完成了,比較簡單,大家都學(xué)會了嗎?
到此這篇關(guān)于Python趣味挑戰(zhàn)之用pygame實(shí)現(xiàn)簡單的金幣旋轉(zhuǎn)效果的文章就介紹到這了,更多相關(guān)pygame實(shí)現(xiàn)金幣旋轉(zhuǎn)內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. JavaEE SpringMyBatis是什么? 它和Hibernate的區(qū)別及如何配置MyBatis2. python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作3. 解決vue頁面刷新,數(shù)據(jù)丟失的問題4. Python 忽略文件名編碼的方法5. android studio實(shí)現(xiàn)簡單的計(jì)算器(無bug)6. Java Media Framework 基礎(chǔ)教程7. 利用單元測試對PHP代碼進(jìn)行檢查8. python excel和yaml文件的讀取封裝9. 在Mac中配置Python虛擬環(huán)境過程解析10. python如何實(shí)現(xiàn)word批量轉(zhuǎn)HTML
