Commit a5e76aee by BellCodeEditor

auto save

parent c701029b
Showing with 39 additions and 0 deletions
a=10
b=20
c=a if a>b else b
print(c)
\ No newline at end of file
import pygame
pygame.init()
ball=pygame.image.load('w.gif')
speed=[1,1]
size=width,height=600,400
screen=pygame.display.set_mode(size,pygame.RESIZABLE)
pygame.display.set_caption('pygame游戏之旅')
fclock=pygame.time.Clock()
black=(0,0,0)
ballrect=ball.get_rect()
fps=200
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:
speed[0]=speed[0] if speed[0]==0 else(abs(speed[0])-1)
if event.key==pygame.K_RIGHT:
speed[0]=speed[0]+1 if speed[0]>0 else speed[0]-1
if event.key==pygame.K_UP:
speed[1]=speed[1]+1 if speed[1]>0 else speed[1]-1
if event.key==pygame.K_DOWN:
speed[1]=speed[1] if speed[1]==0 else(abs(speed[1])-1)
ballrect=ballrect.move(speed[0],speed[1])
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)
fclock.tick(fps)
pygame.display.update()
\ No newline at end of file
w.gif

4.9 KB

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