久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

Python趣味挑戰(zhàn)之用pygame實現(xiàn)簡單的金幣旋轉(zhuǎn)效果

瀏覽:109日期:2022-06-18 08:29:55
一、實現(xiàn)邏輯

step1、保存圖像到list列表。step2、在主窗口每次顯示一張list列表中的對象。

呵呵,好像就這么簡單。所以,主要還是要有圖片。這里也分享一下圖片給大家。

Python趣味挑戰(zhàn)之用pygame實現(xiàn)簡單的金幣旋轉(zhuǎn)效果

二、核心邏輯代碼解析

(一)加載圖像到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實現(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)) # 設置背景為白色screen.blit(bglist[i % 7], (50, 50))print(bglist[i % 7].get_size())i += 1fcclock.tick(fps)pygame.display.flip() # 刷新窗口

(三)相關庫引入及變量初始化

import sys, pygameimport osimport randomimport timepygame.init() # 初始化pygame類screen = pygame.display.set_mode((600, 600)) # 設置窗口大小pygame.display.set_caption(’金幣翻轉(zhuǎn)小游戲V1.0’) # 設置窗口標題tick = pygame.time.Clock()fps = 10 # 設置刷新率,數(shù)字越大刷新率越高fcclock = pygame.time.Clock()bglist = []

(四)main主入口實現(xiàn)

if __name__ == ’__main__’: init_image() run()三、完整代碼

import sys, pygameimport osimport randomimport timepygame.init() # 初始化pygame類screen = pygame.display.set_mode((600, 600)) # 設置窗口大小pygame.display.set_caption(’金幣翻轉(zhuǎn)小游戲V1.0’) # 設置窗口標題tick = pygame.time.Clock()fps = 10 # 設置刷新率,數(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)) # 設置背景為白色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()四、運行效果

Python趣味挑戰(zhàn)之用pygame實現(xiàn)簡單的金幣旋轉(zhuǎn)效果

OK,完成了,比較簡單,大家都學會了嗎?

到此這篇關于Python趣味挑戰(zhàn)之用pygame實現(xiàn)簡單的金幣旋轉(zhuǎn)效果的文章就介紹到這了,更多相關pygame實現(xiàn)金幣旋轉(zhuǎn)內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 寻甸| 盐池县| 紫金县| 黄石市| 昌都县| 正蓝旗| 贺兰县| 普宁市| 固原市| 无极县| 平和县| 兴安县| 德令哈市| 屏山县| 青川县| 和政县| 定安县| 泽普县| 都昌县| 汶川县| 土默特右旗| 涟水县| 洛扎县| 灵川县| 长寿区| 崇左市| 柳林县| 滨州市| 五寨县| 贵德县| 亳州市| 姚安县| 新干县| 河北省| 图片| 正镶白旗| 侯马市| 图们市| 南投县| 通河县| 伽师县|