summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--constants.py1
-rw-r--r--main.py2
-rw-r--r--player.py8
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
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