From dd97b1c41599a83713605a88058c6643b6f1ef15 Mon Sep 17 00:00:00 2001 From: htamas1210 Date: Fri, 11 Jul 2025 19:11:17 +0200 Subject: [PATCH] player rotation --- constants.py | 1 + main.py | 2 ++ player.py | 14 +++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/constants.py b/constants.py index 9ac14a7..1d02cd4 100644 --- a/constants.py +++ b/constants.py @@ -5,3 +5,4 @@ ASTEROID_MIN_RADIUS = 20 ASTEROID_KINDS = 3 ASTEROID_SPAWN_RATE = 0.8 # seconds ASTEROID_MAX_RADIUS = ASTEROID_MIN_RADIUS * ASTEROID_KINDS +PLAYER_TURN_SPEED = 300 diff --git a/main.py b/main.py index 7f7c14d..9367d50 100644 --- a/main.py +++ b/main.py @@ -29,6 +29,8 @@ def main(): pygame.Surface.fill(screen, (0,0,0)) + player.update(dt) + player.draw(screen) pygame.display.flip() #refresh screen diff --git a/player.py b/player.py index 520ad3a..1de32a7 100644 --- a/player.py +++ b/player.py @@ -1,6 +1,6 @@ import pygame from circleshape import CircleShape -from constants import PLAYER_RADIUS +from constants import PLAYER_RADIUS, PLAYER_TURN_SPEED class Player(CircleShape): @@ -20,3 +20,15 @@ class Player(CircleShape): def draw(self, screen): pygame.draw.polygon(screen, (255,255,255), self.triangle(), 2) + + def rotate(self, dt): + self.rotation += PLAYER_TURN_SPEED * dt + + def update(self, dt): + keys = pygame.key.get_pressed() + + if keys[pygame.K_a]: + self.rotate(-dt) + + if keys[pygame.K_d]: + self.rotate(dt)