Commit a5cf5625 by BellCodeEditor

save project

parent a5133b7c
Showing with 41 additions and 5 deletions
import pygame
pygame.init()
size = width, height = 600,400
v = pygame.display.Info()
print(v)
size = width, height = v.current_w, v.current_h
f = pygame.time.Clock()
speed = [1,1]
BLACK = 0,0,0
screen = pygame.display.set_mode((600,400))
pygame.display.set_caption("Pygame壁球")
# screen = pygame.display.set_mode(size,pygame.FULLSCREEN)#窗口全屏显示
# screen = pygame.display.set_mode(size,pygame.NOFRAME)
screen = pygame.display.set_mode(size,pygame.RESIZABLE)
ball = pygame.image.load("pyg02-ball.gif")
i = pygame.image.load("PYG03-flower.png")
pygame.display.set_icon(i)
pygame.display.set_caption("Pygame壁球")
ball = pygame.image.load("apple.png")
ballrect = ball.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if speed[0] < 0:
speed[0] = speed[0] +1
if speed[0] > 0:
speed[0] = speed[0] -1
elif event.key == pygame.K_RIGHT:
if speed[0] >= 0:
speed[0] = speed[0] +1
if speed[0] < 0:
speed[0] = speed[0] -1
elif event.key == pygame.K_UP:
if speed[1] > 0:
speed[1] = speed[1] +1
if speed[1] < 0:
speed[1] = speed[1] -1
elif event.key == pygame.K_DOWN:
if speed[1] < 0:
speed[1] = speed[1] +1
if speed[1] > 0:
speed[1] = speed[1] -1
elif 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)
ballrect = ballrect.move(speed[0],speed[1])
if ballrect.left < 0 or ballrect.right > width:
speed[0] =- speed[0]
......@@ -26,6 +61,6 @@ while True:
screen.fill(BLACK)
screen.blit(ball,ballrect)
pygame.display.update()
f.tick(400)
f.tick(600)
\ 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