void dialogs::show_timed_dialog(std::string face_file, bool is_left, std::string lines[], short delay, bool show_btn=true)
{
    UNUSED(is_left);
    std::string temp_text;
    char temp_char;

    timer.pause();

    draw_dialog_bg(show_btn);
    draw_lib.update_screen();
    st_position dialog_pos = graphLib.get_dialog_pos();
    graphLib.place_face(face_file, st_position(dialog_pos.x+16, dialog_pos.y+16));
    draw_lib.update_screen();

    /// @TODO: usar show_config_bg e hide_config_bg da graphLib - modificar para aceitar centered (que é o atual) ou top ou bottom
    for (int i=0; i<3; i++) {
        for (unsigned int j=0; j<lines[i].size(); j++) {
            temp_char = lines[i].at(j);
            temp_text = "";
            temp_text += temp_char;

            graphLib.draw_text(j*9+(dialog_pos.x+52), i*11+(dialog_pos.y+16), temp_text);
            //graphLib.draw_text(j*9+53, i*11+9, "A");
            draw_lib.update_screen();
            input.waitTime(15);
        }
    }
    input.waitTime(delay);
    timer.unpause();
}
/// @TODO: fix animation. investigate a better way for drawing it (code is way too confusing)
void classMap::redraw_boss_door(bool is_close, int nTiles, int tileX, short player_number) {
	int k, tileCount;
	//is_close = false; // THIS IS A TEMPORARY FIX

	//std::cout << "classMap::redraw_boss_door - is_close: " << is_close << std::endl;

	input.waitTime(10);
	//for (k=0; k<tilePieces; k++) {
	for (k=0; k<nTiles; k++) {
		tileCount = nTiles;
		//if (is_close == false) { std::cout << "classMap::redraw_boss_door - nTiles: " << nTiles << ", tilePieces: " << tilePieces << ", tileCount: " << tileCount << std::endl; }
		// redraw screen
		showMap();
		graphLib.updateScreen();
		int tiles_showed;
		if (is_close == false) {
			tiles_showed = k;
		} else {
			tiles_showed = 0;
		}
		for (int i=0; i<MAP_W; i++) {
			for (int j=0; j<MAP_H; j++) {
				if (map_tiles.tiles[i][j].tile3.x != -1 && map_tiles.tiles[i][j].tile3.y != -1) {
						if (i == tileX && map_tiles.tiles[i][j].locked == TERRAIN_DOOR) {
							//std::cout << "****** redraw_boss_door - k: " << k << ", tiles_showed: " << tiles_showed << ", nTiles: " << nTiles << std::endl;
							if (is_close == false) {
								if (tiles_showed < nTiles) {
									graphLib.placeTile(st_position(map_tiles.tiles[i][j].tile3.x, map_tiles.tiles[i][j].tile3.y), st_position((i*TILESIZE)-scroll.x, (j*TILESIZE)-scroll.y), &graphLib.gameScreen);
									graphLib.updateScreen();
									tiles_showed++;
								}
							} else {
								if (tiles_showed < k) {
									graphLib.placeTile(st_position(map_tiles.tiles[i][j].tile3.x, map_tiles.tiles[i][j].tile3.y), st_position((i*TILESIZE)-scroll.x, (j*TILESIZE)-scroll.y), &graphLib.gameScreen);
									graphLib.updateScreen();
									tiles_showed++;
								}
							}
						} else {
							graphLib.placeTile(st_position(map_tiles.tiles[i][j].tile3.x, map_tiles.tiles[i][j].tile3.y), st_position((i*TILESIZE)+scroll.x, (j*TILESIZE)-scroll.y), &graphLib.gameScreen);
						}
				}
			}
		}
		_player_list.at(0)->show();
		graphLib.draw_hp_bar(_player_list.at(0)->get_current_hp(), player_number, WEAPON_DEFAULT);
		//show_sprite(p1Obj->sprite, game_screen);
		//draw_hp_bar(p1Obj);
		graphLib.updateScreen();
		input.waitTime(100);
	}
	input.waitTime(100);
}
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;
}
示例#4
0
int main(int argc, char *argv[])
{
	quick_load = false;
	UNUSED(argc);
	gameControl.currentStage = TECHNOBOT;
	game_config.selected_player = 1;

	//strncpy (FILEPATH, argv[0], strlen(argv[0])-11);

	string argvString = string(argv[0]);

	FILEPATH = argvString.substr(0, argvString.size()-EXEC_NAME.size());
	//std::cout << "main - FILEPATH: " << FILEPATH << std::endl;

	format_v_2_0_1::file_io fio;
	fio.read_game(game_data);

	// INIT GRAPHICS
	if (graphLib.initGraphics() != true) {
		exit(-1);
	}

	// INIT GAME
	if (quick_load == false) {
		if (gameControl.showIntro() == false) {
			return 0;
		}
	} else {
		gameControl.quick_load_game();
		//ending game_ending;
		//game_ending.start();
	}

	input.clean();
	input.p1_input[BTN_START] = 0;
	input.waitTime(200);
	input.clean();
	while (true) {
		input.readInput();
		if (input.p1_input[BTN_QUIT] == 1) {
			exit(-1);
		}
		gameControl.showGame();
		graphLib.updateScreen();
	}
	/// @TODO: sdl quit sub-systems
	SDL_Quit();
	return 1;
}
示例#5
0
bool dialogs::show_leave_game_dialog() const
{
    bool res = false;
    bool repeat_menu = true;
    int picked_n = -1;

    timer.pause();

    std::cout << ">>>>>>> show_leave_game_dialog::START" << std::endl;

    graphicsLib_gSurface bgCopy;
    graphLib.initSurface(st_size(RES_W, RES_H), &bgCopy);
    graphLib.copyArea(st_position(0, 0), &graphLib.gameScreen, &bgCopy);

    graphLib.show_dialog(0, false);
    st_position dialog_pos = graphLib.get_dialog_pos();
    graphLib.draw_text(dialog_pos.x+30, dialog_pos.y+16, "QUIT GAME?");
    std::vector<std::string> item_list;
    item_list.push_back("YES");
    item_list.push_back("NO");
    option_picker main_picker(false, st_position(dialog_pos.x+40, dialog_pos.y+16+11), item_list, false);
    draw_lib.update_screen();
    while (repeat_menu == true) {
        picked_n = main_picker.pick();
        std::cout << "picked_n: " << picked_n << std::endl;
        if (picked_n == 0) {
            res = true;
            repeat_menu = false;
        } else if (picked_n == 1) {
            res = false;
            repeat_menu = false;
        } else {
            main_picker.draw();
        }
    }
    input.clean();
    input.waitTime(200);
    graphLib.copyArea(st_position(0, 0), &bgCopy, &graphLib.gameScreen);
    draw_lib.update_screen();
    timer.unpause();

    std::cout << ">>>>>>> show_leave_game_dialog::END" << std::endl;

    return res;
}
void classPlayer::teleport_stand()
{
	unsigned int waitTimer = timer.getTimer()+500;
	state.animation_state = ANIM_TYPE_TELEPORT;
	/*
	if (p2Obj) {
		p2Obj->sprite->anim_type = ANIM_TELEPORT;
	}
	*/
	soundManager.play_sfx(SFX_TELEPORT);
	while (waitTimer > timer.getTimer()) {
        draw_lib.update_screen();
		show();
		/*
		if (p2Obj) {
			show_sprite(p2Obj->sprite, game_screen);
		}
		*/
		//drawMap3rdLevel(game_screen);
		//updateScreen(game_screen);
		input.waitTime(20);
	}
}
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);
}
示例#9
0
bool class_config::execute_ingame_menu()
{
    st_position old_pos;


    if (input.p1_input[BTN_START] == 1) {
        input.clean();
        input.waitTime(300);
        // leaving menu, removes pause
        if (ingame_menu_active == true) {
            timer.unpause();
        }
        ingame_menu_active = !ingame_menu_active;

        if (ingame_menu_active) {
            timer.pause();
            generate_weapons_matrix();
            draw_ingame_menu();
        } else {
            // change player color/weapon
            if (ingame_menu_pos.y != 6) {
                player_ref->set_weapon(convert_menu_pos_to_weapon_n(ingame_menu_pos));
            } else {
                // use item
                use_tank(ingame_menu_pos.x);
                ingame_menu_active = !ingame_menu_active; // keep itself inside the menu
                generate_weapons_matrix();
                draw_ingame_menu();
            }
        }
    }

    if (ingame_menu_active) {
        old_pos.x = ingame_menu_pos.x;
        old_pos.y = ingame_menu_pos.y;
        if (input.p1_input[BTN_UP] == 1) {
            move_cursor(0, -1);
        } else if (input.p1_input[BTN_DOWN] == 1) {
            move_cursor(0, 1);
        } else if (input.p1_input[BTN_LEFT] == 1) {
            move_cursor(-1, 0);
        } else if (input.p1_input[BTN_RIGHT] == 1) {
            move_cursor(1, 0);
        } else if (input.p1_input[BTN_R] == 1) {
            if (gameControl.show_config(game_save.stages[gameControl.currentStage]) == true) { // player picked "leave stage" option
                ingame_menu_active = false;
                timer.unpause();
                return true;
            }
            draw_ingame_menu();
        }
        if (old_pos.x != ingame_menu_pos.x || old_pos.y != ingame_menu_pos.y) {
            //std::cout << ">> old_pos.y: " << old_pos.y << ", ingame_menu_pos.y: " << ingame_menu_pos.y << std::endl;
            if (old_pos.y != 6) {
                graphLib.draw_weapon_cursor(old_pos, player_ref->get_weapon_value(convert_menu_pos_to_weapon_n(old_pos)), -1);
                graphLib.draw_weapon_icon(convert_menu_pos_to_weapon_n(old_pos), old_pos, false);
            } else {
                graphLib.erase_menu_item(old_pos.x);
            }
            if (ingame_menu_pos.y != 6) {
                graphLib.draw_weapon_cursor(ingame_menu_pos, player_ref->get_weapon_value(convert_menu_pos_to_weapon_n(ingame_menu_pos)), player_ref->get_number());
                graphLib.draw_weapon_icon(convert_menu_pos_to_weapon_n(ingame_menu_pos), ingame_menu_pos, true);
                change_player_frame_color();
            } else {
                graphLib.draw_menu_item(ingame_menu_pos.x);
            }
        }
        input.clean();
        input.waitTime(MENU_CHANGE_DELAY);
    }
    return ingame_menu_active;
}
示例#10
0
void class_config::use_tank(int tank_type)
{
	int n = 0;

    // check tank number
    if (tank_type == TANK_ENERGY && game_save.items.energy_tanks == 0) {
        return;
    }
    if (tank_type == TANK_WEAPON && game_save.items.weapon_tanks == 0) {
        return;
    }
    if (tank_type == TANK_SPECIAL && game_save.items.special_tanks == 0) {
        return;
    }

	// no need for tank usage
	if (tank_type == TANK_ENERGY && player_ref->get_hp().current == player_ref->get_hp().total) {
		return;
	}
	if (tank_type == TANK_ENERGY || tank_type == TANK_SPECIAL) {
		while (player_ref->get_hp().current < player_ref->get_hp().total) {
			player_ref->set_current_hp(1);
			if (n == 0 || n % 6 == 0) {
				soundManager.play_sfx(SFX_GOT_ENERGY);
			}
			n++;
			//graphLib.draw_horizontal_hp_bar(WPN_COLUMN_Y, 2, player_ref->get_hp().current);
			graphLib.draw_weapon_cursor(st_position(0, 0), player_ref->get_hp().current, -1);
            draw_lib.update_screen();
			input.waitTime(50);
		}
	}
	if (tank_type == TANK_SPECIAL || tank_type == TANK_WEAPON) {
		st_position weapon_pos(0, 0);
		for (int i=0; i<WEAPON_COUNT; i++) {
			n = 0;
			short unsigned int value = player_ref->get_weapon_value(i);
			if (value < player_ref->get_hp().total) {
				while (value < player_ref->get_hp().total) {
					value++;
					player_ref->set_weapon_value(i, value);
					if (n == 0 || n % 6 == 0) {
						soundManager.play_sfx(SFX_GOT_ENERGY);
					}
					n++;
					graphLib.draw_weapon_cursor(weapon_pos, player_ref->get_weapon_value(i), -1);
                    draw_lib.update_screen();
					input.waitTime(50);
				}
			}
			weapon_pos.y = weapon_pos.y+1;
			if (weapon_pos.y > 5) {
				weapon_pos.y = 1;
				weapon_pos.x = 1;
			}
		}
	}
    // consume tank
    if (tank_type == TANK_ENERGY) {
        game_save.items.energy_tanks--;
    }
    if (tank_type == TANK_WEAPON) {
        game_save.items.weapon_tanks--;
    }
    if (tank_type == TANK_SPECIAL) {
        game_save.items.special_tanks--;
    }
}
示例#11
0
int main(int argc, char *argv[])
#endif
{


#ifdef PSP
    SetupCallbacks();
    scePowerSetClockFrequency(333, 333, 166);
#endif

    for (int i=0; i<FLAG_COUNT; i++) {
		GAME_FLAGS[i] = false;
	}
	UNUSED(argc);

    string argvString = "";
#ifndef WII
    argvString = string(argv[0]);
#else
    if (!fatInitDefault()) {
        printf("fatInitDefault ERROR #1");
        std::fflush(stdout);
        timer.delay(500);
        exit(-1);
    }
#endif


    get_filepath();
    // fallback in case getcwd returns null
    if (FILEPATH.size() == 0) {
        std::cout << "Could not read path, fallback to using argv" << std::endl;
        FILEPATH = argvString.substr(0, argvString.size()-EXEC_NAME.size());
    }
    std::cout << "main - argvString: '" << argvString << "', FILEPATH: '" << FILEPATH << "'" << std::endl; std::fflush(stdout);



#ifdef PLAYSTATION2
    std::cout << "PS2.DEBUG #1" << std::endl; std::fflush(stdout);

    #ifndef PS2LINK
    SifIopReset(NULL, 0); // clean previous loading of irx by apps like ulaunchElf. Comment this line to get cout on ps2link
    #endif

    printf("DEBUG.PS2 #1.1\n");

	/* SP193: Being creative (Do something while waiting for the slow IOP to be reset). =D */
	int main_id = GetThreadId();
    ChangeThreadPriority(main_id, 72);
    std::cout << "PS2.DEBUG #1.1" << std::endl; std::fflush(stdout);
    printf("DEBUG.PS2 #1.2\n");

    #ifndef PS2LINK
    while(SifIopSync()) {
        std::cout << "PS2.SifIopSync()" << std::endl;
    }
    #endif
	/* Initialize and connect to all SIF services on the IOP. */
	SifInitRpc(0);
	SifInitIopHeap();
	SifLoadFileInit();
	fioInit();
    printf("DEBUG.PS2 #1.3\n");

	/* Apply the SBV LMB patch to allow modules to be loaded from a buffer in EE RAM. */
	sbv_patch_enable_lmb();

    // --- DEBUG --- //
    //FILEPATH = "cdfs:/";
    // --- DEBUG --- //

    std::cout << "PS2.DEBUG #2" << std::endl; std::fflush(stdout);

    if (FILEPATH.find("mass:") != std::string::npos) {
        printf("DEBUG.PS2 #1.4\n");
        std::cout << "PS2.DEBUG Load USB" << std::endl; std::fflush(stdout);
        PS2_load_USB();
    }

    if (FILEPATH.find("cdfs") != std::string::npos || FILEPATH.find("cdrom") != std::string::npos) {
        printf("DEBUG.PS2 #1.5\n");
        std::cout << "PS2.DEBUG Load CDROM" << std::endl; std::fflush(stdout);
        FILEPATH = "cdfs:";
        PS2_load_CDROM();
    }
    printf("DEBUG.PS2 #2\n");




    std::cout << "PS2.DEBUG #3" << std::endl; std::fflush(stdout);
#endif




	// check command-line paramethers
	if (argc > 1) {
		for (int i=1; i<argc; i++) {
			std::string temp_argv(argv[i]);
			if (temp_argv == "--fullscreen") {

			} else if (temp_argv == "--quickload") {
				GAME_FLAGS[FLAG_QUICKLOAD] = true;
			} else if (temp_argv == "--invencible") { // player have infinite HP
				GAME_FLAGS[FLAG_INVENCIBLE] = true;
			} else if (temp_argv == "--allweapons") { // player have all weapons available even if
				GAME_FLAGS[FLAG_ALLWEAPONS] = true;
			} else if (temp_argv == "--infinitejump") { // player can jump again and again
				GAME_FLAGS[FLAG_INFINITE_JUMP] = true;
			}
		}
	}

    std::cout << "PS2.DEBUG #7" << std::endl; std::fflush(stdout);

    //fio.check_conversion();
	fio.read_game(game_data);


    //GAME_FLAGS[FLAG_INFINITE_HP] = true; // DEBUG


    gameControl.get_drop_item_ids();
	soundManager.init_audio_system();

// PS2 version have to load config AFTER SDL_Init due to SDK issues
#ifdef LINUX
    SAVEPATH = std::string(getenv("HOME")) + "/.rockbot/";
    mkdir(SAVEPATH.c_str(), 0777);
    //std::cout << "SAVEPATH: " << SAVEPATH << ", mkdir-res: " << res << ", errno: " << errno << std::endl;
#elif WIN32
    SAVEPATH =  std::string(getenv("APPDATA")) + "/rockbot";
    std::cout << "SAVEPATH: " << SAVEPATH << std::endl;
    _mkdir(SAVEPATH.c_str());
#else
    SAVEPATH = FILEPATH;
#endif

#ifndef PLAYSTATION2
    fio.load_config(game_config);
#endif

	// INIT GRAPHICS
	if (graphLib.initGraphics() != true) {
        printf("ERROR intializing graphic\n");
		return -1;
	}

    // define SAVEPATH
    #ifdef PLAYSTATION2
        PS2_load_MC();
        SAVEPATH = "mc0:Rockbot/";

        if (fioMkdir(SAVEPATH.c_str()) < 0) {
            std::cout << "main - warning: could not create '" << SAVEPATH << "' folder" << std::endl; std::fflush(stdout);
            /// @TODO - check if directory exists
        } else {
            std::cout << "Folder '" << SAVEPATH << "' created" << std::endl; std::fflush(stdout);
        }

    #endif
    have_save = fio.save_exists();

    #ifndef DEBUG_OUTPUT // redirect output to null
        std::string cout_file = "/dev/null";
        std::ofstream out(cout_file.c_str());
        std::cout.rdbuf(out.rdbuf());
    #else
        // --- REDIRECT STDOUT TO A FILE --- //
        #if defined(PSP) || defined(WII) || defined(ANDROID) || defined(DINGUX) || defined(PLAYSTATION2)
            //std::string cout_file = SAVEPATH + "/stdout.txt";
            std::string cout_file = FILEPATH + "/stdout.txt";
            std::streambuf *coutbuf = std::cout.rdbuf();
            std::ofstream out(cout_file.c_str());
            std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
        #endif
    #endif


    graphLib.preload();
#ifdef PLAYSTATION2
    fio.load_config(game_config);
    PS2_create_save_icons();
#endif
    draw_lib.preload();

    gameControl.currentStage = APEBOT;





	// INIT GAME
	if (GAME_FLAGS[FLAG_QUICKLOAD] == false) {
		if (gameControl.showIntro() == false) {
            std::cout << "ERROR SHOWING INTRO" << std::endl;
			return 0;
		}
	} else {
        gameControl.quick_load_game();
        //ending end_obj;
        //end_obj.start();
        //return 1;
    }

	input.clean();
	input.p1_input[BTN_START] = 0;
	input.waitTime(200);
	input.clean();

    bool run_game = true;



    while (run_game) {
        #if !defined(PSP) && !defined(DINGUX)
            timer.start_ticker();
        #endif


		#ifdef PLAYSTATION2
			RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY);
        #endif


		gameControl.showGame();
#ifdef DEBUG_SHOW_FPS
        gameControl.fps_count();
#endif
        draw_lib.update_screen();
        if (input.p1_input[BTN_QUIT] == 1) {
            //std::cout << "LEAVE #3" << std::endl;
            std::fflush(stdout);
            gameControl.leave_game();
        }
        unsigned int now_ticks = timer.get_ticks();
        if (now_ticks < (1000 / FRAMES_PER_SECOND)) {
            timer.delay((1000 / FRAMES_PER_SECOND) - now_ticks);
        }

    }
	/// @TODO: sdl quit sub-systems


	
#ifdef PSP
    sceKernelExitGame();
    return 0;
#else
    SDL_Quit();
#endif
	
	return 1;
}