Adding in bullets
This commit is contained in:
14
player.py
14
player.py
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user