Python趣味挑戰(zhàn)之用pygame實(shí)現(xiàn)簡(jiǎn)單的金幣旋轉(zhuǎn)效果
step1、保存圖像到list列表。step2、在主窗口每次顯示一張list列表中的對(duì)象。
呵呵,好像就這么簡(jiǎ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實(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)庫(kù)引入及變量初始化
import sys, pygameimport osimport randomimport timepygame.init() # 初始化pygame類(lèi)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類(lèi)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,完成了,比較簡(jiǎn)單,大家都學(xué)會(huì)了嗎?
到此這篇關(guān)于Python趣味挑戰(zhàn)之用pygame實(shí)現(xiàn)簡(jiǎn)單的金幣旋轉(zhuǎn)效果的文章就介紹到這了,更多相關(guān)pygame實(shí)現(xiàn)金幣旋轉(zhuǎn)內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP實(shí)現(xiàn)加法驗(yàn)證碼2. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?3. javascript xml xsl取值及數(shù)據(jù)修改第1/2頁(yè)4. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)5. asp知識(shí)整理筆記4(問(wèn)答模式)6. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼7. 小技巧處理div內(nèi)容溢出8. js的一些潛在規(guī)則使用分析9. XML解析錯(cuò)誤:未組織好 的解決辦法10. ASP中格式化時(shí)間短日期補(bǔ)0變兩位長(zhǎng)日期的方法
