コード例 #1
0
ファイル: main_state.py プロジェクト: foresty0722/2d-game
def ready_game():
    global gameState
    gameState = GAMESTATE_READY
    game_world.remove_objects_at_layer(game_world.layer_obstacle)
    game_world.remove_objects_at_layer(game_world.layer_item)
    player.init(Life.LIFE_AT_START)
    update_score()
コード例 #2
0
def ready_game():
    global gameState
    gameState = GAMESTATE_READY
    game_world.remove_objects_at_layer(game_world.layer_obstacle)
    game_world.remove_objects_at_layer(game_world.layer_item)

    f = open('stage_' + str(stage_number) + '.json', 'r')
    data = json.load(f)
    f.close()

    global stage
    stage = data

    wall.bg_index = data['bg_pattern']
    bricks = data['bricks']

    global ball
    ball.x, ball.y, ball.angle, ball.speed = tuple(data['ball'])
    for d in bricks:
        brick = Brick(d["x"], d["y"], d["t"])
        game_world.add_object(brick, game_world.layer_obstacle)

    global scoreStatic, scoreLabel
    if 'label_s1' in data:
        scoreStatic.color = tuple(data['label_s1'])
    if 'label_s2' in data:
        scoreLabel.color = tuple(data['label_s2'])
    # player.init(Life.LIFE_AT_START)
    update_score()
コード例 #3
0
def ready_game():
    global gameState
    gameState = GAMESTATE_READY
    game_world.remove_objects_at_layer(game_world.layer_obstacle)
    game_world.remove_objects_at_layer(game_world.layer_item)

    global stage_number, max_stage_number

    try:
        f = open('stage_' + str(stage_number) + '.json', 'r')
        data = json.load(f)
        f.close()
        if max_stage_number <= stage_number:
            max_stage_number = stage_number + 1
    except IOError:
        data = None

    global stage

    if data == None:
        bricks = []
        stage['bricks'] = []
    else:
        stage = data

        wall.bg_index = data['bg_pattern']
        bricks = data['bricks']

    global ball
    ball.x, ball.y, ball.angle, ball.speed = tuple(stage['ball'])

    bricks = list(map(lambda d: Brick(d["x"], d["y"], d["t"]), bricks))
    bricks.sort(key=lambda b: b.orderValue())
    for b in bricks:
        game_world.add_object(b, game_world.layer_obstacle)

    global scoreStatic, scoreLabel, nameLabel
    if 'label_s1' in stage:
        color = tuple(stage['label_s1'])
        scoreStatic.color = color
        nameStatic.color = color
    if 'label_s2' in stage:
        color = tuple(stage['label_s2'])
        scoreLabel.color = color
        nameLabel.color = color
    if 'designer' in stage:
        nameLabel.text = stage['designer']

    global brick
    brick = Brick(0, 0, 1, True)

    update_score()
    update_stage_label()
    update_bg_index()
コード例 #4
0
def ready_game():
    #global gameState
    #gameState = GAMESTATE_READY
    game_world.remove_objects_at_layer(game_world.LAYER_MONSTER)
    game_world.remove_all_item()                

    f = open('monster.json', 'r')
    monster_data = json.load(f)
    f.close()

    f = open('room.json', 'r')
    room_data = json.load(f)
    f.close()

    monster_arr = None
    item_data = None
    # 방, 몬스터 정보 받기      
    for o in game_world.background_objects():
        if o.GetID() == ID.ROOM:
            if roomNum == CAVE_0:
                monster_arr = monster_data['cave_0']    
                room_info = room_data['cave_0']    
                o.SetRoom(CAVE_0)
            elif roomNum == CAVE_1:
                monster_arr = monster_data['cave_1']
                room_info = room_data['cave_1']    
                o.SetRoom(CAVE_1)
            elif roomNum == CAVE_2:
                monster_arr = monster_data['cave_2']
                room_info = room_data['cave_2']    
                o.SetRoom(CAVE_2)
            elif roomNum == CAVE_3:
                monster_arr = monster_data['cave_3']
                room_info = room_data['cave_3']    
                o.SetRoom(CAVE_3)
            elif roomNum == CABIN_0:
                monster_arr = monster_data['cabin_0']
                room_info = room_data['cabin_0']    
                o.SetRoom(CABIN_0)
            elif roomNum == CABIN_1:
                monster_arr = monster_data['cabin_1']
                room_info = room_data['cabin_1']    
                o.SetRoom(CABIN_1)
            elif roomNum == CABIN_2:
                monster_arr = monster_data['cabin_2']
                room_info = room_data['cabin_2']    
                o.SetRoom(CABIN_2)
            elif roomNum == CABIN_3:
                monster_arr = monster_data['cabin_3']
                room_info = room_data['cabin_3']    
                o.SetRoom(CABIN_3)
            break;


    for o in game_world.background_objects():
        if o.GetID() == ID.ROOM:
            if not o.GetIsClear():    
                # 몬스터 생성
                for d in monster_arr:
                    if d["ID"] == ID.FLY:
                        _monster = fly.Fly(d["x"], d["y"])
                    elif d["ID"] == ID.MEAT:
                        _monster = meat.Meat(d["x"], d["y"])
                    elif d["ID"] == ID.HOPPER:
                        _monster = hopper.Hopper(d["x"], d["y"])
                    elif d["ID"] == ID.GHOST:
                        _monster = ghost.Ghost(d["x"], d["y"])
                    game_world.add_object(_monster, game_world.LAYER_MONSTER)
                # 아이템 미리 생성
                item_data = item.Item(room_info["item"], 400, 150)
                game_world.add_object(item_data, game_world.LAYER_BG)
                break;

    # 문 생성
    for o in game_world.background_objects():
        if o.GetID() == ID.ROOM:
            o.SetDoor(room_info["left"], room_info["right"], room_info["up"], room_info["down"], room_info["stage"])