added player movement
This commit is contained in:
parent
5b8a9dd113
commit
703023c019
2 changed files with 11 additions and 3 deletions
4
main.py
4
main.py
|
|
@ -15,10 +15,10 @@ def main():
|
|||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
return
|
||||
screen.fill((0, 0, 0))
|
||||
screen.fill((0, 0, 0))
|
||||
p1.draw(screen)
|
||||
p1.update(dt)
|
||||
pygame.display.flip()
|
||||
pygame.display.flip()
|
||||
tick = clock.tick(60)
|
||||
dt = tick/1000
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
10
player.py
10
player.py
|
|
@ -5,7 +5,7 @@ import pygame
|
|||
class Player(circleshape.CircleShape):
|
||||
def __init__(self,x,y):
|
||||
super().__init__(x,y,constants.PLAYER_RADIUS)
|
||||
self.rotation = 0
|
||||
self.rotation = 0
|
||||
|
||||
def triangle(self):
|
||||
forward = pygame.Vector2(0, 1).rotate(self.rotation)
|
||||
|
|
@ -24,6 +24,7 @@ class Player(circleshape.CircleShape):
|
|||
self.rotation += dt*constants.PLAYER_ROTATION_SPEED
|
||||
else:
|
||||
self.rotation += -dt*constants.PLAYER_ROTATION_SPEED
|
||||
|
||||
def update(self, dt):
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
|
|
@ -31,3 +32,10 @@ class Player(circleshape.CircleShape):
|
|||
self.rotate(dt,"left")
|
||||
if keys[pygame.K_d]:
|
||||
self.rotate(dt,"right")
|
||||
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 * constants.PLAYER_SPEED * dt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue