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()