void CBaseJungle::Init() { //--------------------------------------------------------------------------- //初期化 //--------------------------------------------------------------------------- SetFadeIn(); Sint32 col1 = 0xF0408080; Sint32 col2 = 0xF0808040; pGame->pBg->SetSkyColor(50,col1,col2); viiSub::SetScroll_l( GetTargetPlayer()->x , GetTargetPlayer()->y ); //--------------------------------------------------------------------------- //ファイル初期化 //--------------------------------------------------------------------------- // LoadTexture( enTexPageSoldier , "HoundData\\enemychara\\common\\ene_soldier.bmp",0xff00ff00); // UploadTexture(); //--------------------------------------------------------------------------- //エリア初期化 //--------------------------------------------------------------------------- switch(GetArea( )){ case enAreaSeq01: LoadConfig( "HoundData\\[email protected]" ); viiSub::SetScroll_l( GetTargetPlayer()->x , GetTargetPlayer()->y ); // viiMus::ReadBGM( 0,"HoundData\\bgm\\A\\A3_Bgm1.ogg"); viiMus::PlayBGM(enSoundBgm1,enMusicBgmStageA); // LoadConfig( "HoundData\\[email protected]" ); // LoadConfig( "HoundData\\[email protected]" ); // LoadConfig( "HoundData\\[email protected]" ); // LoadConfig( "HoundData\\[email protected]" ); break; case enAreaSeq02: break; case enAreaSeq03: break; case enAreaSeq04: break; case enAreaSeq05: break; } InitEnemies(); }
void TestCombat() { int humanLoc = 0; int enemyLoc = 2; StringOO name = "Barry"; int strength = 10; int health = 100; int luck = 10; int intellegence = 10; Human * humanPtr = new Human(humanLoc, name, strength, health, luck, intellegence); const int enemyNum = 5; Enemy * Enemies[enemyNum] = {}; InitEnemies(Enemies, enemyNum); //Enemy * enemyPtr = new Enemy(enemyLoc, name, strength, health, luck); for (int i = 0; i < enemyNum; i++) { Combat(*humanPtr, *Enemies[i]); } }
void TestAddEnemyToChallenge() { // challenges variables const int challengeNum = 15; Challenge *Challenges[challengeNum] = {}; // enemy variables const int enemyNum = 5; Enemy * Enemies[enemyNum] = {}; // initialise Enemies InitEnemies(Enemies, enemyNum); // initialise Challenges InitChallenges(Challenges); AddEnemyToChallenge(Enemies, Challenges, enemyNum, challengeNum); for (int i = 10; i < 15; i++) { std::cout << Challenges[i]->GetEnemy().GetName() << std::endl; } }
int main(void){ //allegro variables ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_BITMAP *bg = NULL; ALLEGRO_TIMER *timer; //program init if(!al_init()) //initialize Allegro return -1; display = al_create_display(WIDTH, HEIGHT); //create our display object if(!display) //test display object return -1; //============================================== //ADDON INSTALL //============================================== al_install_keyboard(); al_init_image_addon(); al_init_font_addon(); al_init_ttf_addon(); al_init_primitives_addon(); // FONT DEL PROGRAMA. ALLEGRO_FONT *font = al_load_ttf_font("Sarpanch-SemiBold.ttf",30,0 ); // VARIABLES DEL JUEGO ======================== bg = al_load_bitmap("img/sp1.jpg"); SpaceShip nave_jugador; Enemy enemies1[10]; Enemy enemies2[10]; Enemy enemies3[10]; Enemy enemies4[10]; Enemy jefe1[10]; Bullet bullets[5]; char vidas_char[2]; // INICIALIZAR OBJETOS==================== InitShip(nave_jugador); InitBullet(bullets, NUM_BULLETS); InitEnemies(enemies1,ENM1,10,0,220,WIDTH/2); InitEnemies(enemies2,ENM2,8,50,180,WIDTH/2+100); InitEnemies(enemies3,ENM3,6,100,140,WIDTH); InitEnemies(enemies4,ENM4,4,150,100,(WIDTH/2)+100); InitEnemies(jefe1,JEFE,2,200,60); //DrawEnemies(enemies,NUM_ENEMIES); //============================================== //TIMER INIT AND STARTUP //============================================== event_queue = al_create_event_queue(); timer = al_create_timer(1.0 / 60); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_start_timer(timer); //AnimacionEntrada(enemies,NUM_ENEMIES); printf("ya"); int animacion=1; int movimientos=0; while(!done){ ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); // INFORMACION DEL JUEGO Y BG // DrawWindowStatus(); al_draw_bitmap(bg, 0, 0, 0); al_draw_bitmap(nave_jugador.image, 5,440,0); al_draw_text(font, al_map_rgb(255,255,255), 40,430, 0, "X"); sprintf(vidas_char,"%d",vidas); al_draw_text(font, al_map_rgb(255,255,255), 60,430, 0, vidas_char); al_draw_text(font, al_map_rgb(255,255,255), WIDTH/2 - 30, 0,ALLEGRO_ALIGN_CENTRE, "Score"); char vartext[10]; sprintf(vartext,"%d",score); al_draw_text(font, al_map_rgb(255,255,255), WIDTH/2 + 40, 0, 0, vartext); //============================================== //INPUT //============================================== if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN){ switch(ev.keyboard.keycode){ case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = true; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = true; break; case ALLEGRO_KEY_SPACE: keys[SPACE] = true; FireBullet(bullets, NUM_BULLETS, nave_jugador); break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_ESCAPE: done = true; break; case ALLEGRO_KEY_LEFT: keys[LEFT] = false; break; case ALLEGRO_KEY_RIGHT: keys[RIGHT] = false; break; case ALLEGRO_KEY_SPACE: keys[SPACE] = false; break; } } //============================================== //GAME UPDATE //============================================== else if(ev.type == ALLEGRO_EVENT_TIMER){ render = true; if(keys[LEFT]) MoveShipLeft(nave_jugador); else if(keys[RIGHT]) MoveShipRight(nave_jugador); UpdateBullet(bullets, NUM_BULLETS); CollideBullet(bullets,NUM_BULLETS,enemies1,NUM_ENEMIES); CollideBullet(bullets,NUM_BULLETS,enemies2,8); CollideBullet(bullets,NUM_BULLETS,enemies3,6); CollideBullet(bullets,NUM_BULLETS,enemies4,4); CollideBullet(bullets,NUM_BULLETS,jefe1,2); } //============================================== //RENDER //============================================== if(render && al_is_event_queue_empty(event_queue)) { if (animacion==1){ printf("si primero"); movEnemies(enemies1,10,1); movEnemies(enemies2, 8,1); movEnemies(enemies3,6,1); movEnemies(enemies4,4,1); movEnemies(jefe1,2,1); animacion=0; movimientos=1; } render = false; // Dibujar nave al_draw_bitmap(nave_jugador.image, nave_jugador.x - nave_jugador.w / 2, nave_jugador.y - nave_jugador.h / 2, 0); // Dibujar Balas DrawBullet(bullets, NUM_BULLETS); // Dibuja los enemigos. DrawEnemies(enemies1,10); DrawEnemies(enemies2,8); DrawEnemies(enemies3,6); DrawEnemies(enemies4,4); DrawEnemies(jefe1,2); al_flip_display(); al_clear_to_color(al_map_rgb(0,0,0)); if (movimientos){ movimientos=0; movEnemies(enemies1,10,2); movEnemies(enemies2,8,3); } } } for (int i =0;i<10;i++) al_destroy_bitmap(enemies1[i].image); al_destroy_event_queue(event_queue); al_destroy_timer(timer); al_destroy_display(display); //destroy our display object return 0; }
/******************************************************************************************************* * GANE ENGINE - handles the looping of the game *******************************************************************************************************/ void GameEngine() { // user input variables const int userInputLimit = 11; char userInput[userInputLimit] = {}; bool humanFinished = false; bool moveHuman = false; StringOO humanMove = "move south"; int loopCount = 0; // location variables const int locationNum = 11; Location *Locations[locationNum] = {}; int prevLocation = 0; int newLocation = 0; int finishLocation = locationNum - 1; // human player variables int humanLoc = 0; StringOO name = "Bruce"; int strength = 10; int health = 100; int luck = 10; int intellegence = 10; // enemy variables const int enemyNum = 5; Enemy * Enemies[enemyNum] = {}; // challenges variables const int challengeNum = 16; Challenge *Challenges[challengeNum] = {}; // initialise Locations InitLocations(Locations); // initialise human Human Human(humanLoc, name, strength, health, luck, intellegence); // initialise Enemies InitEnemies(Enemies, enemyNum); // initialise Challenges InitChallenges(Challenges); //AllocateChallenges(Locations, locationNum); AllocateChallengesManually(Locations, locationNum); AddEnemyToChallenge(Challenges, enemyNum, challengeNum); // initial splash screen SetConsole(); StartText(Human); // Game loop while (!humanFinished) { // print out details of room std::cout << Locations[Human.GetLocation()]->GetDescription() << std::endl; while (!moveHuman) { // get user to enter move std::cout << "+ "; std::cin.getline(userInput, userInputLimit); std::cout << std::endl; humanMove = userInput; if (loopCount == 5) { std::cout << "\n ENOUGH ALREADY...YOUR MOVING SOUTH!! \n\n"; //bored of guesses humanMove = "move south"; loopCount = 0; } // determine the new location newLocation = PlayerMove(Human, humanMove, Locations[Human.GetLocation()]->GetAjacentLoc()); // validate users move and if validate change their location if (ValidateMove(newLocation, prevLocation)) { // set challenge user has to perform before progrogressing to the next room Human.SetChallenge(Locations[Human.GetLocation()]->GetPathChallenge(Human.GetHeading())); // challenge User Challenge *ChallengePtr = Challenges[Human.GetChallenge()]; ApplyChallenge(ChallengePtr, Human, Enemies); // move user to new location prevLocation = Human.GetLocation(); Human.SetPrevHeading(Human.GetHeading()); Human.SetLocation(newLocation); moveHuman = true; loopCount = 0; std::cout << "\n***----------------------------* pop! *-------------------------------------**\n\n"; } else { // invalid move try again moveHuman = false; loopCount++; } } // reset move moveHuman = false; //check if user is in the finish location if (Human.GetLocation() == finishLocation) { humanFinished = true; std::cout << Locations[Human.GetLocation()]->GetDescription() << std::endl; FinishText(Human); } } //DestroyEnemies(Enemies, enemyNum); for (int i = 0; i < enemyNum; i++) { delete Enemies[i]; } //DestroyChallenges(Challenges, challengeNum); for (int i = 0; i < challengeNum; i++) { delete Challenges[i]; } //DestroyLocations(Locations, locationNum); for (int i = 0; i < locationNum; i++) { delete Locations[i]; } }
void TestInitaliseDestroy() { // user input variables const int userInputLimit = 11; char userInput[userInputLimit] = {}; bool humanFinished = false; bool moveHuman = false; StringOO humanMove = "move south"; // location variables const int locationNum = 11; Location *Locations[locationNum] = {}; int prevLocation = 0; int newLocation = 0; int finishLocation = locationNum - 1; // human player variables int humanLoc = 0; StringOO name = "Barry"; int strength = 10; int health = 100; int luck = 10; int intellegence = 10; // enemy variables const int enemyNum = 5; Enemy * Enemies[enemyNum] = {}; // challenges variables const int challengeNum = 16; Challenge *Challenges[challengeNum] = {}; // initialise Locations InitLocations(Locations); // initialise human Human Human(humanLoc, name, strength, health, luck, intellegence); // initialise Enemies InitEnemies(Enemies, enemyNum); // initialise Challenges InitChallenges(Challenges); AllocateChallenges(Locations, locationNum); AddEnemyToChallenge(Enemies, Challenges, enemyNum, challengeNum); TestCombat() //DestroyEnemies(Enemies, enemyNum); for (int i = 0; i < enemyNum; i++) { delete Enemies[i]; } //DestroyChallenges(Challenges, challengeNum); for (int i = 0; i < challengeNum; i++) { delete Challenges[i]; } //DestroyLocations(Locations, locationNum); for (int i = 0; i < locationNum; i++) { delete Locations[i]; } }