Exemplo n.º 1
0
    def __init__(self, parent: object, type_id='redsprite'):
        super().__init__()
        self.type_id = Enemy.TYPES[type_id]['id']
        self.animation = copy.copy(self.TYPES[type_id]['animation'])
        self.animation.set_parent(self)
        self.animation.play_animation('idle')
        self.rect = self.image.get_rect()
        self.hitrect = self.rect
        self.sprite_type = SPRITE_ENEMY
        self.parent = parent

        self.can_collide = True
        self.collided_with = self
        self.bound_style = BOUND_KILL
        self.bounds = -50, -50, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[
            1] + 50
        self.active = True

        self.position = vector.objVector(0, 0)
        self.velocity = vector.objVector(0, 0)

        self.speed = 0
        self.health = 0
        self.invulnerable = False

        self.timer = 0

        self.phase_list = [self.defualt_move]  # contents actions of phases
        self.phase = 0
        self.phase_timer = 0

        self.fire = 0
        self.fire_pattern = [self.defualt_fire]
        self.fire_pattern_temp = {}  # contents the barrages of this enemy
        self.fire_group = pygame.sprite.Group()

        self.effect_group = pygame.sprite.Group()

        self.death_animation = death_effect.DeathEffect(self)

        self.item_list = []
        for i in range(2):
            i1 = item.Item(self.parent, 'power')
            i2 = item.Item(self.parent, 'point')
            self.item_list.append(i1)
            self.item_list.append(i2)

        self.rotating = False
        self.rotate_angle = 10
Exemplo n.º 2
0
 def collide(self):  # bomb collide with eneny
     if self.collided_with.sprite_type == SPRITE_BOSS:
         self.collided_with.health -= 1
     elif self.collided_with.sprite_type == SPRITE_ENEMY:
         self.collided_with.health -= 9999
     elif self.collided_with.sprite_type == SPRITE_BARRAGE:
         d = item.Item(self.parent, "smallpoint")
         d.position = self.collided_with.position
         d.collected = True
         self.collided_with.die()
         self.parent.item_group.add(d)
Exemplo n.º 3
0
 def summon_a_list2(self, bias=0):
     for i in range(8):
             new = enemy.Enemy(self, 'yellowsprite')
             new.bounds = 0, -30, STAGE_WIDTH_HEIGHT[0], STAGE_WIDTH_HEIGHT[1]
             new.position.x = 72*i + bias
             new.position.y = random.randrange(-20, 0)
             new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
             new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
             new.fire_pattern = [self.fire_004]
             new.phase_list = [self.motion_001_04]
             new.health = 2
             r = random.randint(0, 4)
             if r == 3:
                 i1 = item.Item(self, 'point')
                 new.item_list = [i1] 
             elif r == 4: 
                 i1 = item.Item(self, 'power')
                 new.item_list = [i1] 
             else:
                 new.item_list = [] 
             self.enemy_group.add(new)
Exemplo n.º 4
0
    def phase_006(self):
        """The sixth phase of the stage"""
        if self.timer == 1:
            for e in self.enemy_group.sprites():
                e.die()
            for b in self.barrage_group.sprites():
                d = item.Item(self, "smallpoint")
                d.position = b.position
                b.die()
                self.item_group.add(d)
            for i in self.item_group.sprites():
                i.collected = True

            b = stage_zero_margatriod.Margatriod003(self)
            self.boss_group.add(b)
Exemplo n.º 5
0
    def summon_special2(self, start, end, *args):
        new = enemy.Enemy(self, 'bluesprite')
        back_effect = bossback.BossBack002(new)
        back_effect.scale = 0.5
        new.effect_group.add(back_effect)
        self.effect_group.add(back_effect)
        new.position = start
        new.start = start
        new.end = end
        new.speed = 250*MEASURE_UNIT
        new.fire_pattern = [*args]
        new.phase_list = [self.motion_004]
        new.health = 60

        i1 = item.Item(self, 'life')
        new.item_list.append(i1)
        self.enemy_group.add(new)
Exemplo n.º 6
0
                def generate_mob(position):
                    if position <= STAGE_WIDTH_HEIGHT[0]:
                        new = enemy.Enemy(self, 'bluesprite')
                        new.bounds = -50, -1000, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[1] + 50
                        new.position.x = position
                        new.position.y = 0
                        new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
                        new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
                        new.fire_pattern = [self.fire_003_01]
                        new.phase_list = [self.motion_001_01]
                        new.health = 2

                        i1 = item.Item(self, 'power')
                        new.item_list = [i1] 

                        self.enemy_group.add(new)
                        return generate_mob(position + 80)

                    else:
                        return ''
Exemplo n.º 7
0
    def phase_002(self):
        """Phase two of the stage
        timer: the timer used to count frames player spend in this phase
        stage_zero_margatriod: the boss of this stage
        
        """
        if self.timer == 1:
            for e in self.enemy_group.sprites():
                e.die()
            for b in self.barrage_group.sprites():
                d = item.Item(self, "smallpoint")
                d.position = b.position
                b.die()
                self.item_group.add(d)
            for i in self.item_group.sprites():
                i.collected = True

            b = stage_zero_margatriod.Margatriod001(self)
            self.boss_group.add(b)
        
        if self.timer > 1 and not self.boss_group.sprites():
            self.next_phase()
Exemplo n.º 8
0
    def add_item(self, coordinates, color=None):
        """
        Adds an item to the world database
        :param color: color of the item (None for config default)
        :param coordinates: the coordinates on which the item should be added
        :return: Successful added matter; False: Unsuccessful
        """
        if isinstance(coordinates, int) or isinstance(coordinates, float):
            coordinates = (coordinates, color, 0.0)
            color = None

        elif len(coordinates) == 2:
            coordinates = (coordinates[0], coordinates[1], 0.0)

        if self.grid.are_valid_coordinates(coordinates):
            if coordinates not in self.item_map_coordinates:
                if color is None:
                    color = self.config_data.item_color
                self.new_item = item.Item(self, coordinates, color)
                self.items.append(self.new_item)
                if self.vis is not None:
                    self.vis.item_changed(self.new_item)
                self.csv_round.update_items_num(len(self.items))
                self.item_map_coordinates[
                    self.new_item.coordinates] = self.new_item
                self.item_map_id[self.new_item.get_id()] = self.new_item
                logging.info("Created item with id %s on coordinates %s",
                             str(self.new_item.get_id()), str(coordinates))
                return self.new_item

            else:
                logging.info("there is already an item on %s " %
                             str(coordinates))
                return False
        else:
            logging.info("%s is not a valid location!" % str(coordinates))
            return False
Exemplo n.º 9
0
    def phase_001(self):
        """Create enemy sprites at the correct timing
        bounds: the place of invincible wall
        position: the location of the enemy
        fire_pattern: the type of bullet pattern
        
        """
        if self.timer == 3*FRAME_PER_SECOND or self.timer == 4*FRAME_PER_SECOND:
            for i in range(3):
                for j in range(2):
                    new = enemy.Enemy(self, 'bluesprite')
                    new.bounds = -50, -1000, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[1] + 50
                    new.position.x = STAGE_WIDTH_HEIGHT[0]*0.75 + 50*j
                    new.position.y = 0 - 40*i
                    new.fire_pattern = [self.fire_001_00]
                    new.phase_list = [self.motion_001_00]

                    i1 = item.Item(self, 'power')
                    new.item_list = [i1] 

                    self.enemy_group.add(new)
        
        if 12*FRAME_PER_SECOND >= self.timer > 4*FRAME_PER_SECOND and self.timer%(2*FRAME_PER_SECOND) == 0:
            for i in range(2):
                new = enemy.Enemy(self, 'greensprite')
                new.bounds = -50, -1000, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[1] + 50
                new.position.x = random.randrange(50, STAGE_WIDTH_HEIGHT[0]-50)
                new.position.y = 0
                new.fire_pattern = [self.fire_002_00]
                new.phase_list = [self.motion_002_00]
                new.health = 5

                i1 = item.Item(self, 'power')
                i2 = item.Item(self, 'point')
                i3 = item.Item(self, 'point')
                new.item_list = [i1, i2, i3] 

                self.enemy_group.add(new)
        
        if 9.5*FRAME_PER_SECOND > self.timer >= 8*FRAME_PER_SECOND and self.timer%(0.3*FRAME_PER_SECOND) == 0:
            new = enemy.Enemy(self, 'mess2')
            new.position.x = 0
            new.position.y = STAGE_WIDTH_HEIGHT[1]*0.2
            new.fire_pattern = [self.fire_003_00]
            new.phase_list = [self.motion_003_00]
            i1 = item.Item(self, 'power')
            i2 = item.Item(self, 'point')
            i3 = item.Item(self, 'point')
            new.item_list = [i1, i2, i3] 
            new.rotating = True
            self.enemy_group.add(new)
        if 10.5*FRAME_PER_SECOND > self.timer >= 9*FRAME_PER_SECOND and self.timer%(0.3*FRAME_PER_SECOND) == 0:
            new = enemy.Enemy(self, 'mess2')
            new.position.x = STAGE_WIDTH_HEIGHT[0]
            new.position.y = STAGE_WIDTH_HEIGHT[1]*0.2
            new.fire_pattern = [self.fire_003_00]
            new.phase_list = [self.motion_003_01]
            i1 = item.Item(self, 'power')
            i2 = item.Item(self, 'point')
            i3 = item.Item(self, 'point')
            new.item_list = [i1, i2, i3] 
            new.rotating = True
            self.enemy_group.add(new)   
        if 12.5*FRAME_PER_SECOND > self.timer >= 11*FRAME_PER_SECOND and self.timer%(0.3*FRAME_PER_SECOND) == 0:
            new = enemy.Enemy(self, 'mess2')
            new.position.x = STAGE_WIDTH_HEIGHT[0]
            new.position.y = STAGE_WIDTH_HEIGHT[1]*0.2
            new.fire_pattern = [self.fire_003_00]
            new.phase_list = [self.motion_003_01]
            i1 = item.Item(self, 'power')
            i2 = item.Item(self, 'point')
            i3 = item.Item(self, 'point')
            new.item_list = [i1, i2, i3] 
            new.rotating = True
            self.enemy_group.add(new)  
        if 13.5*FRAME_PER_SECOND > self.timer >= 12*FRAME_PER_SECOND and self.timer%(0.3*FRAME_PER_SECOND) == 0:
            new = enemy.Enemy(self, 'mess2')
            new.position.x = 0
            new.position.y = STAGE_WIDTH_HEIGHT[1]*0.2
            new.fire_pattern = [self.fire_003_00]
            new.phase_list = [self.motion_003_00]
            i1 = item.Item(self, 'power')
            i2 = item.Item(self, 'point')
            i3 = item.Item(self, 'point')
            new.item_list = [i1, i2, i3] 
            new.rotating = True
            self.enemy_group.add(new)
        if 14.5*FRAME_PER_SECOND > self.timer >= 13*FRAME_PER_SECOND and self.timer%(0.5*FRAME_PER_SECOND) == 0:
            for i in range(10):
                new = enemy.Enemy(self, 'bluesprite')
                new.bounds = -50, -1000, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[1] + 50
                new.position.x = random.randrange(50, STAGE_WIDTH_HEIGHT[0]-50)
                new.position.y = random.randrange(-20, 0)
                new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
                new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
                new.fire_pattern = [self.fire_003_00]
                new.phase_list = [self.motion_001_01]
                new.health = 2

                i1 = item.Item(self, 'power')
                new.item_list = [i1] 

                self.enemy_group.add(new)

        if 20*FRAME_PER_SECOND > self.timer >= 15*FRAME_PER_SECOND and self.timer%(1.5*FRAME_PER_SECOND) == 0:

                def generate_mob(position):
                    if position <= STAGE_WIDTH_HEIGHT[0]:
                        new = enemy.Enemy(self, 'bluesprite')
                        new.bounds = -50, -1000, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[1] + 50
                        new.position.x = position
                        new.position.y = 0
                        new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
                        new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
                        new.fire_pattern = [self.fire_003_01]
                        new.phase_list = [self.motion_001_01]
                        new.health = 2

                        i1 = item.Item(self, 'power')
                        new.item_list = [i1] 

                        self.enemy_group.add(new)
                        return generate_mob(position + 80)

                    else:
                        return ''
                
                generate_mob(5)

        if 20*FRAME_PER_SECOND == self.timer:
            self.next_phase()
Exemplo n.º 10
0
    def phase_005(self):
        """The fifth phase of the stage
        
        """
        if (24*FRAME_PER_SECOND > self.timer > 12*FRAME_PER_SECOND or 10*FRAME_PER_SECOND > self.timer > 0) and self.timer % (0.5*FRAME_PER_SECOND) == 0:
            if random.randint(0, 1):
                self.summon_a_list(random.randint(0, 76))
            else:
                for i in range(4):
                    new = enemy.Enemy(self, 'yellowsprite')
                    new.bounds = -5, -10, STAGE_WIDTH_HEIGHT[0] + 5, STAGE_WIDTH_HEIGHT[1] + 5
                    new.position.x = random.randrange(50, STAGE_WIDTH_HEIGHT[0]-50)
                    new.position.y = random.randrange(-20, 0)
                    new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
                    new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
                    new.fire_pattern = [self.fire_004]
                    new.phase_list = [self.motion_001_04]
                    new.health = 5
                    if random.randint(0, 2) == 2:
                        i1 = item.Item(self, 'power')
                        new.item_list = [i1] 
                    else:
                        new.item_list = [] 
                    self.enemy_group.add(new)

        if self.timer == 10*FRAME_PER_SECOND:
            self.summon_special(
                vector.objVector(STAGE_WIDTH_HEIGHT[0], STAGE_WIDTH_HEIGHT[1]/2),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]/3, STAGE_WIDTH_HEIGHT[1]/2),
                self.fire_005, self.fire_005_01
            )

        elif self.timer == 11*FRAME_PER_SECOND:
            self.summon_special(
                vector.objVector(0, STAGE_WIDTH_HEIGHT[1]/3),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]*2/3, STAGE_WIDTH_HEIGHT[1]/3),
                self.fire_005_01, self.fire_005
            )

        elif self.timer == 25*FRAME_PER_SECOND:
            self.summon_special(
                vector.objVector(0, STAGE_WIDTH_HEIGHT[1]/2),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]/3, STAGE_WIDTH_HEIGHT[1]/2),
                self.fire_007
            )

        elif self.timer == 26*FRAME_PER_SECOND:
            self.summon_special(
                vector.objVector(STAGE_WIDTH_HEIGHT[0], STAGE_WIDTH_HEIGHT[1]/3),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]*2/3, STAGE_WIDTH_HEIGHT[1]/3),
                self.fire_007
            )

        elif 32*FRAME_PER_SECOND > self.timer > 28*FRAME_PER_SECOND and self.timer % (0.5*FRAME_PER_SECOND) == 0:
            self.summon_a_list2(random.randint(0, 76))


        elif self.timer == 34*FRAME_PER_SECOND:
            self.summon_special(
                vector.objVector(STAGE_WIDTH_HEIGHT[0]/3, 0),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]/3, STAGE_WIDTH_HEIGHT[1]/3),
                self.fire_006
            )
            self.summon_special(
                vector.objVector(STAGE_WIDTH_HEIGHT[0]*2/3, 0),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]*2/3, STAGE_WIDTH_HEIGHT[1]/3),
                self.fire_006
            )
        elif self.timer == 38*FRAME_PER_SECOND:
            self.summon_special2(
                vector.objVector(STAGE_WIDTH_HEIGHT[0]/3, 0),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]/3, STAGE_WIDTH_HEIGHT[1]/2),
                self.fire_007
            )
            self.summon_special2(
                vector.objVector(STAGE_WIDTH_HEIGHT[0]*2/3, 0),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]*2/3, STAGE_WIDTH_HEIGHT[1]/2),
                self.fire_007
            )
        elif self.timer == 36*FRAME_PER_SECOND:
            self.summon_special(
                vector.objVector(0, STAGE_WIDTH_HEIGHT[0]/3),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]/3, STAGE_WIDTH_HEIGHT[0]/3),
                self.fire_005
            )
            self.summon_special(
                vector.objVector(STAGE_WIDTH_HEIGHT[0], STAGE_WIDTH_HEIGHT[0]/2),
                vector.objVector(STAGE_WIDTH_HEIGHT[0]*2/3, STAGE_WIDTH_HEIGHT[0]/3),
                self.fire_005
            )
        elif self.timer == 40*FRAME_PER_SECOND:
            self.next_phase()
Exemplo n.º 11
0
    def phase_003(self):
        """Third phase of the stage
        velocity: the variable used to control object movement
        acceleration: object acceleration
        
        """
        if 10*FRAME_PER_SECOND > self.timer and self.timer % (0.5*FRAME_PER_SECOND) == 0:
            for i in range(3):
                new = enemy.Enemy(self, 'bluesprite')
                new.bounds = -50, -50, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[1] + 50
                new.position.x = random.randrange(50, STAGE_WIDTH_HEIGHT[0]-50)
                new.position.y = random.randrange(-20, 0)
                new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
                new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
                new.fire_pattern = [self.fire_003_02]
                new.phase_list = [self.motion_001_02]
                new.health = 3  
                if random.randint(0, 3) == 3:
                    i1 = item.Item(self, 'power')
                    new.item_list = [i1] 
                else:
                    new.item_list = [] 
                self.enemy_group.add(new)

            for i in range(2):
                new = enemy.Enemy(self, 'yellowsprite')
                new.bounds = -5, -30, STAGE_WIDTH_HEIGHT[0] + 5, STAGE_WIDTH_HEIGHT[1] + 5
                new.position.x = random.randrange(50, STAGE_WIDTH_HEIGHT[0]-50)
                new.position.y = random.randrange(-20, 0)
                new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
                new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
                new.fire_pattern = [self.fire_003_03, self.fire_003_04]
                new.phase_list = [self.motion_001_03]
                new.health = 5
                if random.randint(0, 3) == 3:
                    i1 = item.Item(self, 'largepower')
                    new.item_list = [i1] 
                else:
                    new.item_list = [] 
                self.enemy_group.add(new)

        elif self.timer >= 10*FRAME_PER_SECOND  and self.timer%(0.5*FRAME_PER_SECOND) == 0:
            for i in range(6):
                new = enemy.Enemy(self, 'bluesprite')
                new.bounds = -50, -30, STAGE_WIDTH_HEIGHT[0] + 50, STAGE_WIDTH_HEIGHT[1] + 50
                new.position.x = random.randrange(50, STAGE_WIDTH_HEIGHT[0]-50)
                new.position.y = random.randrange(-20, 0)
                new.velocity = vector.objVector(0, 200*MEASURE_UNIT)
                new.acceleration = vector.objVector(0, -2.5*MEASURE_UNIT)
                new.fire_pattern = [self.fire_003_05]
                new.phase_list = [self.motion_001_01]
                new.health = 2

                if random.randint(0, 3) == 3:
                    i1 = item.Item(self, 'point')
                    new.item_list = [i1] 
                else:
                    new.item_list = [] 
                self.enemy_group.add(new)
        
        if self.timer == 18*FRAME_PER_SECOND:
            self.next_phase()