|
@@ -1,36 +1,45 @@
|
|
|
# Example file showing a circle moving on screen
|
|
# Example file showing a circle moving on screen
|
|
|
|
|
+# Example file showing a circle moving on screen
|
|
|
import pygame
|
|
import pygame
|
|
|
|
|
|
|
|
# pygame setup
|
|
# pygame setup
|
|
|
pygame.init()
|
|
pygame.init()
|
|
|
-screen = pygame.display.set_mode((1280, 720))
|
|
|
|
|
|
|
+screen = pygame.display.set_mode((720, 720))
|
|
|
clock = pygame.time.Clock()
|
|
clock = pygame.time.Clock()
|
|
|
running = True
|
|
running = True
|
|
|
dt = 0
|
|
dt = 0
|
|
|
|
|
|
|
|
-player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
|
|
|
|
|
|
|
|
|
|
|
|
+player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2)
|
|
|
|
|
+velocity = pygame.Vector2(0,0)
|
|
|
|
|
+acceleration = 500
|
|
|
while running:
|
|
while running:
|
|
|
# poll for events
|
|
# poll for events
|
|
|
# pygame.QUIT event means the user clicked X to close your window
|
|
# pygame.QUIT event means the user clicked X to close your window
|
|
|
for event in pygame.event.get():
|
|
for event in pygame.event.get():
|
|
|
if event.type == pygame.QUIT:
|
|
if event.type == pygame.QUIT:
|
|
|
running = False
|
|
running = False
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ raketa = pygame.image.load("raketa.png").convert_alpha()
|
|
|
# fill the screen with a color to wipe away anything from last frame
|
|
# fill the screen with a color to wipe away anything from last frame
|
|
|
- screen.fill("black")
|
|
|
|
|
|
|
+ screen.fill("purple")
|
|
|
|
|
|
|
|
- pygame.draw.circle(screen, "blue", player_pos, 40)
|
|
|
|
|
|
|
+ screen.blit(raketa, player_pos)
|
|
|
|
|
|
|
|
keys = pygame.key.get_pressed()
|
|
keys = pygame.key.get_pressed()
|
|
|
if keys[pygame.K_w]:
|
|
if keys[pygame.K_w]:
|
|
|
- player_pos.y -= 300 * dt
|
|
|
|
|
|
|
+ velocity.y -= acceleration * dt
|
|
|
|
|
+ pygame.transform.rotate(raketa, 90)
|
|
|
if keys[pygame.K_s]:
|
|
if keys[pygame.K_s]:
|
|
|
- player_pos.y += 300 * dt
|
|
|
|
|
|
|
+ velocity.y += acceleration * dt
|
|
|
|
|
+ pygame.transform.rotate(raketa, 180)
|
|
|
if keys[pygame.K_a]:
|
|
if keys[pygame.K_a]:
|
|
|
- player_pos.x -= 300 * dt
|
|
|
|
|
|
|
+ velocity.x -= acceleration * dt
|
|
|
|
|
+ pygame.transform.rotate(raketa, 360)
|
|
|
if keys[pygame.K_d]:
|
|
if keys[pygame.K_d]:
|
|
|
- player_pos.x += 300 * dt
|
|
|
|
|
|
|
+ velocity.x += acceleration * dt
|
|
|
|
|
+ pygame.transform.rotate(raketa, 270)
|
|
|
|
|
+ player_pos += velocity * dt
|
|
|
|
|
|
|
|
# flip() the display to put your work on screen
|
|
# flip() the display to put your work on screen
|
|
|
pygame.display.flip()
|
|
pygame.display.flip()
|