This commit is contained in:
2025-07-13 19:00:57 +02:00
parent 01a298e864
commit b78a164429
4 changed files with 26 additions and 5 deletions

View File

@@ -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