コード例 #1
0
ファイル: sceneshow.cpp プロジェクト: eduardok/rockbot
void sceneShow::play_music(int n)
{
    if (playmusic_list.size() <= n) {
        std::cout << "ERROR: Scene PlayMusic[" << n << "] invalid. List size is " << image_scenes.size() << "." << std::endl;
        exit(-1);
    }
    soundManager.stop_music();
    soundManager.load_music(playmusic_list.at(n).filename);
    soundManager.play_music();
}
コード例 #2
0
bool classPlayer::get_item(object_colision &obj_info)
{
	if (character::get_item(obj_info)) {
		return true;
	}

	bool res = false;
	// deal with non-blocking items
	if (obj_info._object != NULL && obj_info._object->finished() == false) {
		//std::cout << "classPlayer::get_item" << std::endl;
		switch (obj_info._object->get_type()) {
		case OBJ_ENERGY_TANK:
            if (game_save.items.energy_tanks < 9) {
                game_save.items.energy_tanks++;
            }
			obj_info._object->set_finished(true);
			soundManager.play_sfx(SFX_GOT_ITEM);
            res = true;
			break;
		case OBJ_WEAPON_TANK:
            if (game_save.items.weapon_tanks == 0) {
                game_save.items.weapon_tanks++;
            }
			obj_info._object->set_finished(true);
			soundManager.play_sfx(SFX_GOT_ITEM);
            res = true;
			break;
		case OBJ_LIFE:
            game_save.items.lifes++;
            if (game_save.items.lifes > 9) {
                game_save.items.lifes = 9;
            }
			obj_info._object->set_finished(true);
			soundManager.play_sfx(SFX_GOT_ITEM);
            res = true;
			break;
		case OBJ_WEAPON_PILL_BIG:
			obj_info._object->set_finished(true);
			recharge(ENERGY_TYPE_WEAPON, ENERGY_ITEM_BIG);
            res = true;
			break;
		case OBJ_WEAPON_PILL_SMALL:
			obj_info._object->set_finished(true);
			recharge(ENERGY_TYPE_WEAPON, ENERGY_ITEM_SMALL);
            res = true;
			break;
		default:
			//std::cout << "classPlayer::get_item - unknown item type: " << obj_info._object->get_type() << std::endl;
			break;
		}
	}
	return res;
}
コード例 #3
0
ファイル: sceneshow.cpp プロジェクト: protoman/rockbot
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;
}
コード例 #4
0
void classPlayer::recharge(e_energy_types _en_type, int value)
{
	if (_en_type == ENERGY_TYPE_HP) {
		character::recharge(_en_type, value);
	} else if (_en_type == ENERGY_TYPE_WEAPON) {
        if (game_save.items.weapons[selected_weapon] < PLAYER_INITIAL_HP) {
            if (game_save.items.weapons[selected_weapon] + value <= PLAYER_INITIAL_HP) {
                game_save.items.weapons[selected_weapon] += value;
			} else {
                game_save.items.weapons[selected_weapon] = PLAYER_INITIAL_HP;
			}
			soundManager.play_sfx(SFX_GOT_ENERGY);
			if (value > ENERGY_ITEM_SMALL) {
				soundManager.play_sfx(SFX_GOT_ENERGY);
			}
		}
	}
}
コード例 #5
0
ファイル: sceneshow.cpp プロジェクト: eduardok/rockbot
void sceneShow::play_sfx(int n)
{
    if (playsfx_list.size() <= n) {
        std::cout << "ERROR: Scene PlaySFX[" << n << "] invalid. List size is " << image_scenes.size() << "." << std::endl;
        exit(-1);
    }
    if (playsfx_list.at(n).repeat_times < 1) {
        playsfx_list.at(n).repeat_times = 1;
    }
    soundManager.play_sfx_from_file(playsfx_list.at(n).filename, playsfx_list.at(n).repeat_times);
}
コード例 #6
0
ファイル: main.cpp プロジェクト: farleyknight/rockbot
int main(int argc, char *argv[])
{
    get_filepath();
    fio.read_game(game_data);
    soundManager.init_audio_system();

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

    sceneShow show;
    show.show_scene(0);

    input.wait_keypress();


    return 1;
}
コード例 #7
0
void classPlayer::reset_charging_shot()
{
    if (selected_weapon != WEAPON_DEFAULT) { // only do this, if using normal weapon
        return;
    }
    state.attack_timer = 0;
    attack_button_released = true;
    soundManager.stop_repeated_sfx();
    if (color_keys[0].r != -1) {
        change_char_color(color_keys[0], color_keys[0], true);
    }
    if (color_keys[1].r != -1) {
        change_char_color(color_keys[1], color_keys[1], true);
    }
    // also reset slide/dash
    if (state.animation_type == ANIM_TYPE_SLIDE) {
        set_animation_type(ANIM_TYPE_WALK);
        state.slide_distance = 0;
    }
}
コード例 #8
0
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);
	}
}
コード例 #9
0
ファイル: sceneshow.cpp プロジェクト: eduardok/rockbot
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);
        }
    }
}
コード例 #10
0
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();
    }
}
コード例 #11
0
ファイル: class_config.cpp プロジェクト: eduardok/rockbot
// column1: normal, ape,    daisie, dynamite, mummy,     spike
// column2:         techno, mage,   seahorse, item coil, item jet
// column3: e-tank, w-tank *(must be changed, as currently are two rows)
void class_config::move_cursor(Sint8 x_inc, Sint8 y_inc) {
	// left/right: if position exists, just move. if not then go to first item in nexct column or stays in place
	bool moved = false;
    st_position res;

    //std::cout << ">>>>> class_config::move_cursor - xinc: " << x_inc << ", y_inc: " << y_inc << std::endl;

    if (ingame_menu_pos.y != 6) { // weapons positions
        if (x_inc > 0) {
            if (ingame_menu_pos.x == 0) {
                res = move_weapon_curstor_right();
                if (res.x != -1) {
                    ingame_menu_pos = res;
                    moved = true;
                }
            } else {
                res = move_weapon_curstor_left(); // right on right column - move left
                if (res.x != -1) {
                    ingame_menu_pos = res;
                    moved = true;
                }
			}
		} else if (x_inc < 0 && ingame_menu_pos.y != 0) {
            if (ingame_menu_pos.x == 0) {
                res = move_weapon_curstor_right(); // left on left column - move right
                if (res.x != -1) {
                    ingame_menu_pos = res;
                    moved = true;
                }
            } else {
                res = move_weapon_curstor_left();
                if (res.x != -1) {
                    ingame_menu_pos = res;
                    moved = true;
                }
			}

		}
    } else { // energy drinks position
		if (x_inc > 0 && ingame_menu_pos.y != 0) {
			if (ingame_menu_pos.x < 2) {
				ingame_menu_pos.x++;
			} else {
				ingame_menu_pos.x = 0;
			}
			moved = true;
		} else if (x_inc < 0) {
			if (ingame_menu_pos.x == 0) {
				ingame_menu_pos.x = 2;
			} else {
				ingame_menu_pos.x--;
			}
			moved = true;
		}
	}





	if (y_inc > 0) {
		if (ingame_menu_pos.y < 6) {
            res = move_weapon_curstor_down();
            if (res.y != -1) {
                ingame_menu_pos = res;
                moved = true;
            }
        } else {
            ingame_menu_pos.x = 0;
            ingame_menu_pos.y = 0;
		}
		moved = true;
    } else if (y_inc < 0) {
        if ((ingame_menu_pos.x == 0 && ingame_menu_pos.y == 0) || (ingame_menu_pos.x == 1 && ingame_menu_pos.y == 1)) { // when on top, go to energy drinks section
            std::cout << "MOVE CURSOR #1" << std::endl;
			ingame_menu_pos.y = 6;
		} else {
            if (ingame_menu_pos.y == 6 && ingame_menu_pos.x == 2) { // just fix x, as there is no third column on weapons section as there is in the energy drinks section
				ingame_menu_pos.x = 1;
			}
            res = move_weapon_curstor_up();
            if (res.y != -1) {
                ingame_menu_pos = res;
                moved = true;
            }
		}
	}
	if (moved == true) {
		soundManager.play_sfx(SFX_CURSOR);
    }
}
コード例 #12
0
ファイル: class_config.cpp プロジェクト: eduardok/rockbot
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--;
    }
}
コード例 #13
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;
}
コード例 #14
0
void classPlayer::execute_projectiles()
{
    // animate projectiles
    vector<projectile>::iterator it;
    bool ignore_hit_timer = false;
    if (_simultaneous_shots > 1) {
        ignore_hit_timer = true;
    }

    for (it=projectile_list.begin(); it<projectile_list.end(); it++) {
        if ((*it).is_finished == true) {
            projectile_list.erase(it);
            break;
        }
        st_size moved = (*it).move();

        //std::cout << "projectile.move_type: " << (*it)->get_move_type() << std::endl;

        /// @TODO projectiles that are tele-guided
        if ((*it).get_move_type() == TRAJECTORY_CHAIN) {
            (*it).set_y(position.y+frameSize.height/2);
        } else if ((*it).get_move_type() == TRAJECTORY_QUAKE) {
            damage_ground_npcs();
            continue;
        }
        (*it).draw();
        if ((*it).is_reflected == true) {
            continue;
        }
        // check colision agains enemies
        std::vector<classnpc*>::iterator enemy_it;
        for (enemy_it=map->_npc_list.begin(); enemy_it != map->_npc_list.end(); enemy_it++) {
            if ((*it).is_finished == true) {
                projectile_list.erase(it);
                break;
            }
            if ((*enemy_it)->is_on_visible_screen() == false) {
                continue;
            }
            if ((*enemy_it)->is_dead() == true) {
                continue;
            }



            //classnpc* enemy = (*enemy_it);
            if ((*it).check_colision(st_rectangle((*enemy_it)->getPosition().x, (*enemy_it)->getPosition().y, (*enemy_it)->get_size().width, (*enemy_it)->get_size().height), st_position(moved.width, moved.height)) == true) {
                if ((*enemy_it)->is_shielded((*it).get_direction()) == true) { // shielded NPC -> reflects shot
                    if ((*it).get_trajectory() == TRAJECTORY_CHAIN) {
                        (*it).consume_projectile();
                    } else {
                        (*it).reflect();
                    }
                    continue;
                }
                if ((*enemy_it)->is_invisible() == true) { // invisible NPC -> ignore shot
                    continue;
                }





                // check if have hit area, and if hit it
                st_rectangle enemy_hit_area = (*enemy_it)->get_hit_area();
                st_size enemy_size = (*enemy_it)->get_size();
                enemy_hit_area.x += (*enemy_it)->getPosition().x-1;
                enemy_hit_area.y += (*enemy_it)->getPosition().y;

                //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "] - npc.h: " << enemy_size.height << ", hit_area.h: " << enemy_hit_area.h << std::endl;
                if (enemy_hit_area.w != enemy_size.width || enemy_hit_area.h != enemy_size.height) {
                    //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "] - use hit_area" << std::endl;
                    if ((*it).check_colision(enemy_hit_area, st_position(moved.width, moved.height)) == false) { // hit body, but not the hit area -> reflect
                        //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "]Projectile missed - enemy_hit_area.w: " << enemy_hit_area.w << ", enemy_hit_area.h: " << enemy_hit_area.h << std::endl;
                        (*it).consume_projectile();
                        continue;
                    }
                //} else {
                    //std::cout << ">> PLAYER::execute_projectiles[" << (*enemy_it)->getName() << "] - DONT use hit_area" << std::endl;
                }

                short wpn_id = (*it).get_weapon_id();

                //std::cout << "******* wpn_id: " << wpn_id << std::endl;
                if (wpn_id < 0) {
                    wpn_id = 0;
                }

                //std::cout << ">> player weapon damage #1" << std::endl;
                //std::cout << "******* (*enemy_it)->is_using_circle_weapon(): " << (*enemy_it)->is_using_circle_weapon() << ", (*it)->get_trajectory(): " << (*it)->get_trajectory() << ", TRAJECTORY_CHAIN: " << TRAJECTORY_CHAIN << std::endl;
                // NPC using cicrcle weapon, is only be destroyed by CHAIN, but NPC won't take damage
                if ((*enemy_it)->is_using_circle_weapon() == true ) {
                    if ((*it).get_trajectory() == TRAJECTORY_CHAIN) {
                        //std::cout << "PLAYER projectile hit NPC centered-weapon" << std::endl;
                        (*enemy_it)->consume_projectile();
                    }
                    (*it).consume_projectile();
                    return;
                }

                if ((*it).get_damage() > 0) {
                    int multiplier = game_data.game_npcs[(*enemy_it)->get_number()].weakness[wpn_id].damage_multiplier;
                    if (multiplier <= 0) {
                        multiplier = 1;
                    }
                    (*enemy_it)->damage((*it).get_damage() * multiplier, ignore_hit_timer);
                }
                if ((*it).get_damage() > 0) {
                    (*it).consume_projectile();
                    soundManager.play_sfx(SFX_NPC_HIT);
                }
            }
        }
    }
}