From eee3fe09cc5eb68d297598f6e7d8f05b254d9dda Mon Sep 17 00:00:00 2001 From: htamas1210 Date: Fri, 11 Jul 2025 19:16:24 +0200 Subject: [PATCH] player forward backward movement --- constants.py | 1 + player.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/constants.py b/constants.py index 1d02cd4..a8a6be5 100644 --- a/constants.py +++ b/constants.py @@ -6,3 +6,4 @@ ASTEROID_KINDS = 3 ASTEROID_SPAWN_RATE = 0.8 # seconds ASTEROID_MAX_RADIUS = ASTEROID_MIN_RADIUS * ASTEROID_KINDS PLAYER_TURN_SPEED = 300 +PLAYER_SPEED = 200 diff --git a/player.py b/player.py index 1de32a7..ec4618d 100644 --- a/player.py +++ b/player.py @@ -1,6 +1,6 @@ import pygame from circleshape import CircleShape -from constants import PLAYER_RADIUS, PLAYER_TURN_SPEED +from constants import PLAYER_RADIUS, PLAYER_SPEED, PLAYER_TURN_SPEED class Player(CircleShape): @@ -32,3 +32,13 @@ class Player(CircleShape): if keys[pygame.K_d]: self.rotate(dt) + + if keys[pygame.K_w]: + self.move(dt) + + if keys[pygame.K_s]: + self.move(-dt) + + def move(self, dt): + forward = pygame.Vector2(0, 1).rotate(self.rotation) + self.position += forward * PLAYER_SPEED * dt