Exemple #1
0
    def _handle_mob_collide_mob(self, mob1: Mob, mob2: Mob, data,
                                arbiter: pymunk.Arbiter) -> bool:
        if(mob1.get_id() == "mushroom"):
            mob1.set_tempo(-1 * mob1.get_tempo()) #change the mob direction => reverse the tempo
        if(mob2.get_id() == "mushroom"):
            mob2.set_tempo(-1 * mob2.get_tempo())  #change the mob direction

        if mob1.get_id() == "fireball" or mob2.get_id() == "fireball":
            self._world.remove_mob(mob1)
            self._world.remove_mob(mob2)

        return False
Exemple #2
0
    def _handle_mob_collide_mob(self, mob1: Mob, mob2: Mob, data,
                                arbiter: pymunk.Arbiter) -> bool :
        '''
        when the mushroom hit a fireball it will be destroyed and when he hit another mushroom it will
        change its direction
        '''
        if mob1.get_id() == "fireball" or mob2.get_id() == "fireball" :
            self._world.remove_mob(mob1)
            self._world.remove_mob(mob2)
        if mob1.get_velocity() == "mushroom" or mob2.get_id() == "mushroom" :
            mob1.set_tempo(-mob1.get_tempo())
            mob2.set_tempo(-mob2.get_tempo())

        return False
Exemple #3
0
    def _handle_mob_collide_block(self, mob: Mob, block: Block, data,
                                  arbiter: pymunk.Arbiter) -> bool:
        if(mob.get_id() == "mushroom"): #to change the mob direction when he touch a block
            if get_collision_direction(block, mob) == "L" or get_collision_direction(block, mob) == "R":
                mob.set_tempo(-1 * mob.get_tempo())

        if mob.get_id() == "fireball":
            if block.get_id() == "brick":
                self._world.remove_block(block)
            self._world.remove_mob(mob)
        return True
Exemple #4
0
    def _handle_mob_collide_mob(self, mob1: Mob, mob2: Mob, data,
                                arbiter: pymunk.Arbiter) -> bool:
        if mob1.get_id() == "fireball" or mob2.get_id() == "fireball":
            self._world.remove_mob(mob1)
            self._world.remove_mob(mob2)
        elif mob1.get_id(
        ) == 'bullet_l' or mob1.get_id == 'bullet_r' or mob2.get_id(
        ) == 'bullet_l' or mob2.get_id == 'bullet_r':
            self._world.remove_mob(mob1)
            self._world.remove_mob(mob2)
        elif mob1.get_id() == "gang" and mob2.get_id() == "mushroom":
            return False
        elif mob1.get_id() == "mushroom" and mob2.get_id() == "gang":
            return False
        elif mob1.get_id() == "gang" and mob2.get_id() == "gang":
            return False
        elif mob1.get_id() == "mushroom" and mob2.get_id() == "mushroom":
            mob1.set_tempo(-mob1.get_tempo())
            mob2.set_tempo(-mob2.get_tempo())
        else:
            self._world.remove_mob(mob1)
            self._world.remove_mob(mob2)

        return False
Exemple #5
0
 def _handle_mob_collide_block(self, mob: Mob, block: Block, data,
                               arbiter: pymunk.Arbiter) -> bool :
     '''
     handle when the mob hit other block
     when the mob is fireball and hit a brick, the block will be destroyed
     when the mob is mushroom and hit a brick, it will change its direction
     '''
     if mob.get_id() == "fireball" :
         if block.get_id() == "brick" :
             self._world.remove_block(block)
         self._world.remove_mob(mob)
     if mob.get_id() == "mushroom":
         if get_collision_direction(mob, block) == "L" or get_collision_direction(mob, block) == "R" :
             mob.set_tempo(-mob.get_tempo())
     return True
Exemple #6
0
    def _handle_mob_collide_block(self, mob: Mob, block: Block, data,
                                  arbiter: pymunk.Arbiter) -> bool:
        if mob.get_id() == "fireball" or mob.get_id(
        ) == 'bullet_l' or mob.get_id() == 'bullet_r':
            if block.get_id() == "brick":
                self._world.remove_block(block)
                self._world.remove_mob(mob)
            else:
                self._world.remove_mob(mob)
        elif mob.get_id(
        ) == "mushroom":  # mushroom bounces back a little when encountering blocks
            if get_collision_direction(
                    mob, block) == "R" or get_collision_direction(
                        mob, block) == "L":
                mob.set_tempo(-mob.get_tempo())
        elif mob.get_id(
        ) == 'gang':  # gang jumps over the blocks when encountering them
            if get_collision_direction(mob, block) == "R":
                mob.set_velocity((50, -350))
            elif get_collision_direction(mob, block) == "L":
                mob.set_velocity((-50, -350))

        return True
Exemple #7
0
 def _handle_player_collide_mob(self, player: Player, mob: Mob, data,
                                arbiter: pymunk.Arbiter) -> bool :
     ''' handle when the player hit some mob, when they are colliding, the on_hit function will run'''
     if mob.get_id() == "mushroom" :
         if get_collision_direction(player, mob) == "L" or get_collision_direction(player, mob) == "R" :
             if self._player.get_invincible() :
                 self._world.remove_mob(mob)
             elif self._powerup.get_powerup():
                 self._powerup.set_powerup(False)
             else :
                 mob.on_hit(arbiter, (self._world, player))
                 mob.set_tempo(-mob.get_tempo())
         if get_collision_direction(player, mob) == "A":
             mob.on_hit(arbiter, (self._world, player))
     if mob.get_id() == "fireball" :
         if self._player.get_invincible() :
             self._world.remove_mob(mob)
         elif self._powerup.get_powerup():
             self._powerup.set_powerup(False)
         else :
             mob.on_hit(arbiter, (self._world, player))
             self._world.remove_mob(mob)
     return True