From 681826fc3272b9ec0e60c6863381404c7ee42094 Mon Sep 17 00:00:00 2001 From: yuzu-eva Date: Fri, 20 Sep 2024 17:27:11 +0200 Subject: add movement --- constants.py | 1 + main.py | 2 +- player.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) 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 diff --git a/main.py b/main.py index bd59cfc..f62150f 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/player.py b/player.py index d629c09..339b8d1 100644 --- a/player.py +++ b/player.py @@ -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 -- cgit v1.2.3