Adding in bullets

This commit is contained in:
franky212
2024-10-28 21:10:08 -06:00
parent ae27a3c7a0
commit 48acf7759a
4 changed files with 32 additions and 1 deletions

View File

@@ -1,11 +1,13 @@
import pygame
from circleshape import CircleShape
from constants import PLAYER_RADIUS, PLAYER_TURN_SPEED, PLAYER_SPEED
from shot import Shot
from constants import PLAYER_RADIUS, PLAYER_TURN_SPEED, PLAYER_SPEED, PLAYER_SHOOT_SPEED, PLAYER_SHOOT_COOLDOWN
class Player(CircleShape):
def __init__(self, x, y):
super().__init__(x, y, PLAYER_RADIUS)
self.rotation = 0
self.timer = 0
def rotate(self, dt):
self.rotation += PLAYER_TURN_SPEED * dt
@@ -25,6 +27,16 @@ class Player(CircleShape):
self.move(dt)
if keys[pygame.K_s]:
self.move(-dt)
if keys[pygame.K_SPACE]:
self.shoot()
self.timer -= dt
def shoot(self):
if self.timer > 0:
return
self.timer = PLAYER_SHOOT_COOLDOWN
Shot(self.position.x, self.position.y, (pygame.Vector2(0, 1).rotate(self.rotation)) * PLAYER_SHOOT_SPEED)
# in the player class
def triangle(self):