title: Bullet to Enemy Collision Detection
body: <p>After a few hours of looking for code to reference. I failed i tried to re-write the collision code but it failed. Now my Question is</p>
  
  <p>How can i fix my code to make it delete the Enemy ship when the bullet hits him</p>
  
  <h1>Note: Im not asking for you to do it, i just need it further explained what the problem or where im making a mistake</h1>
  
  <h1>The Code Segment</h1>
  
  <pre><code>    for bullet in Bullets:
      Hit_list = pygame.sprite.Group()
      if pygame.sprite.collide_rect(bullet, Enemy_list):
          Hit_list.add(hit)
          for hit in Hit_list:
              Bullets.remove(bullet)
              All.remove(bullet)
              All.remove(hit)
              Enemy_list.remove(hit)
              # If the bullet goes off the screen it deletes
          if bullet.rect.y &lt; 0:
              Bullets.remove(bullet)
              All.remove(bullet)
  </code></pre>
  
  <h1>The Error</h1>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\jb127996\Desktop\Invaders in Space\Space Shooter.py", line 92, in     &lt;module&gt;
      if pygame.sprite.collide_rect(bullet, Enemy_list):
    File "C:\Python32\lib\site-packages\pygame\sprite.py", line 1290, in collide_rect
      return left.rect.colliderect(right.rect)
  AttributeError: 'Group' object has no attribute 'rect'
  </code></pre>
  
  <h1>Entire Code</h1>
  
  <pre><code>import pygame
  import Player_func
  import AI
  from pygame.locals import *
  
  
  #Background 
  Background = pygame.image.load('Tempback.png')
  Background_size = Background.get_size()
  Background_rect = Background.get_rect()
  
  # Screens Resoultion
  Width = 640
  Height = 480
  Scr = pygame.display.set_mode((Width,Height))
  
  # Fps Clock Vars( Clock.tick(FPS) )
  Clock = pygame.time.Clock()
  FPS = 60
  
  # Colors
  White = (255, 255, 255)
  Black = (0, 0, 0)
  Green = (0, 255, 0)
  Red = (255, 0, 0)
  Blue = (0, 0, 255)
  Orange = (255, 140, 0)
  Default = White
  
  
  # Sprite Lists
  Bullets = pygame.sprite.Group()
  Enemy_list = pygame.sprite.Group()
  All = pygame.sprite.Group()
  
  # Shorting the Class files 
  AI = AI.Enemy()
  Ply = Player_func.Player()
  
  
  # CORDS for Player
  AI.rect.x, AI.rect.y = 100, 50
  AI_pos = (AI.rect.x, AI.rect.y)
  
  Ply.rect.x, Ply.rect.y = 580, 425
  P_pos = (Ply.rect.x, Ply.rect.y)
  
  # True false statements and Vars
  running = True
  Gun_Overload = 0
  Fire = 20
  
  while running:
      Enemy_list.add(AI)
      All.add(AI)
      All.add(Ply)
  
      # Collision Detection for walls on the spaceship
      if Ply.rect.x &lt;= 0:
          Ply.rect.x += 5.5
      elif Ply.rect.x &gt;= 590:
          Ply.rect.x -= 5.5
  
      # Events
      for event in pygame.event.get():
          if event.type == QUIT:
              running = False
  
          elif event.type == KEYDOWN:
              if event.key == K_SPACE and Gun_Overload == Fire:
                  bullet = Player_func.Bullet()
                  bullet.rect.x = (Ply.rect.x +15)
                  bullet.rect.y = Ply.rect.y
                  Bullets.add(bullet)
                  All.add(bullet)
                  Gun_Overload = 0
  
  
      #Cool Down
      if Gun_Overload &lt; Fire:
          Gun_Overload += 1
  
      AI.movement()
      Ply.Controls()
  
      # Updates the Sprite lists so they can all be drawn
      All.update()
  
      # Checks if a bullet hits the enemy on the list
      for bullet in Bullets:
          Hit_list = pygame.sprite.Group()
          if pygame.sprite.collide_rect(bullet, Enemy_list):
              Hit_list.add(hit)
              for hit in Hit_list:
                  Bullets.remove(bullet)
                  All.remove(bullet)
                  All.remove(hit)
                  Enemy_list.remove(hit)
                  # If the bullet goes off the screen it deletes
              if bullet.rect.y &lt; 0:
                  Bullets.remove(bullet)
                  All.remove(bullet)
  
  
      Scr.blit(Background, Background_rect)
      All.draw(Scr)
      pygame.display.flip()
  
      # FPS Clock Loaded in
      Clock.tick(FPS)
  
  pygame.quit()
  </code></pre>