Commit 1e0fa4f0 by BellCodeEditor

save project

parent 1ee78c84
Showing with 39 additions and 0 deletions
import pygame,sys
pygame.init()
size = width,height = 600,400
speed = [1,1]
BLACK = 0,0,0
screen = pygame.display.set_mode(size,pygame.NOFRAME)
pygame.display.set_caption("Pygame游戏之旅")
ball = pygame.image.load(r"C:\Users\Administrator\Documents\level3-lesson24-diy3\ball.gif")
ballrect = ball.get_rect()
fps = 300
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_a:
speed[0] = speed[0] if speed[0] == 0 else(abs(speed[0]))-1
elif event.key == pygame.K_d:
speed[0] = speed[0] + 1 if speed[0] > 0 else speed[0] -1
elif event.key == pygame.K_w:
speed[1] = speed[1] if speed[1] > 0 else speed[1] +1
elif event.key == pygame.K_s:
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)
pygame.display.update()
fclock.tick(fps)
\ No newline at end of file
a = 10
b = 20
c = a if a>b else b
print(c)
\ No newline at end of file
ball.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