[pygame] pygame设计联机对战桌游(1-1)
本系列总目录:https://blog.csdn.net/wxlxy316/article/details/104246724
内容概要
一、阅读学习官方例程(1)
昨日问题
昨日安装pygame后,在使用时出现了pygame.init()语句报错,百度后问题解决:
https://blog.csdn.net/qq_42780289/article/details/88354802
官方教程
1. 弹弹球demo
https://www.pygame.org/docs/tut/PygameIntro.html
记得下载intro_ball.gif
完整代码
import sys, pygame
pygame.init()
size = width, height = 640, 480
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball = pygame.image.load("intro_ball.gif")
ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
ballrect = ballrect.move(speed)
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