added player rotation
This commit is contained in:
parent
ef4695aae2
commit
5b8a9dd113
3 changed files with 15 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
2
main.py
2
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__":
|
||||
|
|
|
|||
12
player.py
12
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue