diff --git a/.idea/Pygame_Project.iml b/.idea/Pygame_Project.iml
index d0876a7..f571432 100644
--- a/.idea/Pygame_Project.iml
+++ b/.idea/Pygame_Project.iml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index a6218fe..e73a553 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,5 +3,5 @@
-
+
\ No newline at end of file
diff --git a/explosion_1.png b/explosion_1.png
new file mode 100644
index 0000000..c2ea29e
Binary files /dev/null and b/explosion_1.png differ
diff --git a/explosion_10.png b/explosion_10.png
new file mode 100644
index 0000000..c7a4056
Binary files /dev/null and b/explosion_10.png differ
diff --git a/explosion_11.png b/explosion_11.png
new file mode 100644
index 0000000..6e38f34
Binary files /dev/null and b/explosion_11.png differ
diff --git a/explosion_12.png b/explosion_12.png
new file mode 100644
index 0000000..877a17d
Binary files /dev/null and b/explosion_12.png differ
diff --git a/explosion_13.png b/explosion_13.png
new file mode 100644
index 0000000..47151ff
Binary files /dev/null and b/explosion_13.png differ
diff --git a/explosion_14.png b/explosion_14.png
new file mode 100644
index 0000000..40f3333
Binary files /dev/null and b/explosion_14.png differ
diff --git a/explosion_15.png b/explosion_15.png
new file mode 100644
index 0000000..623047a
Binary files /dev/null and b/explosion_15.png differ
diff --git a/explosion_16.png b/explosion_16.png
new file mode 100644
index 0000000..e43ac15
Binary files /dev/null and b/explosion_16.png differ
diff --git a/explosion_17.png b/explosion_17.png
new file mode 100644
index 0000000..d48afc2
Binary files /dev/null and b/explosion_17.png differ
diff --git a/explosion_18.png b/explosion_18.png
new file mode 100644
index 0000000..5aeea83
Binary files /dev/null and b/explosion_18.png differ
diff --git a/explosion_19.png b/explosion_19.png
new file mode 100644
index 0000000..917d6c3
Binary files /dev/null and b/explosion_19.png differ
diff --git a/explosion_2.png b/explosion_2.png
new file mode 100644
index 0000000..563b8e3
Binary files /dev/null and b/explosion_2.png differ
diff --git a/explosion_20.png b/explosion_20.png
new file mode 100644
index 0000000..d1715de
Binary files /dev/null and b/explosion_20.png differ
diff --git a/explosion_21.png b/explosion_21.png
new file mode 100644
index 0000000..5747c83
Binary files /dev/null and b/explosion_21.png differ
diff --git a/explosion_22.png b/explosion_22.png
new file mode 100644
index 0000000..be61721
Binary files /dev/null and b/explosion_22.png differ
diff --git a/explosion_23.png b/explosion_23.png
new file mode 100644
index 0000000..e43c19e
Binary files /dev/null and b/explosion_23.png differ
diff --git a/explosion_24.png b/explosion_24.png
new file mode 100644
index 0000000..c4c6cac
Binary files /dev/null and b/explosion_24.png differ
diff --git a/explosion_25.png b/explosion_25.png
new file mode 100644
index 0000000..5e40f35
Binary files /dev/null and b/explosion_25.png differ
diff --git a/explosion_26.png b/explosion_26.png
new file mode 100644
index 0000000..47e38f8
Binary files /dev/null and b/explosion_26.png differ
diff --git a/explosion_27.png b/explosion_27.png
new file mode 100644
index 0000000..f5eee73
Binary files /dev/null and b/explosion_27.png differ
diff --git a/explosion_28.png b/explosion_28.png
new file mode 100644
index 0000000..563c1a8
Binary files /dev/null and b/explosion_28.png differ
diff --git a/explosion_29.png b/explosion_29.png
new file mode 100644
index 0000000..4039de0
Binary files /dev/null and b/explosion_29.png differ
diff --git a/explosion_3.png b/explosion_3.png
new file mode 100644
index 0000000..eefe7f9
Binary files /dev/null and b/explosion_3.png differ
diff --git a/explosion_30.png b/explosion_30.png
new file mode 100644
index 0000000..dfb9298
Binary files /dev/null and b/explosion_30.png differ
diff --git a/explosion_31.png b/explosion_31.png
new file mode 100644
index 0000000..ccd0c78
Binary files /dev/null and b/explosion_31.png differ
diff --git a/explosion_32.png b/explosion_32.png
new file mode 100644
index 0000000..69008f4
Binary files /dev/null and b/explosion_32.png differ
diff --git a/explosion_33.png b/explosion_33.png
new file mode 100644
index 0000000..901d72f
Binary files /dev/null and b/explosion_33.png differ
diff --git a/explosion_34.png b/explosion_34.png
new file mode 100644
index 0000000..1bd9b21
Binary files /dev/null and b/explosion_34.png differ
diff --git a/explosion_35.png b/explosion_35.png
new file mode 100644
index 0000000..7b19b3f
Binary files /dev/null and b/explosion_35.png differ
diff --git a/explosion_36.png b/explosion_36.png
new file mode 100644
index 0000000..775968e
Binary files /dev/null and b/explosion_36.png differ
diff --git a/explosion_37.png b/explosion_37.png
new file mode 100644
index 0000000..8dbb68c
Binary files /dev/null and b/explosion_37.png differ
diff --git a/explosion_38.png b/explosion_38.png
new file mode 100644
index 0000000..a7dbd57
Binary files /dev/null and b/explosion_38.png differ
diff --git a/explosion_39.png b/explosion_39.png
new file mode 100644
index 0000000..6e53eb6
Binary files /dev/null and b/explosion_39.png differ
diff --git a/explosion_4.png b/explosion_4.png
new file mode 100644
index 0000000..872b79d
Binary files /dev/null and b/explosion_4.png differ
diff --git a/explosion_40.png b/explosion_40.png
new file mode 100644
index 0000000..8eca34f
Binary files /dev/null and b/explosion_40.png differ
diff --git a/explosion_41.png b/explosion_41.png
new file mode 100644
index 0000000..2afbdbe
Binary files /dev/null and b/explosion_41.png differ
diff --git a/explosion_42.png b/explosion_42.png
new file mode 100644
index 0000000..5d13bbd
Binary files /dev/null and b/explosion_42.png differ
diff --git a/explosion_43.png b/explosion_43.png
new file mode 100644
index 0000000..2f977dc
Binary files /dev/null and b/explosion_43.png differ
diff --git a/explosion_44.png b/explosion_44.png
new file mode 100644
index 0000000..243f0d3
Binary files /dev/null and b/explosion_44.png differ
diff --git a/explosion_45.png b/explosion_45.png
new file mode 100644
index 0000000..98314f8
Binary files /dev/null and b/explosion_45.png differ
diff --git a/explosion_46.png b/explosion_46.png
new file mode 100644
index 0000000..9c58683
Binary files /dev/null and b/explosion_46.png differ
diff --git a/explosion_47.png b/explosion_47.png
new file mode 100644
index 0000000..f911a0a
Binary files /dev/null and b/explosion_47.png differ
diff --git a/explosion_5.png b/explosion_5.png
new file mode 100644
index 0000000..57b3c08
Binary files /dev/null and b/explosion_5.png differ
diff --git a/explosion_6.png b/explosion_6.png
new file mode 100644
index 0000000..a542ed2
Binary files /dev/null and b/explosion_6.png differ
diff --git a/explosion_7.png b/explosion_7.png
new file mode 100644
index 0000000..58ca26c
Binary files /dev/null and b/explosion_7.png differ
diff --git a/explosion_8.png b/explosion_8.png
new file mode 100644
index 0000000..78d5c23
Binary files /dev/null and b/explosion_8.png differ
diff --git a/explosion_9.png b/explosion_9.png
new file mode 100644
index 0000000..3a1e1d9
Binary files /dev/null and b/explosion_9.png differ
diff --git a/explosion_sound.wav b/explosion_sound.wav
new file mode 100644
index 0000000..87f9251
Binary files /dev/null and b/explosion_sound.wav differ
diff --git a/main.py b/main.py
index fcd57e6..e3947c7 100644
--- a/main.py
+++ b/main.py
@@ -30,8 +30,8 @@ pygame.mixer.music.load('music.mp3')
pygame.mixer.music.play(-1) # Параметр -1 означает зацикливание музыки
shot_sound = pygame.mixer.Sound('shot.wav')
meme_sound = pygame.mixer.Sound("meme_sound.wav")
-
-
+explosion_sound = pygame.mixer.Sound("explosion_sound.wav")
+stoneexplosion_sound = pygame.mixer.Sound("stoneexplosion_sound.wav")
# Загрузка изображений
background_image = pygame.transform.scale(pygame.image.load("travka_pol.jpeg"), (960, 540))
@@ -40,10 +40,73 @@ stenki = pygame.transform.scale(pygame.image.load("stena.jpeg").convert(), (200,
tank_image = pygame.transform.scale(pygame.image.load("ntank-removebg-preview.png"), (PLAYER_WIDTH, PLAYER_HEIGHT))
loh_image = pygame.transform.scale(pygame.image.load("loh.png"), (LOH_WIDTH, LOH_HEIGHT))
bullet_image = pygame.transform.scale(pygame.image.load("bullet.png"), (BULLET_SIZE, BULLET_SIZE))
+explosion_images = [pygame.image.load(f"explosion_{i}.png") for i in range(1, 48)]
+stoneexplosion_images = [pygame.image.load(f"stoneexplosion_{i}.png") for i in range(1, 6)]
menu_background = pygame.transform.scale(pygame.image.load("menu_background.jpg"), (SCREEN_WIDTH, SCREEN_HEIGHT))
+class Explosion(pygame.sprite.Sprite):
+ def __init__(self, x, y):
+ super().__init__()
+ self.image = explosion_images[0]
+ self.rect = self.image.get_rect(center=(x, y))
+ self.frame = 0
+ self.last_update = pygame.time.get_ticks()
+ self.frame_rate = 50
+
+ def update(self):
+ now = pygame.time.get_ticks()
+ if now - self.last_update > self.frame_rate:
+ self.last_update = now
+ self.frame += 1
+ if self.frame == 6:
+ self.kill()
+ else:
+ center = self.rect.center
+ self.image = explosion_images[self.frame]
+ self.rect = self.image.get_rect()
+ self.rect.center = center
+
+# Добавление класса для анимации удара о каменную стену
+class StoneExplosion(pygame.sprite.Sprite):
+ def __init__(self, x, y):
+ super().__init__()
+ self.images = stoneexplosion_images
+ self.image = self.images[0]
+ self.rect = self.image.get_rect(center=(x, y))
+ self.frame = 0
+ self.last_update = pygame.time.get_ticks()
+ self.frame_rate = 50
+ stoneexplosion_sound.play() # Воспроизведение звука удара о стену
+
+ def update(self):
+ now = pygame.time.get_ticks()
+ if now - self.last_update > self.frame_rate:
+ self.last_update = now
+ self.frame += 1
+ if self.frame == len(self.images):
+ self.kill()
+ else:
+ center = self.rect.center
+ self.image = self.images[self.frame]
+ self.rect = self.image.get_rect()
+ self.rect.center = center
+
+
+ def update(self):
+ now = pygame.time.get_ticks()
+ if now - self.last_update > self.frame_rate:
+ self.last_update = now
+ self.frame += 1
+ if self.frame == len(self.images):
+ self.kill()
+ else:
+ center = self.rect.center
+ self.image = self.images[self.frame]
+ self.rect = self.image.get_rect()
+ self.rect.center = center
+
# Определение класса танка
class Tank(pygame.sprite.Sprite):
def __init__(self, x, y):
@@ -96,8 +159,14 @@ class Tank(pygame.sprite.Sprite):
bullets.add(bullet)
self.last_fire_time = current_time # Обновление времени последнего выстрела
+ # Проверяем столкновение пули с каменными стенами
+ if pygame.sprite.spritecollideany(bullet, walls):
+ stoneexplosion_sound.play() # Воспроизведение звука столкновения с каменной стеной
+ explosion = StoneExplosion(bullet.rect.centerx, bullet.rect.centery) # Создание анимации удара о стену
+ all_sprites.add(explosion) # Добавление анимации удара о стену в группу спрайтов
+ bullet.kill() # Удаление пули
+
-# Определение класса снаряда игрока
class PlayerBullet(pygame.sprite.Sprite):
def __init__(self, x, y, angle):
super().__init__()
@@ -112,7 +181,8 @@ class PlayerBullet(pygame.sprite.Sprite):
if not screen.get_rect().colliderect(self.rect):
self.kill()
if pygame.sprite.spritecollideany(self, walls):
- self.kill() # Удаляем снаряд, если он столкнулся со стеной
+ self.kill() # Удаляем снаряд, если он столкнулся со стеной
+
# Определение класса снаряда бота
class BotBullet(pygame.sprite.Sprite):
@@ -129,7 +199,8 @@ class BotBullet(pygame.sprite.Sprite):
if not screen.get_rect().colliderect(self.rect):
self.kill()
if pygame.sprite.spritecollideany(self, walls):
- self.kill() # Удаляем снаряд, если он столкнулся со стеной
+ self.kill() # Удаляем снаряд, если он столкнулся со стеной
+
# Определение класса для бота
class Bot(pygame.sprite.Sprite):
@@ -147,7 +218,7 @@ class Bot(pygame.sprite.Sprite):
self.move_random()
self.rotate_random()
self.check_bounds()
- #self.shoot_random()
+ # self.shoot_random()
def move_random(self):
# Движение вперёд в направлении текущего угла поворота
@@ -174,15 +245,14 @@ class Bot(pygame.sprite.Sprite):
elif self.rect.bottom > SCREEN_HEIGHT:
self.rect.bottom = SCREEN_HEIGHT
- #def shoot_random(self):
- # Выстрел в направлении дула
- #current_time = pygame.time.get_ticks()
- #if current_time - self.last_fire_time > random.randint(1000, 5000):
- #bullet = BotBullet(self.rect.centerx, self.rect.centery, self.angle + 90) # Стрельба в направлении дула
- #all_sprites.add(bullet)
- #bullets.add(bullet)
- #self.last_fire_time = current_time
-
+ # def shoot_random(self):
+ # Выстрел в направлении дула
+ # current_time = pygame.time.get_ticks()
+ # if current_time - self.last_fire_time > random.randint(1000, 5000):
+ # bullet = BotBullet(self.rect.centerx, self.rect.centery, self.angle + 90) # Стрельба в направлении дула
+ # all_sprites.add(bullet)
+ # bullets.add(bullet)
+ # self.last_fire_time = current_time
class Wall(pygame.sprite.Sprite):
@@ -198,7 +268,6 @@ tanks = pygame.sprite.Group()
bullets = pygame.sprite.Group()
walls = pygame.sprite.Group() # Группа для всех стен
-
# Создание стен
wall_positions = [
(360, 40), (460, 730), (460, 830), (460, 930),
@@ -233,9 +302,6 @@ for pos in wall_stenki_positions:
all_sprites.add(wall_stenki)
walls.add(wall_stenki)
-
-
-
# Создание групп спрайтов
all_sprites = pygame.sprite.Group()
tanks = pygame.sprite.Group()
@@ -246,8 +312,6 @@ player = Tank(SCREEN_WIDTH // 8, SCREEN_HEIGHT // 7)
all_sprites.add(player)
tanks.add(player)
-
-
bot = Bot(3 * SCREEN_WIDTH // 4, SCREEN_HEIGHT // 2)
all_sprites.add(bot)
tanks.add(bot)
@@ -260,6 +324,7 @@ bot = Bot(3 * SCREEN_WIDTH // 4, SCREEN_HEIGHT // 2)
all_sprites.add(bot)
tanks.add(bot)
+
def draw_menu():
screen.blit(menu_background, (0, 0))
# Рисуем текст меню
@@ -284,11 +349,10 @@ def respawn_bot():
all_sprites.add(new_bot)
tanks.add(new_bot)
+
last_meme_time = 0
meme_delay = 2000 # Задержка в миллисекундах (2 секунды)
-
-
# Главный цикл программы
menu_active = True
while menu_active:
@@ -302,27 +366,22 @@ while menu_active:
else:
menu_active = False # Нажата кнопка "Старт"
-
-
# Основной игровой цикл
clock = pygame.time.Clock()
running = True
-
while running:
player_bullets = []
bot_bullets = []
current_time = pygame.time.get_ticks()
-
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # Обработка левой кнопки мыши
player.shoot()
-
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_k:
if current_time - last_meme_time > meme_delay: # Проверка задержки
@@ -332,24 +391,24 @@ while running:
# Обновление всех спрайтов
all_sprites.update()
- # Проверка столкновений пуль с танками
+ # Проверка столкновений пуль с танками
for bullet in bullets:
if isinstance(bullet, PlayerBullet):
tank_hit = pygame.sprite.spritecollideany(bullet, tanks, pygame.sprite.collide_mask)
if tank_hit and isinstance(tank_hit, Bot):
- tank_hit.kill() # Удаляем бота, если попал игрок
+ explosion_sound.play() # Воспроизведение звука взрыва
+ explosion = Explosion(tank_hit.rect.centerx, tank_hit.rect.centery) # Создание взрыва
+ all_sprites.add(explosion) # Добавление взрыва в группу спрайтов
bullet.kill() # Удаляем пулю
+ tank_hit.kill() # Удаляем бота
+ respawn_bot() # Создаем нового бота
elif isinstance(bullet, BotBullet):
- tank_hit = pygame.sprite.spritecollideany(bullet, tanks, pygame.sprite.collide_mask)
- if tank_hit and isinstance(tank_hit, Tank):
- tank_hit.kill() # Удаляем игрока, если попал бот
- bullet.kill() # Удаляем пулю
- if tank_hit and isinstance(tank_hit, Bot):
- tank_hit.kill() # Удаляем бота, если попал игрок
- bullet.kill() # Удаляем пулю
- respawn_bot() # Пересоздаем бота в случайном месте карты
-
- bullet.update()
+ # Проверяем столкновение пули бота с стенами
+ if pygame.sprite.spritecollideany(bullet, walls):
+ stoneexplosion_sound.play() # Воспроизведение звука взрыва камня
+ explosion = Explosion(bullet.rect.centerx, bullet.rect.centery) # Создание взрыва камня
+ all_sprites.add(explosion) # Добавление взрыва камня в группу спрайтов
+ bullet.kill() # Удаляем пулю бота
# Отрисовка фона
for i in range(2):
@@ -439,6 +498,4 @@ while running:
clock.tick(FPS)
# Завершение работы Pygame
-pygame.quit()
-
-# token: 8f195a885b18a96da6577884cc731f850f33a9e2
\ No newline at end of file
+pygame.quit()
\ No newline at end of file
diff --git a/stoneexplosion_1.png b/stoneexplosion_1.png
new file mode 100644
index 0000000..4f626b8
Binary files /dev/null and b/stoneexplosion_1.png differ
diff --git a/stoneexplosion_2.png b/stoneexplosion_2.png
new file mode 100644
index 0000000..ca8009d
Binary files /dev/null and b/stoneexplosion_2.png differ
diff --git a/stoneexplosion_3.png b/stoneexplosion_3.png
new file mode 100644
index 0000000..f3e613c
Binary files /dev/null and b/stoneexplosion_3.png differ
diff --git a/stoneexplosion_4.png b/stoneexplosion_4.png
new file mode 100644
index 0000000..5ec164d
Binary files /dev/null and b/stoneexplosion_4.png differ
diff --git a/stoneexplosion_5.png b/stoneexplosion_5.png
new file mode 100644
index 0000000..9a014d4
Binary files /dev/null and b/stoneexplosion_5.png differ
diff --git a/stoneexplosion_sound.wav b/stoneexplosion_sound.wav
new file mode 100644
index 0000000..db6b9d1
Binary files /dev/null and b/stoneexplosion_sound.wav differ