Esempio n. 1
0
void sceneShow::show_scene(int n)
{
    if (n < 0) {
        return;
    }
    if (scene_list.size() <= n) {
        std::cout << "ERROR: Scene List[" << n << "] invalid. List size is " << image_scenes.size() << "." << std::endl;
        return;
    }
    CURRENT_FILE_FORMAT::file_scene_list scene = scene_list.at(n);
    input.clean();

    for (int i=0; i<SCENE_OBJECTS_N; i++) {
        input.read_input();
        int scene_seek_n = scene.objects[i].seek_n;
        //std::cout << ">> sceneShow::show_scene - i: " << i << ", scene_seek_n: " << scene_seek_n << std::endl;

        if (_interrupt_scene == true || input.p1_input[BTN_START] == 1) {
            scene_seek_n = -1;
            break;
        }

        if (scene_seek_n != -1) {
            int scene_type = scene.objects[i].type;
            //std::cout << "### scene_type[" << scene_type << "]" << std::endl;
            if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SHOW_TEXT) {
                show_text(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_CLEAR_AREA) {
                clear_area(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_CLEAR_SCREEN) {
                graphLib.clear_area(0 ,0, RES_W, RES_H, 0, 0, 0);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_MOVE_IMAGE) {
                show_image(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_MOVE_VIEWPOINT) {
                show_viewpoint(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_PLAY_MUSIC) {
                play_music(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_PLAY_SFX) {
                play_sfx(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SHOW_ANIMATION) {
                show_animation(scene_seek_n, scene.objects[i].repeat_value, scene.objects[i].repeat_type);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_STOP_MUSIC) {
                soundManager.stop_music();
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SUBSCENE) {
                show_scene(scene_seek_n);
            } else {
                std::cout << ">> sceneShow::show_scene - unknown scene_type[" << scene_type << "]" << std::endl;
            }
            std::cout << "show_scene::DELAY[" << i << "][" << scene.objects[i].delay_after << "]" << std::endl;
            if (input.waitScapeTime(scene.objects[i].delay_after) == 1) {
                _interrupt_scene = true;
            }
        } else {
            break;
        }
    }
    std::cout << "show_scene::DONE" << std::endl;
}
Esempio n. 2
0
void sceneShow::clear_area(int n)
{
    if (cleararea_list.size() <= n) {
        std::cout << "ERROR: Scene ClearArea[" << n << "] invalid. List size is " << image_scenes.size() << "." << std::endl;
        exit(-1);
    }
    graphLib.clear_area(cleararea_list.at(n).x, cleararea_list.at(n).y, cleararea_list.at(n).w, cleararea_list.at(n).h, cleararea_list.at(n).r, cleararea_list.at(n).g, cleararea_list.at(n).b);
    graphLib.updateScreen();
}
Esempio n. 3
0
void sceneShow::run_text(CURRENT_FILE_FORMAT::file_scene_show_text text)
{

    int lines_n = 0;
    int max_line_w = 0;
    for (int i=0; i<SCENE_TEXT_LINES_N; i++) {
        std::string line = std::string(text.text_lines[i]);
        if (line.size() > 0) {
            if (line.size() > max_line_w) {
                max_line_w = line.size();
            }
            lines_n++;
        }
    }

    int center_x = (RES_W * 0.5) - (max_line_w/2 * FONT_SIZE);
    int center_y = (RES_H * 0.5) - (lines_n * (LINE_H_DIFF * 0.5));
    int pos_x = 0;
    int pos_y = 0;

    if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_dialogbottom) {
        pos_x = 10;
        pos_y = 140;
    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_dialogtop) {
        pos_x = 10;
        pos_y = 10;
    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_centered) {
        pos_x = center_x;
        pos_y = center_y;

    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_center_x) {
        pos_x = center_x;
        pos_y = text.y;

    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_center_y) {
        pos_x = text.x;
        pos_y = center_y;

    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_user_defined) {
        pos_x = text.x;
        pos_y = text.y;
    }

    for (int i=0; i<SCENE_TEXT_LINES_N; i++) {
        std::string line = std::string(text.text_lines[i]);
        if (line.length() < 1) {
            break;
        }
        int adjusted_y = pos_y+(LINE_H_DIFF*i);
        graphLib.clear_area(pos_x, adjusted_y, strlen(text.text_lines[i])*9, 8, 0, 0, 0);
        graphLib.draw_progressive_text(pos_x, adjusted_y, line, false);
    }
}
int key_map::draw_config_keys() const
{
    st_position config_text_pos;
    config_text_pos.x = graphLib.get_config_menu_pos().x + 74;
    config_text_pos.y = graphLib.get_config_menu_pos().y + 40;
    input.clean();
    input.waitTime(100);
    input.clean();
    input.waitTime(100);

    graphLib.clear_area(config_text_pos.x, config_text_pos.y, 180,  180, 0, 0, 0);
    std::vector<std::string> options;
    options.push_back("RESET TO DEFAULT");
    options.push_back("SET JUMP");
    options.push_back("SET ATTACK");
    options.push_back("SET SHIELD");
    options.push_back("SET DASH");
    options.push_back("SET L");
    options.push_back("SET R");
    options.push_back("SET START");

    // -- NEW -- //
    if (game_config.input_mode == INPUT_MODE_DIGITAL) {
        options.push_back("DIRECTIONAL: DIGITAL");
    } else {
        options.push_back("DIRECTIONAL: ANALOG");
    }
    // -- NEW --//
    if (game_config.input_mode == INPUT_MODE_DIGITAL) {
        options.push_back("SET UP");
        options.push_back("SET DOWN");
        options.push_back("SET LEFT");
        options.push_back("SET RIGHT");
    }



    short selected_option = 0;
    option_picker main_config_picker(false, config_text_pos, options, true);
    selected_option = main_config_picker.pick();
    std::cout << "key_map::draw_config_keys - selected_option: " << selected_option << std::endl;
    return selected_option;
}
Esempio n. 5
0
void gfx_sin_wave::show(int x, int y)
{
    float angle_max = 3.14 * SIN_STEPS;
    float angle_step = angle_max / surface->width;
    float angle = 0;
    for (int j=0; j<max_amplitude; j++) {
        graphLib.clear_area(x, y, surface->width, surface->height, 0, 0, 0);
        for (int i=0; i<surface->height; i++) {
            float pos_x = (sin(angle) + x)*amplitude;
            int pos_y = i + y;
            angle += angle_step;
            //std::cout << "i[" << i << "], pos_x[" << pos_x << "], pos_y[" << pos_y << "]" << std::endl;
            graphLib.showSurfacePortion(surface, st_rectangle(0, i, surface->width, 1), st_rectangle(pos_x, pos_y, surface->width, 1));
        }
        amplitude--;
        graphLib.updateScreen();
        timer.delay(40);
    }
}
void key_map::redraw_line(short line) const
{
    std::cout << "******* key_map::redraw_line - line: " << line << std::endl;
    st_position config_text_pos;
    config_text_pos.x = graphLib.get_config_menu_pos().x + 74;
    config_text_pos.y = graphLib.get_config_menu_pos().y + 40;
    graphLib.clear_area(config_text_pos.x+70-1, config_text_pos.y-1 + line*CURSOR_SPACING, 110,  CURSOR_SPACING+1, 0, 0, 0);
    ///@TODO -
    /*
    if (key_config[line].key_type == 0) {
        graphLib.draw_text(config_text_pos.x + 70, config_text_pos.y + line*CURSOR_SPACING, "JOYSTICK"); // input type (joystick/keyboard)
    } else {
        graphLib.draw_text(config_text_pos.x + 70, config_text_pos.y + line*CURSOR_SPACING, "KEYBOARD"); // input type (joystick/keyboard)
    }
    */

    std::stringstream key_n_ss;
    ///@TODO - key_n_ss << key_config[line].key_number;

    graphLib.draw_text(config_text_pos.x + 140, config_text_pos.y + line*CURSOR_SPACING, key_n_ss.str()); //input code (number)
}
Esempio n. 7
0
void sceneShow::show_scene(int n)
{
    if (scene_list.size() <= n) {
        std::cout << "ERROR: Scene List[" << n << "] invalid. List size is " << image_scenes.size() << "." << std::endl;
        exit(-1);
    }
    CURRENT_FILE_FORMAT::file_scene_list scene = scene_list.at(0);
    for (int i=0; i<SCENE_OBJECTS_N; i++) {
        int scene_seek_n = scene.objects[i].seek_n;
        if (scene_seek_n != -1) {
            int scene_type = scene.objects[i].type;
            if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SHOW_TEXT) {
                show_text(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_CLEAR_AREA) {
                clear_area(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_CLEAR_SCREEN) {
                graphLib.clear_area(0 ,0, RES_W, RES_H, 0, 0, 0);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_MOVE_IMAGE) {
                show_image(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_MOVE_VIEWPOINT) {
                /// @TODO
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_PLAY_MUSIC) {
                play_music(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_PLAY_SFX) {
                play_sfx(scene_seek_n);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SHOW_ANIMATION) {
                show_animation(scene_seek_n, scene.objects[i].repeat_value, scene.objects[i].repeat_type);
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_STOP_MUSIC) {
                soundManager.stop_music();
            } else if (scene_type == CURRENT_FILE_FORMAT::SCENETYPE_SUBSCENE) {
                show_scene(scene_seek_n);
            }
            timer.delay(scene.objects[i].delay_after);
        }
    }
}
void key_map::draw_screen()
{
    bool finished = false;
    st_position config_text_pos;
    st_position cursor_pos;
    short _pick_pos = 0;

    config_text_pos.x = graphLib.get_config_menu_pos().x + 74;
    config_text_pos.y = graphLib.get_config_menu_pos().y + 40;
    cursor_pos = config_text_pos;

    graphLib.clear_area(config_text_pos.x-1, config_text_pos.y-1, 180,  180, 0, 0, 0);
    input.clean();
    input.waitTime(300);

    for (unsigned int i=0; i<_keys_list.size(); i++) {
        graphLib.draw_text(config_text_pos.x, config_text_pos.y + i*CURSOR_SPACING, _keys_list[i].c_str());
        redraw_line(i);
    }
    graphLib.draw_text(config_text_pos.x, config_text_pos.y + _keys_list.size()*CURSOR_SPACING, "RETURN");
    draw_lib.update_screen();

    //cout << "scenesLib::option_picker::START\n";
    graphLib.drawCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));

    while (finished == false) {
        input.readInput();
        if (input.p1_input[BTN_START]) {
            if (_pick_pos == (short)_keys_list.size()) {
                std::cout << "key_map::draw_screen - FINISHED #1" << std::endl;
                finished = true;
            } else {
                graphLib.draw_text(config_text_pos.x, config_text_pos.y + _keys_list.size()*CURSOR_SPACING+CURSOR_SPACING*2, "PRESS NEW KEY/BUTTON"); //input code (number)
                draw_lib.update_screen();
                //format_v_2_1_1::st_key_config new_key = input.get_pressed_key();
                graphLib.clear_area(config_text_pos.x, config_text_pos.y + _keys_list.size()*CURSOR_SPACING+CURSOR_SPACING*2-1, 180,  CURSOR_SPACING+1, 0, 0, 0);
                ///@TODO - key_config[_pick_pos].key_type = new_key.key_type;
                ///@TODO - key_config[_pick_pos].key_number = new_key.key_number;
                redraw_line(_pick_pos);
                draw_lib.update_screen();
            }
        }
        if (input.p1_input[BTN_DOWN]) {
                soundManager.play_sfx(SFX_CURSOR);
                graphLib.eraseCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
                _pick_pos++;
                if (_pick_pos >= (short)_keys_list.size()+1) {
                    _pick_pos = 0;
                }
                graphLib.drawCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
        }
        if (input.p1_input[BTN_UP]) {
                soundManager.play_sfx(SFX_CURSOR);
                graphLib.eraseCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
                _pick_pos--;
                if (_pick_pos < 0) {
                    _pick_pos = _keys_list.size();
                }
                graphLib.drawCursor(st_position(cursor_pos.x-CURSOR_SPACING, cursor_pos.y+(_pick_pos*CURSOR_SPACING)));
        }
        if (input.p1_input[BTN_QUIT]) {
            std::cout << "key_map::draw_screen - FINISHED #2" << std::endl;
            finished = true;
        }
        input.clean();
        input.waitTime(10);
        draw_lib.update_screen();
    }
}
void key_map::config_input()
{
    CURRENT_FILE_FORMAT::st_game_config game_config_copy = game_config;
    int selected_option = 0;

    while (selected_option != -1) {
        selected_option = draw_config_keys();

        std::cout << "key_map::config_input - selected_option: " << selected_option << std::endl;

        if (selected_option == 0) {
            game_config.set_default_keys();
            std::cout << "key_map::config_input - LEAVE #1" << std::endl;
        } else if (selected_option == -1) {
            std::cout << "key_map::config_input - LEAVE #2" << std::endl;
            // apply changes to game-config
            apply_key_codes_changes(game_config_copy);
            return;

        // -- NEW -- //
        } else if (selected_option == 8) {
            if (game_config.input_mode == INPUT_MODE_DIGITAL) {
                game_config.input_mode = INPUT_MODE_ANALOG;
            } else {
                game_config.input_mode = INPUT_MODE_DIGITAL;
            }
        // -- NEW -- //


        } else {
            std::cout << "key_map::config_input - PICK KEY #1" << std::endl;
            INPUT_COMMANDS selected_key = BTN_JUMP;
            if (selected_option == 1) {
                selected_key = BTN_JUMP;
            } else if (selected_option == 2) {
                selected_key = BTN_ATTACK;
            } else if (selected_option == 3) {
                selected_key = BTN_SHIELD;
            } else if (selected_option == 4) {
                selected_key = BTN_DASH;
            } else if (selected_option == 5) {
                selected_key = BTN_L;
            } else if (selected_option == 6) {
                selected_key = BTN_R;
            } else if (selected_option == 7) {
                selected_key = BTN_START;
            } else if (selected_option == 9) {
                selected_key = BTN_UP;
            } else if (selected_option == 10) {
                selected_key = BTN_DOWN;
            } else if (selected_option == 11) {
                selected_key = BTN_LEFT;
            } else if (selected_option == 12) {
                selected_key = BTN_RIGHT;
            }

            st_position menu_pos(graphLib.get_config_menu_pos().x + 74, graphLib.get_config_menu_pos().y + 40);
            graphLib.clear_area(menu_pos.x, menu_pos.y, 180,  180, 0, 0, 0);
            graphLib.draw_text(menu_pos.x, menu_pos.y, "PRESS A KEY OR BUTTON");
            input.clean();
            input.waitTime(20);
            bool is_joystick = input.pick_key_or_button(game_config_copy, selected_key);
            check_key_duplicates(game_config_copy, selected_key, is_joystick);
        }
    }
    // apply changes to game-config
    apply_key_codes_changes(game_config_copy);
}
Esempio n. 10
0
void sceneShow::clear_screen()
{
    graphLib.clear_area(0, 0, RES_W, RES_H, 0, 0, 0);
    graphLib.updateScreen();
}
Esempio n. 11
0
void sceneShow::run_text(CURRENT_FILE_FORMAT::file_scene_show_text text)
{

    int lines_n = 0;
    int max_line_w = 0;

    // this part is used to calculate text/lines size for positioning
    /// @TODO: optimize using a vector
    std::vector<int> string_id_list;
    for (int i=0; i<SCENE_TEXT_LINES_N; i++) {
        string_id_list.push_back(text.line_string_id[i]);
    }

    std::vector<std::string> text_lines;
    for (int i=0; i<SCENE_TEXT_LINES_N; i++) {

        std::string line = fio_str.get_scenes_string(text.line_string_id[i]);

        if (line.size() > 0) {
            text_lines.push_back(line);
            if (line.size() > max_line_w) {
                max_line_w = line.size();
            }
            // only count as line if not empty
            lines_n = i+1;
        } else {
            text_lines.push_back(std::string(" "));
        }
    }

    int center_x = (RES_W * 0.5) - (max_line_w/2 * FONT_SIZE);
    int center_y = (RES_H * 0.5) - (lines_n * (SCENES_LINE_H_DIFF * 0.5));
    int pos_x = 0;
    int pos_y = 0;

    if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_dialogbottom) {
        pos_x = 10;
        pos_y = SCENES_TEXT_BOTTOM_POSY;
    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_dialogtop) {
        pos_x = 10;
        pos_y = 10;
    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_centered) {
        pos_x = center_x;
        pos_y = center_y;

    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_center_x) {
        pos_x = center_x;
        pos_y = text.y;

    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_center_y) {
        pos_x = text.x;
        pos_y = center_y;

    } else if (text.position_type == CURRENT_FILE_FORMAT::text_position_type_user_defined) {
        pos_x = text.x;
        pos_y = text.y;
    }

    std::vector<std::string> lines;
    int max_w = 0;
    for (int i=0; i<text_lines.size(); i++) {
        std::string line = std::string(text_lines.at(i));
        if (line.length() < 1) {
            break;
        }
        lines.push_back(line);
        if (line.length() * FONT_SIZE > max_w) {
            max_w = line.length() * (FONT_SIZE+5);
        }
    }
    // clear text area
    int max_h = lines.size()*SCENES_LINE_H_DIFF;
    std::cout << "lines[" << lines.size() << "], max_w[" << max_w << "], max_h[" << max_h << "]" << std::endl;
    graphLib.clear_area(pos_x, pos_y, max_w, max_h, 0, 0, 0);


    for (int i=0; i<lines.size(); i++) {
        if (input.p1_input[BTN_START] == 1) {
            _interrupt_scene = true;
            break;
        }
        std::string line = std::string(lines.at(i));
        int adjusted_y = pos_y+(SCENES_LINE_H_DIFF*i);
        graphLib.clear_area(pos_x, adjusted_y, line.length()*9, 8, 0, 0, 0);
        if (graphLib.draw_progressive_text(pos_x, adjusted_y, line, false, 30) == 1) {
            _interrupt_scene = true;
            break;
        }
    }
    std::cout << "run_text::DONE" << std::endl;
}