main.py 913 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/python3
  2. import sys, pygame
  3. import xml.etree.ElementTree as xmlparser
  4. pygame.init()
  5. white = 255, 255, 255
  6. red = 255, 0, 0
  7. yellow = 255, 255, 0
  8. yellow = 0, 255, 0
  9. size = width, height = 800, 600
  10. speed = [2, 2]
  11. black = 0, 0, 0
  12. screen = pygame.display.set_mode(size)
  13. ball = pygame.image.load("assets/ball.png")
  14. ballrect = ball.get_rect()
  15. font = pygame.font.Font("assets/Cantarell-Regular.ttf", 32)
  16. text = font.render("The Ball", 2, white)
  17. sound = pygame.mixer.Sound("assets/146726__fins__jumping.wav")
  18. while 1:
  19. for event in pygame.event.get():
  20. if event.type == pygame.QUIT: sys.exit()
  21. ballrect = ballrect.move(speed)
  22. if ballrect.left < 0 or ballrect.right > width:
  23. speed[0] = -speed[0]
  24. sound.play()
  25. if ballrect.top < 0 or ballrect.bottom > height:
  26. speed[1] = -speed[1]
  27. sound.play()
  28. screen.fill(black)
  29. screen.blit(ball, ballrect)
  30. screen.blit(text, (4, 4))
  31. pygame.display.flip()