我有问题清单,但没有出现。 NameError:名称“ current_room_ghost_list”未定义

时间:2019-11-20 19:46:36

标签: pygame

您好,我遇到的危险清单没有出现问题。我找不到错误。问题似乎在“坏人数据”部分中。我尝试将其初始化并将其设置为零。这一点无法解决。我不确定这是什么问题。任何帮助是极大的赞赏。谢谢


################################Creating the Health bar#############################################################################################################

def draw_health():
    box = Rect((20, 765), (350, 20))
    screen.draw.filled_rect(box, BLACK)
    screen.draw.text("HEALTH", (20, 766), color=RED)

    if health > 0:
        box = Rect((100, 765), (health, 20))
        screen.draw.filled_rect(box, RED) 




################################BAD GUY DARA ########################################################################################################################

ghost_data = {# dictionary
    #room number: [[y, x, direction, bounce addition to direction]]
    26: [[1, 8, 2, 1], [7, 3, 4, 1]], 32: [[1, 5, 4, -1]],
    27: [[1, 8, 2, 1], [7, 3, 4, 1]],
    28: [[1, 8, 2, 1], [7, 3, 4, 1]], 
    29: [[1, 8, 2, 1], [7, 3, 4, 1]],
    30: [[1, 8, 2, 1], [7, 3, 4, 1]],
    31: [[1, 8, 2, 1], [7, 3, 4, 1]],
    34: [[5, 1, 1, 1], [5, 5, 1, 2]],
    35: [[4, 4, 1, 2], [2, 5, 2, 2]],
    36: [[2, 1, 2, 2]], 32: [[1, 4, 3, 2], [5, 8, 1, 2]],
    37: [[1, 8, 2, 1], [7, 3, 4, 1]],
    38: [[1, 8, 2, 1], [7, 3, 4, 1]],
    39: [[1, 8, 2, 1], [7, 3, 4, 1]],
    40: [[3, 1, 3, -1], [6, 5, 2, 2], [7, 5, 4, 2]],
    41: [[4, 5, 2, 2], [6, 3, 4, 2], [8, 1, 2, 2]],
    44: [[2, 1, 2, 2], [4, 3, 2, 2], [6, 5, 2, 2]],
    45: [[2, 1, 2, 2], [4, 3, 2, 2], [6, 5, 2, 2]],
    46: [[2, 1, 2, 2]],
    47: [[2, 1, 2, 2], [4, 3, 2, 2], [6, 5, 2, 2]],
    48: [[1, 8, 3, 2], [8, 8, 1, 2], [3, 9, 3, 2]],
    49: [[2, 1, 2, 2], [4, 3, 2, 2], [6, 5, 2, 2]]
    }



def ghost_start():
    global current_room_ghost_list, ghost_map
    if room_the_player_is_in in ghost_data.keys():
        current_room_ghosts_list = ghost_data[room_the_player_is_in]
        for ghost in current_room_ghost_list:
            ghost_y = ghost[0]
            ghost_x = ghost[1]
            ghost_map[ghost_y][ghost_x] = 49 + (room_the_player_is_in % 1)
        clock.schedule_interval(ghost_move, 0.20)

def ghost_move():
    global current_room_ghost_list, ghost_data, ghost_map, old_player_x, old_player_y

    if game_over:
        return

    for ghost in current_room_ghost_list:
        ghost_y = ghost[0]
        ghost_x = ghost[1]
        ghost_direction = ghost[2]

        old_ghost_x = ghost_x
        old_ghost_y = ghost_y
        ghost_map[old_ghost_y][old_ghost_x] = 0 

        if ghost_direction == 1: # up
            ghost_y -= 1
        if ghost_direction == 2: # right
            ghost_x += 1
        if ghost_direction == 3: # down
            ghost_y += 1
        if ghost_direction == 4: # left
            ghost_x -= 1

        ghost_should_bounce = False

        if (ghost_y == user_y and ghost_x == user_x) or (ghost_y == from_player_y and ghost_x == from_player_x and frame_of_sprite > 0):
            sounds.ouch.play()######################################################
            deplete_health(1)
            ghost_should_bounce = True

        # Stop going out of the doors
        if ghost_x == room_width: 
            ghost_should_bounce = True
            ghost_x = room_width - 1
        if ghost_x == -1: 
            ghost_should_bounce = True
            ghost_x = 0
        if ghost_y == room_height:
            ghost_should_bounce = True
            ghost_y = room_height - 1
        if ghost_y == -1:
            ghost_should_bounce = True
            ghost_y = 0

        # Stop when hazard hits scenery or another hazard.
        if room_map[ghost_y][ghost_x] not in items_player_may_stand_on or ghost_map[ghost_y][ghost_x] != 0:
            ghost_should_bounce = True

        if ghost_should_bounce:
            ghost_y = old_ghost_y # Move back to last valid position.
            ghost_x = old_ghost_x
            ghost_direction += ghost[3]
            if ghost_direction > 4:
                ghost_direction -= 4
            if ghost_direction < 1:
                ghost_direction += 4
            ghost[2] = ghost_direction

        ghost_map[ghost_y][ghost_x] = 49 + (room_the_player_is_in % 1)
        ghost[0] = ghost_y
        ghost[1] = ghost_x

1 个答案:

答案 0 :(得分:0)

该问题是由拼写错误引起的。变量的名称是 current_room_ghost_list,而不是 current_rooms_ghost_list