pygame小游戏-碰撞
程序员文章站
2024-03-19 11:29:58
...
python和pygme的安装
注意:python和pygame版本要匹配,都是32位的。1.9.2是pygame版本,py3.2是对应的python版本,默认的安装路径。
安装成功后cmd检查下:
IDLE也可以检查一下:
import pygame
import sys
pygame.init()
size = width, height = 1000 , 1000
speed = [-2,1]
bg = (255,255,255)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("初次见面,请多多关照")
turtle = pygame.image.load("turtle.png")
position = turtle.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
position = position.move(speed)
if position .left < 0 or position.right > width:
turtle = pygame.transform.flip(turtle,True,False)
speed[0] = - speed[0]
if position .top < 0 or position.bottom > height:
peed[1] = - speed[1]
screen.fill(bg)
screen.blit(turtle,position)
pygame.display.flip()
pygame.time.delay(10)
运行了一下,是成功了: