Commit 23d6376f by BellCodeEditor

save project

parent ed15d4c3
Showing with 41 additions and 0 deletions
# Unit PYG02: Pygame Wall Ball Game version 2 节奏型
import pygame,sys
pygame.init()
vinfo=pygame.display.Info()
# size = width, height = vinfo.current_w,vinfo.current_h
size = width, height = 600,400
speed = [1,1]
BLACK = 0, 0, 0
# screen = pygame.display.set_mode(size,pygame.FULLSCREEN)
# screen = pygame.display.set_mode(size,pygame.NOFRAME)
screen = pygame.display.set_mode(size,pygame.RESIZABLE)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load(r"C:\Users\Administrator\Desktop\PYG02-ball.gif")
flower=pygame.image.load(r'C:\Users\Administrator\Desktop\PYG03-flower.png')
ballrect = ball.get_rect()
pygame.display.set_icon(flower)
fclock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_ESCAPE:
exit()
elif event.type==pygame.VIDEORESIZE:
size=width,height=event.size[0],event.size[1]
screen=pygame.display.set_mode(size,pygame.RESIZABLE)
if pygame.display.get_active():
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)
screen.blit(ball, ballrect)
pygame.display.update()
fclock.tick(100)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment