当前位置: 首页>>代码示例>>Python>>正文


Python Map.draw_map方法代码示例

本文整理汇总了Python中map.Map.draw_map方法的典型用法代码示例。如果您正苦于以下问题:Python Map.draw_map方法的具体用法?Python Map.draw_map怎么用?Python Map.draw_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在map.Map的用法示例。


在下文中一共展示了Map.draw_map方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import draw_map [as 别名]

#.........这里部分代码省略.........
            x_ = self.check_map_width((self.map.camera.x*(-1)+self.player.x)/32) 
            y_ = self.check_map_height((self.map.camera.y*(-1)+self.player.y+42)/32)                
        elif self.last_input[K_RIGHT]:
            x_ = self.check_map_width((self.map.camera.x*(-1)+self.player.x+24)/32)
            y_ = self.check_map_height((self.map.camera.y*(-1)+self.player.y+42)/32)
        elif self.last_input[K_UP]:
            x_ = self.check_map_width((self.map.camera.x*(-1) + self.player.x+16)/32)
            y_ = self.check_map_height((self.map.camera.y*(-1) + self.player.y+16*(1))/32)
        elif self.last_input[K_DOWN]:
            x_ = self.check_map_width((self.map.camera.x*(-1) + self.player.x+16)/32)
            y_ = self.check_map_height((self.map.camera.y*(-1) + self.player.y+48)/32)
        if self.map.map_tiles[x_][y_].object is not None and self.map.map_tiles[x_][y_].object.type == 'NPC':
            if self.map.map_tiles[x_][y_].object.has_dialog:
                file_name = u'%s_%s' % (self.player.name, self.map.map_tiles[x_][y_].object.name)
                if file_name.upper() not in dialog.DIALOGUES:
                    dialog.load_dialog(file_name.upper())
                dialog.dialog(self.player, self.map, self.map.map_tiles[x_][y_].object.get_position, file_name)
    
    def move_left(self, x_, y_):
        if self.map.map_tiles[x_][y_].can_walk:
            if not self.map.move(self.walk_speed, 0):
                if not (self.player.x + self.walk_speed*(-1)) < 0:
                    self.player.move(self.walk_speed*(-1), 0)
        self.player.change_sprite(self.walk_speed*(-1), 0)
    
    def move_right(self, x_, y_):
        if self.map.map_tiles[x_][y_].can_walk:
            if not self.map.move(self.walk_speed*(-1), 0):
                if not (self.player.x + self.walk_speed) > global_data.screen_width - (self.player.image.get_width()/4):
                    self.player.move(self.walk_speed, 0)
        self.player.change_sprite(self.walk_speed, 0)

    def move_up(self, x_, y_):
        if self.map.map_tiles[x_][y_].can_walk:
            if not self.map.move(0, self.walk_speed):
                if not (self.player.y + self.walk_speed*(-1)) < 0:
                    self.player.move(0, self.walk_speed*(-1))
        elif self.map.map_tiles[x_][y_].object is not None:
            self.object_map_collider(self.map.map_tiles[x_][y_].object, x_, y_)
        self.player.change_sprite(0, self.walk_speed*(-1))

    def move_down(self, x_, y_):
        if self.map.map_tiles[x_][y_].can_walk:
            if not self.map.move(0, self.walk_speed*(-1)):
                if not (self.player.y + self.walk_speed) > global_data.screen_height - \
                        (self.player.image.get_height()/4):
                    self.player.move(0, self.walk_speed)
        self.player.change_sprite(0, self.walk_speed)

    def object_map_collider(self, object, x_, y_):
        if object.type == 'PORTAL':
            if not self.map.map_tiles[x_][y_].object.name in self.maps:
                self.maps[self.map.map_tiles[x_][y_].object.name] = Map(self.map.map_tiles[x_][y_].object.name) 
            self.map = self.maps[self.map.map_tiles[x_][y_].object.name]

    """ Recebe o input do jogador e realiza a ação de acordo com a tecla pressionada """
    def player_input(self, key_pressed):
        """
        calcula qual será a posição futura do personagem em relação ao mapa geral usando a posição da 
        camera em relação ao mapa e do personagem e do personagem em relação a camera
        """
        #x_, y_ = (self.map.camera.x*(-1)+self.player.x)/32, (self.map.camera.y*(-1)+self.player.y)/32
         
        if key_pressed[K_RETURN]:
            self.key_return()
        
        elif key_pressed[K_LEFT]:
            x_ = self.check_map_width((self.map.camera.x*(-1)+self.player.x)/32) 
            y_ = self.check_map_height((self.map.camera.y*(-1)+self.player.y+42)/32)
            self.move_left(x_, y_)

        elif key_pressed[K_RIGHT]:
            x_ = self.check_map_width((self.map.camera.x*(-1)+self.player.x+24)/32)
            y_ = self.check_map_height((self.map.camera.y*(-1)+self.player.y+42)/32)
            self.move_right(x_, y_)

        elif key_pressed[K_UP]:
            x_ = self.check_map_width((self.map.camera.x*(-1) + self.player.x+16)/32)
            y_ = self.check_map_height((self.map.camera.y*(-1) + self.player.y+16*(1))/32)
            self.move_up(x_, y_)

        elif key_pressed[K_DOWN]:
            x_ = self.check_map_width((self.map.camera.x*(-1) + self.player.x+16)/32)
            y_ = self.check_map_height((self.map.camera.y*(-1) + self.player.y+48)/32)
            self.move_down(x_, y_)
            
        self.last_input = key_pressed

    def main_loop(self):
        while True:
            for ev in event.get():
                if ev.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                elif ev.type == pygame.KEYDOWN:
                    self.player_input(pygame.key.get_pressed())
                self.map.draw_map()
                self.player.draw()
                pygame.display.update()
            self.clock.tick(30)
开发者ID:joaopgom,项目名称:rpg-v2,代码行数:104,代码来源:game.py

示例2: Game

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import draw_map [as 别名]
class Game():
    def __init__(self):
        self.player = Player('CLOUD')
        self.team = None    
        self.maps = []
        self.map = Map('WORLD_MAP')
        self.time = time.Clock()
    
    def player_input(self, key_pressed):
        if key_pressed[K_LEFT]:
            self.camera_effect(3, 0)
        elif key_pressed[K_RIGHT]:
            self.camera_effect(-3, 0)
        elif key_pressed[K_UP]:
            self.camera_effect(0, 3)
        elif key_pressed[K_DOWN]:
            self.camera_effect(0, -3)
    
    def camera_effect(self, x_axis, y_axis):
        self.player.walk_change_sprite(x_axis, y_axis)

        player_x, player_y = self.player.position[0]+x_axis, self.player.position[1]+y_axis
        
        x = (self.map.camera[0] * (-1)) + self.player.position[0] if self.map.camera[0] < 0 else self.map.camera[0] + self.player.position[0]
        y = (self.map.camera[1] * (-1)) + self.player.position[1] if self.map.camera[1] < 0 else self.map.camera[1] + self.player.position[1]
        x = (x + 2) if x_axis > 0 else (x + 2)
        y = (y + 2) if y_axis > 0 else (y + 2)
        
        y = int(ceil(y/32))
        x = int(ceil(x/32))
        
        y_sum = 0
        x_sum = 0
        
        if y_axis != 0:
            y_sum = -1 if y_axis > 0 else 1
        if x_axis != 0:
            x_sum = -1 if x_axis > 0 else 1
        x += x_sum
        y += y_sum
        
        if x < 0:
            x = 0
        if x >= len(self.map.tiles[0]):
            x = len(self.map.tiles[0]) - 1 
        
        if y < 0:
            y = 0
        if y > len(self.map.tiles):
            y = len(self.map.tiles)
        #print x, y, self.map.tiles[y][x].can_walk
        if self.map.tiles[y][x].can_walk:
            if self.map.move_camera(x_axis, y_axis):
                self.map.set_camera(x_axis, y_axis)
            else:
                x_axis = x_axis*(-1)
                y_axis = y_axis*(-1)
                #print x_axis, y_axis
                if x_axis != 0:
                    if x_axis > 0:
                        if self.player.position[0] + x_axis > (800-25):
                            x_axis = 0
                    else:
                        if self.player.position[0] + x_axis + 25 < 25:
                            x_axis = 0
    
                if y_axis != 0:
                    if y_axis > 0:
                        print self.player.position[1] + y_axis
                        if self.player.position[1] + y_axis > (608-38):                                
                            y_axis = 0
                    else:
                        if self.player.position[1] + y_axis + 38 < 38:
                            y_axis = 0                                
    
                self.player.move_player(x_axis, y_axis)
    
    def main_loop(self):
        pygame.key.set_repeat(1, 10)
        while True:
            
            for ev in event.get():
                if ev.type == pygame.QUIT:
                    for i in range(30):
                        for j in range(30):
                           if not self.map.tiles[i][j].can_walk:
                               print i, j, self.map.tiles[i][j] 
            
                    pygame.quit()
                    sys.exit()
                elif ev.type == pygame.KEYDOWN:
                    self.player_input(pygame.key.get_pressed())            
            self.map.draw_map()
            self.player.draw()
            self.player.make_move = False
            pygame.display.update()
            self.time.tick(15)
开发者ID:joaopgom,项目名称:rpg-pygame,代码行数:99,代码来源:game.py

示例3: spawn_monster_guarding_item

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import draw_map [as 别名]
    while play_level:

        if counter == 22 - level:
            spawn_monster_guarding_item(monster_spawner, item_spawner)
            counter = 0

        if cheat_activated:
            print("Player position {}".format(player.pos))
            print("Door position {}".format(door_pos))
            for monster in monster_spawner.monster_list:
                print("Monster position {}".format(monster.pos))
            for item in item_spawner.item_list:
                print("Item position {}".format(item.pos))

        player.heal()
        map.draw_map(player.pos)
        direction_dict = map.collision_detection(player.pos)

        direction = input("Where would you like to go?")
        direction = direction.lower()
        if direction_dict["S"] and (direction == "s" or direction == "south" or direction == "d" or direction == "down"):
            player.pos_y += 1
        elif direction_dict["N"] and (direction == "n" or direction == "north" or direction == "u" or direction == "up"):
            player.pos_y -= 1
        elif direction_dict["E"] and (direction == "e" or direction == "east" or direction == "r" or direction == "right"):
            player.pos_x += 1
        elif direction_dict["W"] and (direction == "w" or direction == "west" or direction == "l" or direction == "left"):
            player.pos_x -= 1
        elif direction == "cheat":
            cheat_activated = True
            print("Cheating activated")
开发者ID:Krasi2405,项目名称:Dungeon-Game,代码行数:33,代码来源:dungeon_game.py


注:本文中的map.Map.draw_map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。