void Darkroom::init1(void){ limitTime = 60 * 60; DeleteGraph(background); background = LoadGraph("res/bg/stage1_bg_y.png"); DeleteGraph(forground); forground = LoadGraph("res/bg/stage1_fg.png"); DeleteSoundMem(bgm); bgm = LoadSoundMem("res/bgm/Stage1.mp3"); for(int i = 0; i < SOUND_NUM; i++) { sound[i].x = rand() % WINDOW_WIDTH - 80 + 40; sound[i].y = rand() % WINDOW_HEIGHT - 80 + 20; sound[i].v_x = 1 + (double)(rand() % 100)/100; sound[i].v_y = 1 + (double)(rand() % 100)/100; sound[i].caught = FALSE; if( i < 24){ sound[i].visible = TRUE; } else { sound[i].visible = FALSE; continue; } sound[i].count = rand() % 4 * 15; if(i < 24 / 3){ setSound(0, &sound[i]); } else if(i < 24 / 3 * 2){ setSound(1, &sound[i]); } else { setSound(2, &sound[i]); } } for(int i = 0; i < 8; i++) { enemy[i].x = rand() % WINDOW_WIDTH - 80 + 40; enemy[i].y = rand() % WINDOW_HEIGHT - 80 + 20; if(i < 2){ enemy[i].visible = TRUE; } else { enemy[i].visible = FALSE; continue; } enemy[i].count = rand() % 4 * 15; delete(enemy[i].pattern); if(i % 4 == 0){ //MoveSinWave* p; MoveSinWave* p = new MoveSinWave(enemy[i].y, rand() % 5 * 0.01 , rand() % 3 * 20 + 10); //p->angle = rand() % 360; //p->radius = rand() % 150 + 20; enemy[i].pattern = p; } else if(i % 4 == 1){ MoveReflect* p; p = new MoveReflect(); enemy[i].pattern = p; } else if(i % 4 == 2){ MoveEscape* p; p = new MoveEscape(); p->player_x = &(player.x); p->player_y = &(player.y); enemy[i].pattern = p; } else { MoveSinWave* p = new MoveSinWave(enemy[i].y, rand() % 5 * 0.01 , rand() % 3 * 20 + 10); p->dx = rand() % 5; enemy[i].pattern = p; } } PlaySoundMem(bgm, DX_PLAYTYPE_LOOP); }
void Test :: run(){ //Test frand // assert( frand()==0.1f ); // assert( frand()==0.7f ); // assert( frand()==0.7f ); // assert( frand()==0.1f ); // cout << "gismoManager::randmom() is OK."<<endl; cout << "CLASS Sound is ok.(check the receive yourself.)" << endl; //TestEventHandler EventHandler eventHandler; EvTest evTest; eventHandler.eventAdd("/t01" , &evTest); int args[] = {0,1,2}; assert ( eventHandler.bang("/t01", args) == 138 ); assert ( eventHandler.bang("/t01") == 137 ); cout << "GismoBundledClass::eventHandler is OK." << endl; //Test EventHandler with Gismo gismo.eventAdd("/t01" , &evTest); assert ( gismo.bang("/t01" , args) == 138 ); //Sound Trigger int snd_id = 0; setSound(0); setSound(2); setSound(4); cout << "GismoManager::eventHandler with Gismo is OK." << endl; //Define an agent ag_t ag; //Test GismoManager.getAgents() ag_t *agents = gismo.getAgents(); agents[0].posi.x = 0.13f; agents[0].posi.y = 0.2f; assert(agents[0].posi.x == 0.13f); assert(agents[0].posi.y == 0.2f); cout << "GismoManager:getAgent() is OK." << endl; //Test GismoLibrary distance() posi_t tmp1, tmp2; tmp1.x = 0.0f; tmp1.y = 0.0f; tmp2.x = 3.0f; tmp2.y = 4.0f; assert(distance(tmp1, tmp2) == 5.0f); tmp1.x = 0.5f; tmp1.y = 0.5f; tmp2.x = -0.5f; tmp2.y = -0.5f; assert(distance(tmp1, tmp2)==(float)sqrt(2.0f)); tmp1.x = 3.0f; tmp1.y = 4.0f; tmp2.x = 0.0f; tmp2.y = 0.0f; assert(distance(tmp1, tmp2) == 5.0f); tmp1.x = 5.0f; tmp1.y = 12.0f; tmp2.x = 0.0f; tmp2.y = 0.0f; assert(distance(tmp1, tmp2) == 13.0f); cout << "GismoLibrary:distance() is OK." << endl; //Test Init AgentActive initAgentActive(&ag); assert(ag.size == AG_DEF_SIZE); assert(ag.active==true); cout << "GismoLibrary:initAgentActive() is OK." << endl; //TestAgentAdd initAgentActive(&ag); ag.view = 0.23f; ag.posi.x = 0.2f; ag.posi.y=0.2f; gismo.addAgent(ag); assert (gismo.add.buf[0].view == 0.23f); assert (gismo.add.count == 1); cout << "GismoManager:addAgent() is OK." << endl; //TestSync ag_t ag2; initAgentActive(&ag2); ag2.view = 0.34f; gismo.addAgent(ag2); gismo.addSync(); //Finally gismo requires sync to avoid direct agent addition when processing agents. assert(gismo.add.count==0 && gismo.agents.count==2); assert(agents[0].active && agents[1].active); assert(agents[0].view==0.23f && agents[1].view==0.34f); cout << "gismoLibrary:addSync() is OK." << endl; //Test gismo Library seekNearest(); agents[0].posi.x = 0.0f; agents[0].posi.y = 0.0f; agents[1].posi.x = 0.5f; agents[1].posi.y = 0.5f; ag_t ag3; initAgentActive(&ag3); ag3.posi.x = 0.5f; ag3.posi.y = 0.49f; gismo.addAgent(ag3); //add the new agent to addBuffer ag_t ag4; ag4.posi.x = 0.7f; ag4.posi.y = 0.49f; gismo.addAgent(ag3); //add the new agent to addBuffer gismo.addSync(); //refrect the add buffer to actual buffer int nearest_agent = seekNearest(0, &gismo.agents); //seek the nearest agent of agent[0] cout << nearest_agent << endl; assert(nearest_agent==2); cout << "gismoManager:seekNearest() is OK."<<endl; //Test isViewRange /* REST FOR VIEW/MOV RATE ag_t ag5; ag5.view = 0.5f; assert( isViewRange(&ag5,0.3f)==true ); assert( isViewRange(&ag5,0.51f)==false ); cout << "gismoLibrary::isViewRange() is OK" << endl; //Test isLarge assert( isLarge(0.5 , 0.4)==true ); assert( isLarge(0.5, 0.501)==false); cout << "gismoLibrary::isaLarge is OK" <<endl; //Test Move ag_t ag6; posi_t tmp; tmp.x=1.0; tmp.y=0.0; initAgent(&ag6); ag6.posi.x=0.5; ag6.posi.y=0.5; move(&ag6,&tmp); assert(ag6.posi.x >= 0.5f); assert(ag6.posi.y <= 0.5f); cout << "gismoLibrary::move() is OK." << endl; //Test Run ag_t tmpAg1, tmpAg2; tmpAg1.posi.x = 0.75f; tmpAg1.posi.y = 0.75f; tmpAg1.mov = 0.001f; tmpAg1.spd.x = 0.0f; tmpAg1.spd.y = 0.0f; tmpAg2.posi.x = 0.5f; tmpAg2.posi.y = 0.5f; running(&tmpAg1, &tmpAg2.posi); assert(tmpAg1.posi.x >= 0.75f); assert(tmpAg1.posi.y >= 0.75f); tmpAg1.posi.x = 0.25f; tmpAg1.posi.y = 0.75f; tmpAg1.spd.x = 0.0f; tmpAg1.spd.y = 0.0f; running(&tmpAg1, &tmpAg2.posi); assert(tmpAg1.posi.x <= 0.25f); assert(tmpAg1.posi.y >= 0.75f); tmpAg1.posi.x = 0.75f; tmpAg1.posi.y = 0.45f; tmpAg1.spd.x = 0.0f; tmpAg1.spd.y = 0.0f; running(&tmpAg1, &tmpAg2.posi); assert(tmpAg1.posi.x >= 0.75f); assert(tmpAg1.posi.y <= 0.45f); tmpAg1.posi.x = 0.25f; tmpAg1.posi.y = 0.25f; tmpAg1.spd.x = 0.0f; tmpAg1.spd.y = 0.0f; running(&tmpAg1, &tmpAg2.posi); //0115 assert(tmpAg1.posi.x < 0.25f); //assert(tmpAg1.posi.y < 0.25f); cout << "gismoLibrary::running() is OK." << endl; //TestConditionCheck condition_e cond1 = CALM; condition_e cond2 = RUN; assert ( conditionCheck(cond1, cond2) == false ); cond2 = CALM; assert ( conditionCheck(cond1, cond2) == true ); //Test interactWith() ag_t ag8 , ag9; initAgent(&ag8); initAgent(&ag9); ag8.size = 1.0f; ag8.posi.x = 0.0f; ag8.posi.y = 0.0f; ag9.posi.x = 1.0f; ag9.posi.y = 1.0f; ag8.view = 1.5; interactWith(&ag8 , &ag9); */ //TestReset agents[0].active=true; agents[1].active=true; agBuffReset(&gismo.agents); assert(agents[0].active==false); assert(agents[1].active==false); assert(gismo.agents.count == 0); //TestLogistic float fval=0.5; fval = logistic(fval); assert(fval==0.75f); fval = logistic(fval); cout << "GismoLibrary::logistic() is OK." << endl; //Test //agBuffReset(&gismo.agents); int val = 1; gismo.bang("/gismo/reset" , &val); ag_t ag1; initAgent(&ag1); ag1.view = 256.0f; gismo.agents.buf[0] = ag1; ag1.view = 356.0f; gismo.agents.buf[1] = ag1; ag_t *pAg1 = gismo.getAgent(0); assert(pAg1->view == 256.0f); ag_t *pAg2 = gismo.getAgent(1); assert(pAg2->view == 356.0f); //TestSpeedLimit assert ( limitter(1.1f, 1.0f) == 1.0f ); assert ( limitter(-1.1f, 1.0f) == -1.0f ); assert ( limitter(0.49f, 0.5f) == 0.49f ); assert ( limitter(-0.49f, 0.5f) == -0.49f ); assert ( limitter(0.0051f, 0.005f) == 0.005f ); assert ( limitter(-0.00501f, 0.005f) == -0.005f ); cout << "speedLimitter is OK." << endl; //Test positionLoop() posi_t pos; pos.x = 1.1; pos.y = -0.01; positionLoop(&pos, 1.0f, 1.0f); assert (pos.x == 0.0f); assert (pos.y == 1.0f); pos.x = -0.1; pos.y = 1.4; positionLoop(&pos, 1.0f, 1.0f); assert (pos.x == 1.0f); assert (pos.y == 0.0f); pos.x = 0.0f; pos.y = 1.0f; positionLoop(&pos, 1.0f, 1.0f); assert (pos.x == 1.0f); assert (pos.y == 1.0f); //Check result check pos.x = 0.5f; pos.y = 0.5f; bool result = positionLoop(&pos , 1.0f, 1.0f); assert (result==false); pos.x = 1.0f; pos.y = 1.0f; result = positionLoop(&pos , 1.0f, 1.0f); assert (result==false); pos.x = 1.05f; pos.y = 1.05f; result = positionLoop(&pos , 1.0f, 1.0f); assert (result==true); pos.x = 1.05f; pos.y = 1.00f; result = positionLoop(&pos , 1.0f, 1.0f); assert (result==true); cout << "GismoLibrary::positionLoop() is OK" << endl; //Test attackCheck float fval2 = 0.0f; float size2 = 1.0f; attackCheck(fval2, &size2); bool size_test2 = true; if ( size2 != (1.0f-AG_DMG) ) size_test2 = false; assert(size_test2); assert(size2 == 1.0f-AG_DMG); size2 = 1.0f; fval2 = ATK_DIST+0.1; attackCheck(fval2, &size2); assert(size2 == 1.0f); cout << "GismoLibrary::attackCheck() is OK" << endl; size2 = 1.0f; fval2 = ATK_DIST; attackCheck(fval2, &size2); assert(size2 == 1.0f-AG_DMG); //Test deadCheck float dummy_size = 0.0001f; bool active = true; deadCheck( &dummy_size , &active ); assert(active == false); assert(dummy_size == 0.0f); dummy_size = 1.0f; active = true; deadCheck( &dummy_size , &active ); assert(active == true); cout << "GismoLibrary::deadCheck is OK" << endl; //Test Shape2Agent ag_shape_t shape; shape.nodes[0].x = 0.5f; shape.nodes[0].y = 0.5f; shape.nodes[1].x = 1.0f; shape.nodes[1].y = 1.0f; shape.node_count = 2; shape.edges[0].node_id_a = 0; shape.edges[0].node_id_b = 1; shape.edge_count = 1; ag_t tmpAg = shape2Agent(shape); assert(tmpAg.view == 0.005f); //assert(tmpAg.size == 0.011f); assert(tmpAg.mov == 0.35f); ag_shape_t shape2; shape2.node_count = 50000; ag_t tmpAg3 = shape2Agent(shape2); cout << tmpAg3.mov << endl; assert(tmpAg3.mov == MOV_MINIMUM); cout << "Shape2Agent.hpp::shape2Agent() is OK" << endl; //Test moveOnLine() posi_t posi = moveOnLine(0.5f, 0.0f, 0.0f, 1.0f, 1.0f); assert(posi.x == 0.5f && posi.y == 0.5f); posi = moveOnLine(1.0f, 0.0f, 0.0f, 1.0f, 1.0f); assert(posi.x == 1.0f && posi.y == 1.0f); posi = moveOnLine(0.5f, -1.0f, -1.0f, -2.0f, -2.0f); assert(posi.x == -1.5f && posi.y == -1.5f); posi = moveOnLine(0.0f, -1.0f, -1.0f, -2.0f, -2.0f); assert(posi.x == -1.0f && posi.y == -1.0f); posi = moveOnLine(0.5f, 0.0f, 0.0f, -1.0f, -2.0f); assert(posi.x == -0.5f && posi.y == -1.0f); //TestGetArraySize int iArray[137]; posi_t posiArray[138]; assert(getArraySize(iArray)==137); assert(getArraySize(posiArray)==138); cout << "TestGetArraySize.h::getArraySize() is ok." << endl; //Test lambda bang int myArg[2]; myArg[0] = 12; myArg[1] = 13; gismo.bang("/lambdaTest", myArg); //TestSoundTrigger param_u params[4]; params[0].ival = 0; //Genre params[1].ival = 1; //Song params[2].ival = 2; //Slice params[3].fval = 1.0f;//effect gismo.bang("/soundTrg" , ¶ms); cout << "sound trigger is ok. If you could listen the RM sound" << endl; //Test shape2Sound ag_shape_t shapeForSound; shapeForSound.node_count = 12; shapeForSound.color = 0.50f; sound_t snd = shape2sound(shapeForSound,5); assert(snd.genre == 2); assert(snd.song == 5); shapeForSound.node_count = 6; shapeForSound.color = 1.0f; snd = shape2sound(shapeForSound,1137); assert(snd.genre == 0); assert(snd.song == 137); cout << "SoundTrigger::shape2Sound is OK" << endl; ag_t test; test.condition = CALM; ag2sound(&test, &snd); assert(snd.slice == 0); assert(snd.effect_val == EF_VAL_CALM); test.condition = RUN; ag2sound(&test, &snd); assert(snd.slice == 1); assert(snd.effect_val == EF_VAL_RUN); test.condition = CHASE; ag2sound(&test, &snd); assert(snd.slice == 2); assert(snd.effect_val == EF_VAL_CHASE); test.condition = DMG; ag2sound(&test, &snd); assert(snd.slice == 3); assert(snd.effect_val == EF_VAL_DMG); test.condition = DEATH; ag2sound(&test, &snd); assert(snd.slice == 4); assert(snd.effect_val == EF_VAL_DEATH); cout << "SoundTrigger::ag2Sound is OK" << endl; //Test makePositionToAdd in Shape2Agent // posi_t myPosi = makePositionToAdd(); // assert(myPosi.x == ) // }
void Darkroom::init4(void){ limitTime = 60 * 120; DeleteGraph(background); switch(result.stage_color()){ case 0: background = LoadGraph("res/bg/stage4_R_bg_y.png"); break; case 1: background = LoadGraph("res/bg/stage4_G_bg_y.png"); break; case 2: background = LoadGraph("res/bg/stage4_B_bg_y.png"); break; } DeleteGraph(forground); switch(result.stage_color()){ case 0: forground = LoadGraph("res/bg/stage4_R_fg.png"); break; case 1: forground = LoadGraph("res/bg/stage4_G_fg.png"); break; case 2: forground = LoadGraph("res/bg/stage4_B_fg.png"); break; } DeleteSoundMem(bgm); bgm = LoadSoundMem("res/bgm/Stage3.mp3"); for(int i = 0; i < SOUND_NUM; i++) { sound[i].x = rand() % WINDOW_WIDTH - 80 + 40; sound[i].y = rand() % WINDOW_HEIGHT - 80 + 20; sound[i].v_x = 1 + (double)(rand() % 100)/100; sound[i].v_y = 1 + (double)(rand() % 100)/100; sound[i].caught = FALSE; if( i < 64){ sound[i].visible = TRUE; } else { sound[i].visible = FALSE; continue; } sound[i].count = rand() % 4 * 15; setSound(i % 3, &sound[i]); } for(int i = 0; i < ENEMY_NUM; i++) { enemy[i].x = rand() % WINDOW_WIDTH - 80 + 40; enemy[i].y = rand() % WINDOW_HEIGHT - 80 + 20; if(i < 6){ enemy[i].visible = TRUE; } else { enemy[i].visible = FALSE; continue; } enemy[i].count = rand() % 4 * 15; delete(enemy[i].pattern); if(i % 3 == 0){ MoveCircular* p; p = new MoveCircular(); p->angle = rand() % 360; p->radius = rand() % 150 + 20; enemy[i].pattern = p; } else if(i % 3 == 1){ MoveReflect* p; p = new MoveReflect(); enemy[i].pattern = p; } else { MoveEscape* p; p = new MoveEscape(); p->player_x = &(player.x); p->player_y = &(player.y); enemy[i].pattern = p; } } PlaySoundMem(bgm, DX_PLAYTYPE_LOOP); }
Cow::Cow() { setName("Cow"); setSound("Moo"); m_milkProduced = 0; }
Chicken::Chicken() { setName("Chicken"); setSound("Cluck"); }
//------------------------------------------------------------------------- void Sound::setSound3D(const SoundDefPtr& _soundDef) { setSound(true, _soundDef); }
//------------------------------------------------------------------------- void Sound::setSound2D(const SoundDefPtr& _soundDef) { setSound(false, _soundDef); }
CyberChicken::CyberChicken() { setName("Cyber Chicken"); setSound("Resistance is futile"); }