| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- # Example file showing a circle moving on screen
- # Example file showing a circle moving on screen
- import pygame
- # pygame setup
- pygame.init()
- screen = pygame.display.set_mode((720, 720))
- clock = pygame.time.Clock()
- running = True
- dt = 0
- player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
- velocity = pygame.Vector2(0,0)
- acceleration = 500
- while running:
- # poll for events
- # pygame.QUIT event means the user clicked X to close your window
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
-
- raketa = pygame.image.load("raketa.png").convert_alpha()
- # fill the screen with a color to wipe away anything from last frame
- screen.fill("purple")
- screen.blit(raketa, player_pos)
- keys = pygame.key.get_pressed()
- if keys[pygame.K_w]:
- velocity.y -= acceleration * dt
- pygame.transform.rotate(raketa, 90)
- if keys[pygame.K_s]:
- velocity.y += acceleration * dt
- pygame.transform.rotate(raketa, 180)
- if keys[pygame.K_a]:
- velocity.x -= acceleration * dt
- pygame.transform.rotate(raketa, 360)
- if keys[pygame.K_d]:
- velocity.x += acceleration * dt
- pygame.transform.rotate(raketa, 270)
- player_pos += velocity * dt
- # flip() the display to put your work on screen
- pygame.display.flip()
- # limits FPS to 60
- # dt is delta time in seconds since last frame, used for framerate-
- # independent physics.
- dt = clock.tick(60) / 1000
- pygame.quit()
|