Commit 7ab59cad by BellCodeEditor

save project

parent f7d4443d
Showing with 58 additions and 0 deletions
import pygame
pygame.init()
vinfo = pygame.display.Info()
size = width, height = vinfo.current_w,vinfo.current_h
size = width, height =600,400
size = width,height
speed = [1,1]
BLACK = 0, 0, 0
screen = pygame.display.set_mode(size,pygame.RESIZABLE)
#screen = pygame.display.set_mode(size,pygame.NOFRAME)
#screen = pygame.display.set_mode(size,pygame.FULLSCREEN)
pygame.display.set_caption("ballgame")
ball = pygame.image.load("PYG02-ball.gif")
icon = pygame.image.load("PYG03-flower.png")
pygame.display.set_icon(icon)
ballrect = ball.get_rect()
fclock = pygame.time.Clock()
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
if 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_UP:
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)
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(500)
\ 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