shooting
This commit is contained in:
14
player.py
14
player.py
@@ -1,11 +1,9 @@
|
||||
import pygame
|
||||
from circleshape import CircleShape
|
||||
from constants import PLAYER_RADIUS, PLAYER_SPEED, PLAYER_TURN_SPEED
|
||||
|
||||
from constants import PLAYER_RADIUS, PLAYER_SHOOT_SPEED, PLAYER_SPEED, PLAYER_TURN_SPEED, SHOT_RADIUS
|
||||
from shot import Shot
|
||||
|
||||
class Player(CircleShape):
|
||||
#containers = []
|
||||
|
||||
def __init__(self, x, y):
|
||||
super().__init__(x, y, PLAYER_RADIUS)
|
||||
self.rotation = 0
|
||||
@@ -22,7 +20,6 @@ class Player(CircleShape):
|
||||
def draw(self, screen):
|
||||
pygame.draw.polygon(screen, (255,255,255), self.triangle(), 2)
|
||||
|
||||
|
||||
def rotate(self, dt):
|
||||
self.rotation += PLAYER_TURN_SPEED * dt
|
||||
|
||||
@@ -41,6 +38,13 @@ class Player(CircleShape):
|
||||
if keys[pygame.K_s]:
|
||||
self.move(-dt)
|
||||
|
||||
if keys[pygame.K_SPACE]:
|
||||
self.shoot(dt)
|
||||
|
||||
def move(self, dt):
|
||||
forward = pygame.Vector2(0, 1).rotate(self.rotation)
|
||||
self.position += forward * PLAYER_SPEED * dt
|
||||
|
||||
def shoot(self, dt):
|
||||
shot = Shot(self.position.x, self.position.y, SHOT_RADIUS)
|
||||
shot.velocity = pygame.Vector2(0, 1).rotate(self.rotation) * PLAYER_SHOOT_SPEED
|
||||
|
||||
Reference in New Issue
Block a user