summaryrefslogtreecommitdiff
path: root/player.py
diff options
context:
space:
mode:
authoryuzu-eva <stevenhu@web.de>2024-09-20 18:43:29 +0200
committeryuzu-eva <stevenhu@web.de>2024-09-20 18:43:29 +0200
commit6d45b7245fdaaa0d35e429b69c9ac14ee940a841 (patch)
treec34058d2df152d8e12e45ed0640ca71a948a19d3 /player.py
parenta00f4cf1eb4217483408dde11d9d0c7e763ab0a2 (diff)
add collision for bullets
Diffstat (limited to 'player.py')
-rw-r--r--player.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/player.py b/player.py
index 9b7f4bc..8fbcdc3 100644
--- a/player.py
+++ b/player.py
@@ -7,6 +7,7 @@ class Player(CircleShape):
def __init__(self, x, y):
super().__init__(x, y, PLAYER_RADIUS)
self.rotation = 0
+ self.timer = 0
# in the player class
def triangle(self):
@@ -25,6 +26,7 @@ class Player(CircleShape):
def update(self, dt):
keys = pygame.key.get_pressed()
+ self.timer -= dt
if keys[pygame.K_LEFT]:
self.rotate(-dt)
if keys[pygame.K_RIGHT]:
@@ -34,12 +36,16 @@ class Player(CircleShape):
if keys[pygame.K_DOWN]:
self.move(-dt)
if keys[pygame.K_SPACE]:
- self.shoot(self.position)
+ self.shoot()
def move(self, dt):
forward = pygame.Vector2(0, 1).rotate(self.rotation)
self.position += forward * PLAYER_SPEED * dt
- def shoot(self, position):
- shot = Shot(position.x, position.y, SHOT_RADIUS)
+ def shoot(self):
+ if self.timer > 0:
+ return
+ shot = Shot(self.position.x, self.position.y, SHOT_RADIUS)
shot.velocity = pygame.Vector2(0, 1).rotate(self.rotation) * PLAYER_SHOOT_SPEED
+ self.timer = PLAYER_SHOOT_COOLDOWN
+