示例#1
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)

        return False
示例#2
0
文件: app.py 项目: Uncccle/SuperMario
    def _handle_player_collide_mob(self, player: Player, mob: Mob, data,
                                   arbiter: pymunk.Arbiter) -> bool:

        if self._player_star.activated():
            self._world.remove_mob(mob)
            return False
        else:
            if mob._id == "mushroom":
                if mob.dead:
                    return False
                if get_collision_direction(player, mob) == "A":
                    self._renderer.kill_mushroom(mob.get_shape())
                    mob.freeze()
                    self._master.after(500,
                                       lambda: self._world.remove_mob(mob))
                    self._can_jump = True
                    self._jump()
                    return True

            mob.on_hit(arbiter, (self._world, player))
            self._status_view.set_health(self._player.get_health())
            self._status_view.set_score(self._player.get_score())

            if self._player.get_health() == 0:
                tk.messagebox.showinfo("Gameover", "You died.")
                self._master.quit()
            return True
示例#3
0
 def _handle_player_collide_mob(self, player: Player, mob: Mob, data,
                                arbiter: pymunk.Arbiter) -> bool:
     if player.is_niubi():
         self._world.remove_mob(mob)
     elif player.is_shoot():
         player.set_shoot(False)
     else:
         mob.on_hit(arbiter, (self._world, player))
     return True
示例#4
0
文件: app.py 项目: Uncccle/SuperMario
 def _handle_mob_collide_block(self, mob: Mob, block: Block, data,
                               arbiter: pymunk.Arbiter) -> bool:
     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(block, mob) in ("L", "R"):
             mob.direction *= -1
     return True
示例#5
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
示例#6
0
文件: world.py 项目: DDusa/a3_files
    def add_mob(self, mob: Mob, x: float, y: float, friction: float = 1.):
        """Adds a mob to the game world centred at the position ('x', 'y')

        Parameters:
            mob (Mob): The mob to add to the game world

            - See add_thing for other parameters
        """

        self.add_thing(mob, x, y, mob.get_size(), collision_type=self._collision_types['mob'],
                       categories=self._thing_categories["mob"], mass=mob.get_weight(), friction=friction)
示例#7
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
示例#8
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
示例#9
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
示例#10
0
def create_mob(world: World, mob_id: str, x: int, y: int, *args):
    """Create a new mob instance and add it to the world based on the mob_id.

    Parameters:
        world (World): The world where the mob should be added to.
        mob_id (str): The mob identifier of the mob to create.
        x (int): The x coordinate of the mob.
        y (int): The y coordinate of the mob.
    """
    mob_id = MOBS[mob_id]
    if mob_id == "cloud":
        mob = CloudMob()
    elif mob_id == "fireball":
        mob = Fireball()
    elif mob_id == "mushroom":
        mob = Mushroom()
    elif mob_id == 'gang':
        mob = Gang()
    elif mob_id == 'bullet_l':
        mob = BulletLeft()
    elif mob_id == 'bullet_r':
        mob = BulletRight()
    else:
        mob = Mob(mob_id, size=(1, 1))

    world.add_mob(mob, x * BLOCK_SIZE, y * BLOCK_SIZE)
示例#11
0
 def _handle_mob_collide_block(self, mob: Mob, block: Block, data,
                               arbiter: pymunk.Arbiter) -> bool:
     if mob.get_id() == "fireball":
         if block.get_id() == "brick":
             self._world.remove_block(block)
         self._world.remove_mob(mob)
     return True
示例#12
0
    def _handle_player_collide_mob(self, player: Player, mob: Mob, data,
                                   arbiter: pymunk.Arbiter) -> bool:
        # A collision with a mob make Mario Lost a health.
        # When Mario is Invincible Mario Lost and gain a life.
        # Thus, the health don't change tough the collision heppened
        if player.invincible == True :
            player.change_health(1)

        if(type(mob) is MushroomMob):
            if get_collision_direction(player, mob) == "A": #in case if the player is above the mushroomMob
                player.set_velocity((0, 100)) #the player up
                mob.destroy() #destroy the mob
            else:#in case the collision is on another direction
                player.change_health(-1) #the player should lose health
                player.set_velocity((2 * mob.get_velocity()[0], 0)) , #the player should be slightly repelled away

        mob.on_hit(arbiter, (self._world, player))
        return True
示例#13
0
 def _draw_mob(self, instance: Mob, shape: pymunk.Shape, view: tk.Canvas,
               offset: Tuple[int, int]) -> List[int]:
     image = self.load_image(self._mob_images[instance.get_id()])
     return [
         view.create_image(shape.bb.center().x + offset[0],
                           shape.bb.center().y,
                           image=image,
                           tags="mob")
     ]
示例#14
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
示例#15
0
 def _handle_player_collide_mob(self, player: Player, mob: Mob, data,
                                arbiter: pymunk.Arbiter) -> bool:
     mob.on_hit(arbiter, (self._world, player))
     return True
示例#16
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
示例#17
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