added player rotation

This commit is contained in:
specCon18 2025-01-14 13:17:46 -05:00
parent ef4695aae2
commit 5b8a9dd113
3 changed files with 15 additions and 3 deletions

View file

@ -2,7 +2,9 @@ SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720 SCREEN_HEIGHT = 720
PLAYER_RADIUS = 20 PLAYER_RADIUS = 20
PLAYER_TURN_SPEED = 300 PLAYER_ROTATION_SPEED = 300
PLAYER_SPEED = 200
ASTEROID_MIN_RADIUS = 20 ASTEROID_MIN_RADIUS = 20
ASTEROID_KINDS = 3 ASTEROID_KINDS = 3
ASTEROID_SPAWN_RATE = 0.8 # seconds ASTEROID_SPAWN_RATE = 0.8 # seconds

View file

@ -17,8 +17,8 @@ def main():
return return
screen.fill((0, 0, 0)) screen.fill((0, 0, 0))
p1.draw(screen) p1.draw(screen)
p1.update(dt)
pygame.display.flip() pygame.display.flip()
tick = clock.tick(60) tick = clock.tick(60)
dt = tick/1000 dt = tick/1000
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -19,5 +19,15 @@ class Player(circleshape.CircleShape):
pygame.draw.polygon(screen,(255,255,255),self.triangle(),2) 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")