标签:margin display form fill play nbsp als game ott
‘‘‘
一只飘来飘去的小乌龟,在触碰到边框的时候,马上掉头转向。
‘‘‘
import pygame
import sys
pygame.init()
size = width, height =600, 600
speed = [-2, 1]
bg = (254, 254, 254)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("python小乌龟")
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:
speed[1] = -speed[-1]
screen.fill(bg) screen.blit(turtle,position) pygame.display.flip() pygame.time.delay(10)
标签:margin display form fill play nbsp als game ott
原文地址:https://www.cnblogs.com/cjl0706/p/12028968.html