pygame笔记1
程序员文章站
2022-03-16 08:43:01
...
screen = pygame.display.set_mode(x, y) // 设置显示窗口
pygame.display.set_caption() // 设置标题
import pygame, sys
pygame.init()
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("Pygame游戏之旅")
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
pygame.display.update()
import pygame, sys
pygame.init()
size = width, height = 600, 400
speed = [1, 1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("D:/PYG02-ball.gif") #载入图片
ballrect = ball.get_rect() #生成对应矩形
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speed[0], speed[1]) # 模拟壁球移动
if ballrect.left < 0 or ballrect.right > width:
speed[0] = - speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = - speed[1]
screen.fill(BLACK)
screen.blit(ball, ballrect) # 让小球附着在矩阵上,随着矩阵移动
pygame.display.update()