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

View File

@ -3,5 +3,5 @@
<component name="Black"> <component name="Black">
<option name="sdkName" value="Python 3.11" /> <option name="sdkName" value="Python 3.11" />
</component> </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> </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.

143
main.py
View File

@ -30,8 +30,8 @@ pygame.mixer.music.load('music.mp3')
pygame.mixer.music.play(-1) # Параметр -1 означает зацикливание музыки pygame.mixer.music.play(-1) # Параметр -1 означает зацикливание музыки
shot_sound = pygame.mixer.Sound('shot.wav') shot_sound = pygame.mixer.Sound('shot.wav')
meme_sound = pygame.mixer.Sound("meme_sound.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)) 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)) 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)) 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)) 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)) 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): class Tank(pygame.sprite.Sprite):
def __init__(self, x, y): def __init__(self, x, y):
@ -96,8 +159,14 @@ class Tank(pygame.sprite.Sprite):
bullets.add(bullet) bullets.add(bullet)
self.last_fire_time = current_time # Обновление времени последнего выстрела 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): class PlayerBullet(pygame.sprite.Sprite):
def __init__(self, x, y, angle): def __init__(self, x, y, angle):
super().__init__() super().__init__()
@ -112,7 +181,8 @@ class PlayerBullet(pygame.sprite.Sprite):
if not screen.get_rect().colliderect(self.rect): if not screen.get_rect().colliderect(self.rect):
self.kill() self.kill()
if pygame.sprite.spritecollideany(self, walls): if pygame.sprite.spritecollideany(self, walls):
self.kill() # Удаляем снаряд, если он столкнулся со стеной self.kill() # Удаляем снаряд, если он столкнулся со стеной
# Определение класса снаряда бота # Определение класса снаряда бота
class BotBullet(pygame.sprite.Sprite): class BotBullet(pygame.sprite.Sprite):
@ -129,7 +199,8 @@ class BotBullet(pygame.sprite.Sprite):
if not screen.get_rect().colliderect(self.rect): if not screen.get_rect().colliderect(self.rect):
self.kill() self.kill()
if pygame.sprite.spritecollideany(self, walls): if pygame.sprite.spritecollideany(self, walls):
self.kill() # Удаляем снаряд, если он столкнулся со стеной self.kill() # Удаляем снаряд, если он столкнулся со стеной
# Определение класса для бота # Определение класса для бота
class Bot(pygame.sprite.Sprite): class Bot(pygame.sprite.Sprite):
@ -147,7 +218,7 @@ class Bot(pygame.sprite.Sprite):
self.move_random() self.move_random()
self.rotate_random() self.rotate_random()
self.check_bounds() self.check_bounds()
#self.shoot_random() # self.shoot_random()
def move_random(self): def move_random(self):
# Движение вперёд в направлении текущего угла поворота # Движение вперёд в направлении текущего угла поворота
@ -174,15 +245,14 @@ class Bot(pygame.sprite.Sprite):
elif self.rect.bottom > SCREEN_HEIGHT: elif self.rect.bottom > SCREEN_HEIGHT:
self.rect.bottom = SCREEN_HEIGHT self.rect.bottom = SCREEN_HEIGHT
#def shoot_random(self): # def shoot_random(self):
# Выстрел в направлении дула # Выстрел в направлении дула
#current_time = pygame.time.get_ticks() # current_time = pygame.time.get_ticks()
#if current_time - self.last_fire_time > random.randint(1000, 5000): # if current_time - self.last_fire_time > random.randint(1000, 5000):
#bullet = BotBullet(self.rect.centerx, self.rect.centery, self.angle + 90) # Стрельба в направлении дула # bullet = BotBullet(self.rect.centerx, self.rect.centery, self.angle + 90) # Стрельба в направлении дула
#all_sprites.add(bullet) # all_sprites.add(bullet)
#bullets.add(bullet) # bullets.add(bullet)
#self.last_fire_time = current_time # self.last_fire_time = current_time
class Wall(pygame.sprite.Sprite): class Wall(pygame.sprite.Sprite):
@ -198,7 +268,6 @@ tanks = pygame.sprite.Group()
bullets = pygame.sprite.Group() bullets = pygame.sprite.Group()
walls = pygame.sprite.Group() # Группа для всех стен walls = pygame.sprite.Group() # Группа для всех стен
# Создание стен # Создание стен
wall_positions = [ wall_positions = [
(360, 40), (460, 730), (460, 830), (460, 930), (360, 40), (460, 730), (460, 830), (460, 930),
@ -233,9 +302,6 @@ for pos in wall_stenki_positions:
all_sprites.add(wall_stenki) all_sprites.add(wall_stenki)
walls.add(wall_stenki) walls.add(wall_stenki)
# Создание групп спрайтов # Создание групп спрайтов
all_sprites = pygame.sprite.Group() all_sprites = pygame.sprite.Group()
tanks = pygame.sprite.Group() tanks = pygame.sprite.Group()
@ -246,8 +312,6 @@ player = Tank(SCREEN_WIDTH // 8, SCREEN_HEIGHT // 7)
all_sprites.add(player) all_sprites.add(player)
tanks.add(player) tanks.add(player)
bot = Bot(3 * SCREEN_WIDTH // 4, SCREEN_HEIGHT // 2) bot = Bot(3 * SCREEN_WIDTH // 4, SCREEN_HEIGHT // 2)
all_sprites.add(bot) all_sprites.add(bot)
tanks.add(bot) tanks.add(bot)
@ -260,6 +324,7 @@ bot = Bot(3 * SCREEN_WIDTH // 4, SCREEN_HEIGHT // 2)
all_sprites.add(bot) all_sprites.add(bot)
tanks.add(bot) tanks.add(bot)
def draw_menu(): def draw_menu():
screen.blit(menu_background, (0, 0)) screen.blit(menu_background, (0, 0))
# Рисуем текст меню # Рисуем текст меню
@ -284,11 +349,10 @@ def respawn_bot():
all_sprites.add(new_bot) all_sprites.add(new_bot)
tanks.add(new_bot) tanks.add(new_bot)
last_meme_time = 0 last_meme_time = 0
meme_delay = 2000 # Задержка в миллисекундах (2 секунды) meme_delay = 2000 # Задержка в миллисекундах (2 секунды)
# Главный цикл программы # Главный цикл программы
menu_active = True menu_active = True
while menu_active: while menu_active:
@ -302,27 +366,22 @@ while menu_active:
else: else:
menu_active = False # Нажата кнопка "Старт" menu_active = False # Нажата кнопка "Старт"
# Основной игровой цикл # Основной игровой цикл
clock = pygame.time.Clock() clock = pygame.time.Clock()
running = True running = True
while running: while running:
player_bullets = [] player_bullets = []
bot_bullets = [] bot_bullets = []
current_time = pygame.time.get_ticks() current_time = pygame.time.get_ticks()
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
running = False running = False
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # Обработка левой кнопки мыши elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: # Обработка левой кнопки мыши
player.shoot() player.shoot()
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_k: if event.key == pygame.K_k:
if current_time - last_meme_time > meme_delay: # Проверка задержки if current_time - last_meme_time > meme_delay: # Проверка задержки
@ -332,24 +391,24 @@ while running:
# Обновление всех спрайтов # Обновление всех спрайтов
all_sprites.update() all_sprites.update()
# Проверка столкновений пуль с танками # Проверка столкновений пуль с танками
for bullet in bullets: for bullet in bullets:
if isinstance(bullet, PlayerBullet): if isinstance(bullet, PlayerBullet):
tank_hit = pygame.sprite.spritecollideany(bullet, tanks, pygame.sprite.collide_mask) tank_hit = pygame.sprite.spritecollideany(bullet, tanks, pygame.sprite.collide_mask)
if tank_hit and isinstance(tank_hit, Bot): 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() # Удаляем пулю bullet.kill() # Удаляем пулю
tank_hit.kill() # Удаляем бота
respawn_bot() # Создаем нового бота
elif isinstance(bullet, BotBullet): elif isinstance(bullet, BotBullet):
tank_hit = pygame.sprite.spritecollideany(bullet, tanks, pygame.sprite.collide_mask) # Проверяем столкновение пули бота с стенами
if tank_hit and isinstance(tank_hit, Tank): if pygame.sprite.spritecollideany(bullet, walls):
tank_hit.kill() # Удаляем игрока, если попал бот stoneexplosion_sound.play() # Воспроизведение звука взрыва камня
bullet.kill() # Удаляем пулю explosion = Explosion(bullet.rect.centerx, bullet.rect.centery) # Создание взрыва камня
if tank_hit and isinstance(tank_hit, Bot): all_sprites.add(explosion) # Добавление взрыва камня в группу спрайтов
tank_hit.kill() # Удаляем бота, если попал игрок bullet.kill() # Удаляем пулю бота
bullet.kill() # Удаляем пулю
respawn_bot() # Пересоздаем бота в случайном месте карты
bullet.update()
# Отрисовка фона # Отрисовка фона
for i in range(2): for i in range(2):
@ -439,6 +498,4 @@ while running:
clock.tick(FPS) clock.tick(FPS)
# Завершение работы Pygame # Завершение работы Pygame
pygame.quit() 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.