Python:
import pygame, sys
from bullet import Bullet
from ino import Ino
import time
def events(screen, gun, bullets):
"""обработка событий"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
#вправо
if event.key == pygame.K_d:
gun.mright = True
elif event.key == pygame.K_a:
gun.mleft = True
elif event.key == pygame.K_SPACE:
new_bullet = Bullet(screen, gun)
bullets.add(new_bullet)
elif event.type == pygame.KEYUP:
if event.key == pygame.K_d:
gun.mright = False
elif event.key == pygame.K_a:
gun.mleft = False
def update(bg_color, screen, gun, inos, bullets):
"""Обновление экрана"""
screen.fill(bg_color)
for bullet in bullets.sprites():
bullet.draw_bullet()
gun.output()
inos.draw(screen)
pygame.display.flip()
def update_bullets(inos, bullets):
"""обновление позиции пуль"""
bullets.update()
for bullet in bullets.copy():
if bullet.rect.bottom <= 0:
bullets.remove(bullet)
collections = pygame.sprite.groupcollide(bullets, inos, True, True)
def gun_kill(stats, screen, inos, bullets, gun):
"""столкновение пушки и армии"""
stats.guns_left -= 1
inos.empty()
bullets.empty()
create_army(screen, inos)
gun.create_gun()
time.sleep(1)
def update_inos(inos, bullets, screen, stats, gun):
"""обновляет позицию инопланетян"""
inos.update()
if pygame.sprite.spritecollideany(gun, inos):
gun_kill(stats, screen, inos, bullets, gun)
inos_check(stats, screen, gun, inos, bullets)
def inos_check(stats, screen, gun, inos, bullets):
"""Проверка пришельцев до края экрана"""
screen_rect = screen.get_rect()
for ino in inos.sprites():
if ino.rect.bottom >= screen_rect.bottom:
gun_kill(stats, screen, gun, inos, bullets)
break
def create_army(screen, inos):
"""создание армии пришкльцев"""
ino = Ino(screen)
ino_width = ino.rect.width
number_ino_x = int((700 - 2 * ino_width) / ino_width)
ino_height = ino.rect.height
number_ino_y = int((800 - 100 - 2 * ino_height) / ino_height)
for row_number in range(number_ino_x - 3):
for ino_number in range(number_ino_x):
ino = Ino(screen)
ino.x = ino_width + (ino_width * ino_number)
ino.y = ino_height + (ino_height * row_number)
ino.rect.x = ino.x
ino.rect.y = ino.rect.height + ino.rect.height * row_number
inos.add(ino)
после выдает ошибку:
File "C:\Users\Матвей Захарченко\PycharmProjects\PythonProjects\controles.py", line 47, in gun_kill
inos.empty()
AttributeError: 'Gun' object has no attribute 'empty'

Работаю на Windows 10
Питон 3.9.10