# -*- coding: utf-8 -*-
""" Spyder Editor This is a temporary script file. """ import pygame,sys pygame.init() size = width,height = 600, 400 speend = [1,1] WHITE = 255,255,255 screen =pygame.display.set_mode(size) pygame.display.set_caption("dj") ball = pygame.image.load("dj.gif") ballrect =ball.get_rect() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ballrect = ballrect.move(speend[0],speend[1]) if ballrect.left < 0 or ballrect.right >width: speend[0] = -speend[0] if ballrect.top < 0 or ballrect.bottom > height: speend[1] = -speend[1] screen.fill(WHITE) screen.blit(ball,ballrect) pygame.display.update()
—————————————————————————————————————————————————————
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import pygame,sys
pygame.init()
size = width,height = 600, 400
speend = [1,1]
WHITE = 255,255,255
screen =pygame.display.set_mode(size)
pygame.display.set_caption("dj")
ball = pygame.image.load("dj.gif")
ballrect =ball.get_rect()
fps = 300
fclock =pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
ballrect = ballrect.move(speend[0],speend[1])
if ballrect.left < 0 or ballrect.right >width:
speend[0] = -speend[0]
if ballrect.top < 0 or ballrect.bottom > height:
speend[1] = -speend[1]
screen.fill(WHITE)
screen.blit(ball,ballrect)
pygame.display.update()
fclock.tick(fps)
—————————————————————————————————————————————————————
原文地址:https://www.cnblogs.com/llhhcc/p/10230759.html