Beispiel #1
0
 def check_collision(self, target):
     if pygame.sprite.spritecollideany(self, target):
         self.game.explosion_group.add(
             Explosion(self.rect.x, self.rect.y, 1))
         self.kill()
         # del self.game.bullets[self.game.bullets.index(self)]
         return pygame.sprite.spritecollideany(self, target)
     return False
Beispiel #2
0
    def do_damage(self, damage):
        self.hp_hero -= damage
        self.game.explosion_group.add(Explosion(self.rect.x + 35, self.rect.y, 2))

        if self.game.music_on:
            pygame.mixer.Sound('sounds/ExploseSound.mp3').play()

        if self.hp_hero <= 0:
            # del self.game.hero[self.game.hero.index(self)]
            self.kill()
            OutroLose(self.screen_size)
            self.game.running = False
Beispiel #3
0
    def update(self, *args):
        self.pos = [self.pos_x, self.pos_y]
        schedule.run_pending()
        if self.type_of_alien == 'S':
            if self.d_x == 'Right':
                self.pos_x += self.alien_speed
            elif self.d_x == 'Left':
                self.pos_x -= self.alien_speed

            if self.pos_x <= 0:
                self.pos_x = 0
                self.d_x = 'Right'
            elif self.pos_x >= self.game.width - 80:
                self.pos_x = self.game.width - 80
                self.d_x = 'Left'
            self.rect.x = self.pos_x

        elif self.type_of_alien == 'M':
            if self.d_x == 'Right':
                self.pos_x += self.alien_speed
            elif self.d_x == 'Left':
                self.pos_x -= self.alien_speed

            if self.pos_x <= 0:
                self.pos_x = 0
                self.d_x = 'Right'
            elif self.pos_x >= self.game.width - 80:
                self.pos_x = self.game.width - 80
                self.d_x = 'Left'

            if self.d_y == 'Up':
                self.pos_y += int(self.alien_speed / 2)
            elif self.d_y == 'Down':
                self.pos_y -= int(self.alien_speed / 2)

            if self.pos_y <= 0:
                self.pos_y = 0
                self.d_y = 'Up'
            elif self.pos_y >= int(self.game.height / 3):
                self.pos_y = int(self.game.height / 3)
                self.d_y = 'Down'

            self.rect.x = self.pos_x
            self.rect.y = self.pos_y

        if self.hp <= 0:
            del self.game.ints[self.game.ints.index(self)]
            schedule.clear(f'shoot {self.alien_id}')
            schedule.clear(f'start_shoot {self.alien_id}')
            self.game.explosion_group.add(
                Explosion(self.rect.x, self.rect.y, 2))
            self.kill()
Beispiel #4
0
    def update(self, *args):
        self.pos = [self.pos_x, self.pos_y]
        schedule.run_pending()
        if self.d_x == 'Right':
            self.pos_x += self.laser_speed
        elif self.d_x == 'Left':
            self.pos_x -= self.laser_speed

        if self.pos_x <= 0:
            self.pos_x = 0
            self.d_x = 'Right'
        elif self.pos_x >= self.game.width - 80:
            self.pos_x = self.game.width - 80
            self.d_x = 'Left'

        if self.d_y == 'Up':
            self.pos_y += int(self.laser_speed / 2)
        elif self.d_y == 'Down':
            self.pos_y -= int(self.laser_speed / 2)

        if self.pos_y <= 0:
            self.pos_y = 0
            self.d_y = 'Up'
        elif self.pos_y >= int(self.game.height / 3):
            self.pos_y = int(self.game.height / 3)
            self.d_y = 'Down'

        self.rect.x = self.pos_x
        self.rect.y = self.pos_y

        if self.hp <= 0:
            del self.game.lasers[self.game.lasers.index(self)]
            if self.laser:
                try:
                    self.laser.sound.stop()
                except AttributeError:
                    pass
                self.laser.kill()
            schedule.clear(f'shoot {self.alien_id}')
            schedule.clear(f'laser {self.alien_id}')
            self.game.explosion_group.add(Explosion(self.rect.x, self.rect.y, 2))
            self.kill()