美文网首页Pygame101
001 Memory Puzzle - step1 创建基础

001 Memory Puzzle - step1 创建基础

作者: 爱学习的洋仔 | 来源:发表于2018-06-13 15:52 被阅读0次
    (1) 导入需要的模块
    import random
    import pygame
    import sys
    
    from pygame.locals import *
    
    (2) 基础配置
    FPS = 30 # 设置帧数为30
    WINDOW_WIDTH = 640 
    WINDOW_HEIGHT = 480
    # 设置游戏画面为640 * 480像素
    
    (3) 游戏中需要的颜色
    # R G B
    GRAY = (100,100,100)
    NAVYBLUE = (60,60,100)
    WHITE = (255,255,255)
    RED = (255,0,0)
    GREEN = (0,255,0)
    BLUE = (0,0,255)
    YELLOW = (255,255,0)
    ORANGE = (255,128,0)
    PUPPLE = (255,0,255)
    CYAN = (0,255,255)
    BGCOLOR = NAVYBLUE # 背景色设置为navyblue
    
    (4) 定义main函数
    def main():
    
        pygame.init()
        fpsclock = pygame.time.Clock()
        displaysurf = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
        pygame.display.set_caption("Memory Game")
        displaysurf.fill(BGCOLOR)
        while True:
            displaysurf.fill(BGCOLOR)
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
            pygame.display.update()
            fpsclock.tick(FPS)
    
    if __name__ == '__main__':
        main()
    

    运行程序, 显示一个深蓝色的背景
    ScreenClip [2].png

    Memory Puzzle下一节:绘制图形

    相关文章

      网友评论

        本文标题:001 Memory Puzzle - step1 创建基础

        本文链接:https://www.haomeiwen.com/subject/ouijeftx.html