splitting asteroids, game done
This commit is contained in:
10
player.py
10
player.py
@@ -1,12 +1,13 @@
|
||||
import pygame
|
||||
from circleshape import CircleShape
|
||||
from constants import PLAYER_RADIUS, PLAYER_SHOOT_SPEED, PLAYER_SPEED, PLAYER_TURN_SPEED, SHOT_RADIUS
|
||||
from constants import PLAYER_RADIUS, PLAYER_SHOOT_COOLDOWN, PLAYER_SHOOT_SPEED, PLAYER_SPEED, PLAYER_TURN_SPEED, SHOT_RADIUS
|
||||
from shot import Shot
|
||||
|
||||
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):
|
||||
@@ -24,6 +25,8 @@ class Player(CircleShape):
|
||||
self.rotation += PLAYER_TURN_SPEED * dt
|
||||
|
||||
def update(self, dt):
|
||||
self.timer -= dt
|
||||
|
||||
keys = pygame.key.get_pressed()
|
||||
|
||||
if keys[pygame.K_a]:
|
||||
@@ -46,5 +49,10 @@ class Player(CircleShape):
|
||||
self.position += forward * PLAYER_SPEED * dt
|
||||
|
||||
def shoot(self, dt):
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user