From 5b8a9dd113c0d3f302f91fbd306336f01c43b7c3 Mon Sep 17 00:00:00 2001 From: specCon18 Date: Tue, 14 Jan 2025 13:17:46 -0500 Subject: [PATCH] added player rotation --- constants.py | 4 +++- main.py | 2 +- player.py | 12 +++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/constants.py b/constants.py index 5cec962..41441c9 100644 --- a/constants.py +++ b/constants.py @@ -2,7 +2,9 @@ SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720 PLAYER_RADIUS = 20 -PLAYER_TURN_SPEED = 300 +PLAYER_ROTATION_SPEED = 300 +PLAYER_SPEED = 200 + ASTEROID_MIN_RADIUS = 20 ASTEROID_KINDS = 3 ASTEROID_SPAWN_RATE = 0.8 # seconds diff --git a/main.py b/main.py index 52e7179..857bc5d 100644 --- a/main.py +++ b/main.py @@ -17,8 +17,8 @@ def main(): return screen.fill((0, 0, 0)) p1.draw(screen) + p1.update(dt) pygame.display.flip() - tick = clock.tick(60) dt = tick/1000 if __name__ == "__main__": diff --git a/player.py b/player.py index 1b5824a..81f4a35 100644 --- a/player.py +++ b/player.py @@ -19,5 +19,15 @@ class Player(circleshape.CircleShape): pygame.draw.polygon(screen,(255,255,255),self.triangle(),2) - def rotate(self,dt): + def rotate(self,dt,dir): + if dir == "right": + self.rotation += dt*constants.PLAYER_ROTATION_SPEED + else: + self.rotation += -dt*constants.PLAYER_ROTATION_SPEED + def update(self, dt): + keys = pygame.key.get_pressed() + if keys[pygame.K_a]: + self.rotate(dt,"left") + if keys[pygame.K_d]: + self.rotate(dt,"right")