Update main.py

52
Artjoms Marians Ņečajevs 2024-02-26 08:19:29 +00:00
parent d4dd04a44c
commit 5f7ebdbc05
1 changed files with 12 additions and 6 deletions

18
main.py
View File

@ -6,11 +6,11 @@ import math
SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080
PLAYER_SIZE = 150
BULLET_SIZE = 30
BULLET_SIZE = 20
FPS = 60
BULLET_SPEED = 6
TANK_SPEED = 2
FIRE_DELAY = 500
DEFAULT_TANK_SPEED = 2
FIRE_DELAY = 500 # Задержка между выстрелами в миллисекундах
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
@ -38,6 +38,7 @@ class Tank(pygame.sprite.Sprite):
self.rect = self.image.get_rect(center=(x, y))
self.angle = -90 # Поворот на 90 градусов против часовой стрелки
self.last_fire_time = pygame.time.get_ticks() # Время последнего выстрела
self.speed = DEFAULT_TANK_SPEED
def update(self):
keys = pygame.key.get_pressed()
@ -50,8 +51,8 @@ class Tank(pygame.sprite.Sprite):
def move_forward(self):
angle_rad = math.radians(self.angle + 270)
self.rect.x += TANK_SPEED * math.cos(angle_rad)
self.rect.y += TANK_SPEED * math.sin(angle_rad)
self.rect.x += self.speed * math.cos(angle_rad)
self.rect.y += self.speed * math.sin(angle_rad)
def shoot(self):
current_time = pygame.time.get_ticks()
@ -98,6 +99,9 @@ while running:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # Обработка левой кнопки мыши
player.shoot()
elif event.type == pygame.KEYDOWN: # Обработка нажатия клавиш
if event.key == pygame.K_F10: # Если нажата клавиша пробела
player.speed += 5 # Увеличиваем скорость танка
# Обновление всех спрайтов
all_sprites.update()
@ -186,8 +190,10 @@ while running:
screen.blit(stenki, (1600, 1030))
screen.blit(stenki, (1800, 1030))
# Остальной код отрисовки стен и спрайтов остается без изменений
pygame.display.flip()
clock.tick(FPS)
# Завершение работы Pygame
pygame.quit()
pygame.quit()