pygmame 封装了一些通用的游戏操作: 鼠标键盘图片音乐 …
pip3 install pygame
游戏的框架
import pygame
#from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('测试游戏')
clock = pygame.time.Clock()
#三原色 rgb 红绿蓝,每种颜色的取值为 0-255
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)
while True:
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
pygame.display.update()
clock.tick(10)
画各种常见图形
画矩形
import pygame
#from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption('测试游戏')
clock = pygame.time.Clock()
#三原色 rgb 红绿蓝,每种颜色的取值为 0-255
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (255,0,0)
while True:
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT: