Beispiel #1
0
 def explode(self):
     """when destroyed"""
     self.explosion_time -= 1
     if self.explosion_time > 0:
         self.screen.blit(self.explosion_image, self.rect)
     else:
         GOL.del_go(self)
Beispiel #2
0
 def update(self):
     # while a solid bullet
     if not self.destroyed:
         # Move
         if self.dir == "UP":
             self.y -= self.speed
             self.rect.y = int(self.y)
         elif self.dir == "DOWN":
             self.y += self.speed
             self.rect.y = int(self.y)
         elif isinstance(self.dir, tuple):
             self.y += self.dir[0] * self.speed
             self.rect.y = int(self.y)
             self.x += self.dir[1] * self.speed
             self.rect.x = int(self.x)
         # Check if reach bottom or top
         if self.rect.top >= self.screen.get_rect().bottom:
             GOL.del_go(self)
         elif self.rect.bottom <= self.screen.get_rect().top:
             GOL.del_go(self)
         # Check if hit anything
         if isinstance(self.ship, Player):
             for alien in GOL.get_golist(Aliens):
                 if self.rect.colliderect(alien.rect):
                     if alien.spawned and not alien.destroyed:
                         alien.take_dmg(self.dmg)
                         self.destroyed = True
         elif isinstance(self.ship, Aliens):
             if GOL.get_go(Player):
                 if self.rect.colliderect(GOL.get_go(Player).rect):
                     GOL.get_go(Player).take_dmg(self.dmg)
                     self.destroyed = True
Beispiel #3
0
 def update(self):
     if self.spawned:
         Ships.update(self)
         if not self.destroyed:
             # Movement
             self.y += self.speed
             self.rect.y = int(self.y)
             # Fire
             self.fire()
             # Check if reached bottom
             if self.rect.top == self.screen.get_rect().bottom:
                 GOL.get_go(Base).take_dmg(self.hp)
                 GOL.del_go(self)
     else:
         if self.spawn_timer <= 0:
             self.spawned = True
         else:
             self.spawn_timer -= 1
Beispiel #4
0
 def update(self):
     # Sprite to draw selection.
     #1 -IF Destroyed check
     if self.destroyed == True:
         if self.expl_timer >= len(self.sprites_expl) * self.expl_time:
             self.sprite_index = 0
             self.sprite = self.sprites_expl[self.sprite_index]
         elif self.expl_timer < (len(self.sprites_expl) - 1 -
                                 self.sprite_index) * self.expl_time:
             self.sprite_index += 1
             self.sprite = self.sprites_expl[self.sprite_index]
         elif self.expl_timer <= 0:
             GOL.del_go(self)
         self.expl_timer -= 1
     #2 -If Alive dmg check
     elif self.hp <= self.max_hp * (len(self.sprites) - 1 -
                                    self.sprite_index) / len(self.sprites):
         self.sprite_index += 1
         self.sprite = self.sprites[self.sprite_index]
Beispiel #5
0
 def update(self):
     self.time -= 1
     if self.time <= 0:
         GOL.del_go(self)