forked from ivaisfelds/Pygame_Project
Update Tanki imbovie
parent
c9dee338f0
commit
4c4321c88b
|
@ -32,6 +32,7 @@ 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")
|
explosion_sound = pygame.mixer.Sound("explosion_sound.wav")
|
||||||
|
meme_sound = pygame.mixer.Sound("meme_sound.wav")
|
||||||
stoneexplosion_sound = pygame.mixer.Sound("stoneexplosion_sound.wav")
|
stoneexplosion_sound = pygame.mixer.Sound("stoneexplosion_sound.wav")
|
||||||
|
|
||||||
# Загрузка изображений
|
# Загрузка изображений
|
||||||
|
@ -69,7 +70,7 @@ class Explosion(pygame.sprite.Sprite):
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.center = center
|
self.rect.center = center
|
||||||
|
|
||||||
# Добавление класса для анимации удара о каменную стену
|
# Добавление класса для анимации удара о каменную стену
|
||||||
class StoneExplosion(pygame.sprite.Sprite):
|
class StoneExplosion(pygame.sprite.Sprite):
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -160,7 +161,7 @@ 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):
|
if pygame.sprite.spritecollideany(bullet, walls):
|
||||||
stoneexplosion_sound.play() # Воспроизведение звука столкновения с каменной стеной
|
stoneexplosion_sound.play() # Воспроизведение звука столкновения с каменной стеной
|
||||||
explosion = StoneExplosion(bullet.rect.centerx, bullet.rect.centery) # Создание анимации удара о стену
|
explosion = StoneExplosion(bullet.rect.centerx, bullet.rect.centery) # Создание анимации удара о стену
|
||||||
|
@ -181,7 +182,7 @@ 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() # Удаляем снаряд, если он столкнулся со стеной
|
||||||
|
|
||||||
|
|
||||||
# Определение класса снаряда бота
|
# Определение класса снаряда бота
|
||||||
|
@ -199,7 +200,7 @@ 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() # Удаляем снаряд, если он столкнулся со стеной
|
||||||
|
|
||||||
|
|
||||||
# Определение класса для бота
|
# Определение класса для бота
|
||||||
|
@ -245,7 +246,7 @@ class Bot(pygame.sprite.Sprite):
|
||||||
self.rect.bottom = SCREEN_HEIGHT
|
self.rect.bottom = SCREEN_HEIGHT
|
||||||
|
|
||||||
def shoot_random(self):
|
def shoot_random(self):
|
||||||
# Vыстрел в направлении дула
|
# Vыстрел в направлении дула
|
||||||
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) # Стрельба в направлении дула
|
||||||
|
@ -372,7 +373,8 @@ def draw_settings_menu():
|
||||||
|
|
||||||
return quit_rect
|
return quit_rect
|
||||||
|
|
||||||
|
last_meme_time = 0
|
||||||
|
meme_delay = 2000 # Задержка в миллисекундах (2 секунды)
|
||||||
|
|
||||||
# Главный цикл программы
|
# Главный цикл программы
|
||||||
menu_active = True
|
menu_active = True
|
||||||
|
@ -404,6 +406,9 @@ running = True
|
||||||
paused = False # Track pause state
|
paused = False # Track pause state
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
|
|
||||||
|
current_time = pygame.time.get_ticks()
|
||||||
|
|
||||||
# Handle events
|
# Handle events
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
@ -412,12 +417,11 @@ while running:
|
||||||
# Handle left mouse button click
|
# Handle left mouse button click
|
||||||
if not paused:
|
if not paused:
|
||||||
player.shoot()
|
player.shoot()
|
||||||
elif event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_k:
|
if event.key == pygame.K_k:
|
||||||
# Handle 'k' key press for meme sound
|
if current_time - last_meme_time > meme_delay: # Проверка задержки
|
||||||
if current_time - last_meme_time > meme_delay:
|
|
||||||
meme_sound.play()
|
meme_sound.play()
|
||||||
last_meme_time = current_time
|
last_meme_time = current_time # Обновление времени последнего воспроизведения звука
|
||||||
elif event.key == pygame.K_ESCAPE:
|
elif event.key == pygame.K_ESCAPE:
|
||||||
# Toggle pause state when escape key is pressed
|
# Toggle pause state when escape key is pressed
|
||||||
paused = not paused
|
paused = not paused
|
||||||
|
@ -426,7 +430,7 @@ while running:
|
||||||
# Update sprites
|
# Update sprites
|
||||||
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)
|
||||||
|
@ -440,7 +444,7 @@ while running:
|
||||||
score += 1
|
score += 1
|
||||||
|
|
||||||
elif isinstance(bullet, BotBullet):
|
elif isinstance(bullet, BotBullet):
|
||||||
# Проверяем столкновение пули бота с стенами
|
# Проверяем столкновение пули бота с стенами
|
||||||
if pygame.sprite.spritecollideany(bullet, walls):
|
if pygame.sprite.spritecollideany(bullet, walls):
|
||||||
stoneexplosion_sound.play() # Воспроизведение звука взрыва камня
|
stoneexplosion_sound.play() # Воспроизведение звука взрыва камня
|
||||||
explosion = Explosion(bullet.rect.centerx, bullet.rect.centery) # Создание взрыва камня
|
explosion = Explosion(bullet.rect.centerx, bullet.rect.centery) # Создание взрыва камня
|
Loading…
Reference in New Issue