player forward backward movement

This commit is contained in:
2025-07-11 19:16:24 +02:00
parent dd97b1c415
commit eee3fe09cc
2 changed files with 12 additions and 1 deletions

View File

@@ -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

View File

@@ -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