raketa.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Example file showing a circle moving on screen
  2. # Example file showing a circle moving on screen
  3. import pygame
  4. # pygame setup
  5. pygame.init()
  6. screen = pygame.display.set_mode((720, 720))
  7. clock = pygame.time.Clock()
  8. running = True
  9. dt = 0
  10. player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
  11. velocity = pygame.Vector2(0,0)
  12. acceleration = 500
  13. while running:
  14. # poll for events
  15. # pygame.QUIT event means the user clicked X to close your window
  16. for event in pygame.event.get():
  17. if event.type == pygame.QUIT:
  18. running = False
  19. raketa = pygame.image.load("raketa.png").convert_alpha()
  20. # fill the screen with a color to wipe away anything from last frame
  21. screen.fill("purple")
  22. screen.blit(raketa, player_pos)
  23. keys = pygame.key.get_pressed()
  24. if keys[pygame.K_w]:
  25. velocity.y -= acceleration * dt
  26. pygame.transform.rotate(raketa, 90)
  27. if keys[pygame.K_s]:
  28. velocity.y += acceleration * dt
  29. pygame.transform.rotate(raketa, 180)
  30. if keys[pygame.K_a]:
  31. velocity.x -= acceleration * dt
  32. pygame.transform.rotate(raketa, 360)
  33. if keys[pygame.K_d]:
  34. velocity.x += acceleration * dt
  35. pygame.transform.rotate(raketa, 270)
  36. player_pos += velocity * dt
  37. # flip() the display to put your work on screen
  38. pygame.display.flip()
  39. # limits FPS to 60
  40. # dt is delta time in seconds since last frame, used for framerate-
  41. # independent physics.
  42. dt = clock.tick(60) / 1000
  43. pygame.quit()