佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > Python趣味挑戰(zhàn)之用pygame實(shí)現(xiàn)簡(jiǎn)單的金幣旋轉(zhuǎn)效果

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

熱門標(biāo)簽:美圖手機(jī) 銀行業(yè)務(wù) 檢查注冊(cè)表項(xiàng) 服務(wù)器配置 鐵路電話系統(tǒng) 智能手機(jī) 呼叫中心市場(chǎng)需求 網(wǎng)站文章發(fā)布

一、實(shí)現(xià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 += 1
        fcclock.tick(fps)
        pygame.display.flip()  # 刷新窗口

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

import sys, pygame
import os
import random
import time

pygame.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, pygame
import os
import random
import time

pygame.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 += 1
        fcclock.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)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python趣味挑戰(zhàn)之教你用pygame畫進(jìn)度條
  • Python趣味挑戰(zhàn)之pygame實(shí)現(xiàn)無敵好看的百葉窗動(dòng)態(tài)效果
  • Python3+Pygame實(shí)現(xiàn)射擊游戲完整代碼
  • python 基于pygame實(shí)現(xiàn)俄羅斯方塊
  • python pygame 憤怒的小鳥游戲示例代碼
  • Python3.9.0 a1安裝pygame出錯(cuò)解決全過程(小結(jié))
  • python之pygame模塊實(shí)現(xiàn)飛機(jī)大戰(zhàn)完整代碼
  • Python使用Pygame繪制時(shí)鐘
  • Python3.8安裝Pygame教程步驟詳解
  • python pygame入門教程

標(biāo)簽:沈陽 新疆 長(zhǎng)治 河南 樂山 上海 滄州 紅河

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python趣味挑戰(zhàn)之用pygame實(shí)現(xiàn)簡(jiǎn)單的金幣旋轉(zhuǎn)效果》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    黑水县| 探索| 开原市| 长春市| 新疆| 仁寿县| 凌海市| 焉耆| 星子县| 忻州市| 金堂县| 秭归县| 水富县| 昆山市| 大英县| 碌曲县| 隆尧县| 邢台县| 宝应县| 呼伦贝尔市| 永德县| 香港| 鸡东县| 荔波县| 临潭县| 舒城县| 枣庄市| 贞丰县| 通海县| 红安县| 清徐县| 清水县| 抚州市| 宁国市| 彭山县| 炎陵县| 通许县| 远安县| 呼伦贝尔市| 沿河| 郎溪县|