Arseshka Lu 2024-03-02 19:33:38 +02:00
parent b1572cd218
commit c1488d729b
57 changed files with 102 additions and 45 deletions

View File

@ -2,7 +2,7 @@
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.11" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

BIN
explosion_1.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
explosion_10.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

BIN
explosion_11.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
explosion_12.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
explosion_13.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
explosion_14.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
explosion_15.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
explosion_16.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
explosion_17.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
explosion_18.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
explosion_19.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
explosion_2.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
explosion_20.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
explosion_21.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
explosion_22.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

BIN
explosion_23.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
explosion_24.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
explosion_25.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
explosion_26.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

BIN
explosion_27.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

BIN
explosion_28.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
explosion_29.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

BIN
explosion_3.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
explosion_30.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

BIN
explosion_31.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
explosion_32.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

BIN
explosion_33.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
explosion_34.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
explosion_35.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

BIN
explosion_36.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

BIN
explosion_37.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

BIN
explosion_38.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
explosion_39.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
explosion_4.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
explosion_40.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
explosion_41.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
explosion_42.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
explosion_43.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
explosion_44.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
explosion_45.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
explosion_46.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
explosion_47.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
explosion_5.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

BIN
explosion_6.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
explosion_7.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
explosion_8.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
explosion_9.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

BIN
explosion_sound.wav 100644

Binary file not shown.

133
main.py
View File

@ -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__()
@ -114,6 +183,7 @@ class PlayerBullet(pygame.sprite.Sprite):
if pygame.sprite.spritecollideany(self, walls):
self.kill() # Удаляем снаряд, если он столкнулся со стеной
# Определение класса снаряда бота
class BotBullet(pygame.sprite.Sprite):
def __init__(self, x, y, angle):
@ -131,6 +201,7 @@ class BotBullet(pygame.sprite.Sprite):
if pygame.sprite.spritecollideany(self, walls):
self.kill() # Удаляем снаряд, если он столкнулся со стеной
# Определение класса для бота
class Bot(pygame.sprite.Sprite):
def __init__(self, x, y):
@ -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):
# 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
# 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: # Проверка задержки
@ -337,19 +396,19 @@ while running:
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):
@ -440,5 +499,3 @@ while running:
# Завершение работы Pygame
pygame.quit()
# token: 8f195a885b18a96da6577884cc731f850f33a9e2

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.