diff options
| -rw-r--r-- | constants.py | 1 | ||||
| -rw-r--r-- | main.py | 2 | ||||
| -rw-r--r-- | player.py | 8 |
3 files changed, 10 insertions, 1 deletions
diff --git a/constants.py b/constants.py index 4b98fc6..020eeab 100644 --- a/constants.py +++ b/constants.py @@ -8,3 +8,4 @@ ASTEROID_MAX_RADIUS = ASTEROID_MIN_RADIUS * ASTEROID_KINDS PLAYER_RADIUS = 20 PLAYER_TURN_SPEED = 300 +PLAYER_SPEED = 200 @@ -11,7 +11,7 @@ def main(): player = Player(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) while True: for event in pygame.event.get(): - if event.type == pygame.QUIT: + if event.type == pygame.QUIT or pygame.key.get_pressed()[pygame.K_q]: return screen.fill("black") player.update(dt) @@ -28,4 +28,12 @@ class Player(CircleShape): self.rotate(-dt) if keys[pygame.K_RIGHT]: self.rotate(dt) + if keys[pygame.K_UP]: + self.move(dt) + if keys[pygame.K_DOWN]: + self.move(-dt) + + def move(self, dt): + forward = pygame.Vector2(0, 1).rotate(self.rotation) + self.position += forward * PLAYER_SPEED * dt |
