Exemplo n.º 1
0
    def _handle_player_collide_block(self, player: Player, block: Block, data,
                                     arbiter: pymunk.Arbiter) -> bool:

        if(block.get_id() == "bounce"):  # Propel Mario when collide to BounceBlock
            self._player.set_velocity((0, -180))

        if(block.get_id()== "flag"):
            self.addScore() #to let the player enter his name to add the score on the highscore file
            self.level = self.getNextLevel(self.level) #get the nextLevel using the config File
            self.reset_world(self.level)
            if(get_collision_direction(player, block) == "A"): #increase the player health in case his on top of the flag
                player.change_health(1)

        if(block.get_id()=="tunnel" and get_collision_direction(player, block) == "A" and self.down_pressed is True): #GO THE NEXT LEVEL IF the player pressed up on top of the tunnel
            self.level = self.getNextTunnelLevel(self.level)
            self.reset_world(self.level)

        #Removing the bricks on the left and on the right of the switch
        if block.get_id() == "switch" and get_collision_direction(player, block) == "A":
            x,y = block.get_position()
            block1 = self._world.get_block(x-GRID_WIDTH,y-block.getCollNum()*GRID_HEIGHT)
            block2 = self._world.get_block(x+GRID_WIDTH,y+block.getCollNum()*GRID_HEIGHT)
            self._world.remove_block(block1)
            self._world.remove_block(block2)
            block.incrementcollNum()

        block.on_hit(arbiter, (self._world, player))
        return True
Exemplo n.º 2
0
    def _handle_player_collide_block(self, player: Player, block: Block, data,
                                     arbiter: pymunk.Arbiter) -> bool:
        if get_collision_direction(player, block) == "A":
            self._can_jump = True

        if block._id == "bouncy":
            if get_collision_direction(player, block) == "A":
                self._renderer.activate_bouncy(block.get_shape())
        elif block._id == "switch":
            if block.activated():
                return False
        elif block._id == "flagpole":
            name = self._ask_name()
            score_name = self._current_level.replace(".txt", "_score.txt")
            self._scores.load_scores(score_name)
            self._scores.add_score(name, self._player.get_score())
            self._scores.save_scores(score_name)
            self.reset_world(block._next_level)
        block.on_hit(arbiter, (self._world, player))
        return True
Exemplo n.º 3
0
 def _handle_player_collide_block(self, player: Player, block: Block, data,
                                  arbiter: pymunk.Arbiter) -> bool :
     ''' handle when the player hit some blocks, when they are colliding, the on_hit function will run'''
     if block.get_id() == "switch":
         block.on_hit(arbiter, (self._world, player))
         return False
     if block.get_id() == "flag":
         if get_collision_direction(player, block) == "L" or get_collision_direction(player, block) == "R":
             self.reset_world(new_level=block.get_filename())
         if get_collision_direction(player, block) == "A" :
             block.on_hit(arbiter, (self._world, player))
     if block.get_id() == "tunnel":
         if get_collision_direction(player, block) == "A":
             #
             self._master.bind("s", lambda a : self._tunnel(block))
             self._master.bind("<Down>", lambda a : self._tunnel(block))
     else:
         block.on_hit(arbiter, (self._world, player))
     return True
Exemplo n.º 4
0
    def _handle_player_collide_block(self, player: Player, block: Block, data,
                                     arbiter: pymunk.Arbiter) -> bool:

        if get_collision_direction(
                player, block
        ) == "A":  # when player touch the blocks, set jumping to false
            self._player.set_jumping(False)

        if block.get_id() == "flag":
            if get_collision_direction(player, block) == "A":
                block.on_hit(arbiter, data)
            else:
                # tell the player to input their name and see if the score records need to be updated
                self.update_score()
                if self.get_next_level(
                ) == 'END':  # if there's no further level, ask if start over
                    ans = messagebox.askokcancel(
                        'Good job, you finish the game', 'Start Over?')
                    if ans:
                        self.reset_world('level1.txt')
                        self._level = 'level1.txt'
                        self._player.clear_score()
                        self._player.change_health(
                            self._player.get_max_health())
                        self.redraw_status()
                    else:
                        self._master.destroy()
                else:
                    self.reset_world(self.get_next_level())
                    self._level = self.get_next_level()
        elif block.get_id() == "tunnel":
            if get_collision_direction(
                    player, block) == "A" and self._player.is_duck() is True:
                self._player.set_duck(False)
                self.reset_world(self.get_next_level())
        elif block.get_id() == 'switches':
            if block.is_active():
                block.on_hit(arbiter, (self._world, player))

        block.on_hit(arbiter, (self._world, player))
        return True
Exemplo n.º 5
0
    def _handle_player_collide_block(self, player: Player, block: Block, data,
                                     arbiter: pymunk.Arbiter) -> bool:

        block.on_hit(arbiter, (self._world, player))
        return True