int main(void) { int r = 5; //player positions int c = 4; int r2 = 80; //first ball positions int c2 = 120; int human_speed = 2; //guess what this is? int width = 2; //dont bother, this is the frame width int human_size = 10; //duh int size = 10; //size of computer int dr = 3; //speed of player int dc = 3; //should = dr int agression; //not being used right now int inRange = 0; //a random count variable int human_health = 100; //human starting health int comp_health = 100; //computer starting health int newgame = 1; //another count var int loopCount = 0; int numAttacks = 0; //number of times human attacks int justAttacked; //count var for computer attacks int result; //count var int death_radius = 4; //this is how many pixels the radius around the computer is that you have to be in to attack/be attacked int next_var1 = 0; int retreat = 0; int retreat_length = 100; //how long it is after going in to retreat mode that you win int next_var2 = 0; int junkVar = 0; //prebuild the binary search tree //make the data in each node be a pointer to a function, then the output of that function //decides which node is next NaryNode *root = NULL; root = createNaryNode(createIntData(0), 0); //make the root node (check health) appendChild(root, createNaryNode(createIntData(1), 0)); //make the first child (if health is ok) appendChild(root, createNaryNode(createIntData(2), 0)); //make the second child (if health is bad) appendChild(root->child[0], createNaryNode(createIntData(3), 0)); //treat the first child as the root and add another child appendChild(root->child[1], createNaryNode(createIntData(4), 0)); //treat the first child as the root and add another child appendChild(root->child[1]->child[4], createNaryNode(createIntData(5), 0)); //add another child on right parent int *tree1; int *tree2; int *tree3; tree1 = (int*)(root->child[1]); (int*)(root->child[1]) = 4; (int*)(root->child[0]) = 2; (int*)(root->child[1]->child[4]) = 1; //tree1 = root->child[1]; /* [root] / \ [child1] ----------child 2] / \ \ \ [child3] [child4] [child5] [child6] / / \ [child7] [child8] [child9] | | [child9] [child10] */ Junk first; first.margin = 40; //the margin for death for the computer first.comp_health_rate = 1; //how fast the you kill the computer first.human_health_rate = 2; //how fast the computer kills you while(keepGoing()) { waitForVBlank(ON); switch (gameState) { case START: //start mode 4 initializeGBA(MODE_4); FlipPage(ON); paintBackground(PressEnterBitmap); FlipPage(OFF); //in to mode 3 GBASetup(); initializeGBA(MODE_3); drawBackground(6); while(!keyHit(BUTTON_START)){ while(keyHit(BUTTON_START)){ break;} } //reset all the count vars and such newgame = 1; numAttacks = 0; loopCount = 0; justAttacked = 0; human_health = 100; //human starting health comp_health = 100; //computer starting health next_var1 = 0; next_var2 = 0; r = 5; //player positions c = 4; r2 = 80; //first ball positions c2 = 120; gameState = PLAY; retreat = 0; break; case PLAY: //start mode 3 FlipPage(OFF); GBASetup(); waitForVBlank(ON); loopCount++; drawRectDMA(0, 0, 160, 240, COLOR(0,0,0)); //the black background //nary tree usage tree3 = (int*)(root->child[1]); if(tree3){ junkVar++; } if(comp_health < first.margin){ gameState = WIN; } //frame drawRectDMA(1, 1, 240, 1, COLOR(0,0,31)); //left bar drawRectDMA(159, 1, 1, 240, COLOR(0,0,31));//bottom bar drawRectDMA(1, 1, 240, 1, COLOR(0,0,31));//bottom bar drawRectDMA(159, 1, 1, 240, COLOR(0,0,31));//bottom bar //draw health bars if(human_health == 100){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human starting health drawRectDMA(5, 6, 1, 1, COLOR(0,0,31)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,31)); } if(comp_health == 100){ drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer starting health drawRectDMA(5, 232, 1, 1, COLOR(31,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(31,0,0)); //newgame = 0; } if((human_health < 100) && (human_health > 66)){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human health 2/3 drawRectDMA(5, 6, 1, 1, COLOR(0,0,31)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,0)); } if((human_health < 66) && (human_health >33)){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,31)); //human health 1/3 drawRectDMA(5, 6, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,0)); } if((human_health < 33) && (human_health >0)){ drawRectDMA(5, 4, 1, 1, COLOR(0,0,0)); //human health 0/3 drawRectDMA(5, 6, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 8, 1, 1, COLOR(0,0,0)); } if((comp_health < 100) && (comp_health > 66)){ drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer health 2/3 drawRectDMA(5, 232, 1, 1, COLOR(31,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(0,0,0)); } if((comp_health < 66) && (comp_health > 33)){ drawRectDMA(5, 230, 1, 1, COLOR(31,0,0)); //computer health 1/3 drawRectDMA(5, 232, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(0,0,0)); } if((comp_health < 33) && (comp_health > 0)){ drawRectDMA(5, 230, 1, 1, COLOR(0,0,0)); //computer health 0/3 drawRectDMA(5, 232, 1, 1, COLOR(0,0,0)); drawRectDMA(5, 234, 1, 1, COLOR(0,0,0)); } waitForVBlank(ON); //player control //controls the boundries and the speed drawRectDMA( r, c, width, width, COLOR(0,0,0)); if(keyHit(BUTTON_UP)) { r = r - human_speed; if(r <= 1) r = 2; } if(keyHit(BUTTON_DOWN)) { r = r + human_speed; if(r >= 159+human_size) r = 159; } if(keyHit(BUTTON_LEFT)) { c = c - human_speed; if(c <= 1) c = 2; } if(keyHit(BUTTON_RIGHT)) { c = c + human_speed; if(c >= 239+human_size) c = 239; } //start ball code (makes ball move) drawRectDMA( r2, c2, size, size, COLOR(0,0,0) ); drawRectDMA( r2, c2, size, size, COLOR(0,0,31) ); //collision detection //walls (make ball bounce) //computer bouncing if((r2+size) > 156) dr = -dr; //top if((c2+size) > 236) dc = -dc; //bottom and right if((c2+size) < 15) dc = -dc; //left if(((r2) <= 3) || ((r2) >= 158)) dr = -dr; //top and bottom //draw player square drawRectDMA( r, c, human_size, human_size, COLOR(0,0,0)); drawRectDMA( r, c, human_size, human_size, COLOR(0,0,31) ); //the actual square //draw bouncing ball drawRectDMA( r2, c2, size, size, COLOR(31,0,0)); //right wall drawRectDMA( 1, 238, 72 , width - 1, COLOR(0,0,31) ); drawRectDMA( 87, 238, 73, width - 1, COLOR(0,0,31) ); //keep player in boundries if(r < 2) { r = 2; } if(r+size > (159)) { r = (148); } if((c+size > 239)) { c = 228; } if((c < 2)) { c = 2; } //keep computer in boundries //the computer boundry is smaller so he doesn't get stuck in corners if(r2 < 10) { r2 = 10; } if(r2+size >= (149)) { r2 = (138); } if((c2 < 10)) { c2 = 10; } if((c2+size > 229)) { c2 = 218; } //BEGIN AI //if the health is low if((retreatCheck(comp_health,(first.margin)))){ //retreat (int*)(root->child[1]) = 1; if(r < r2){ r2 = r2 + 1; } if(r > r2){ r2 = r2 - 1; } if(c < c2){ c2 = c2 + 1; } if(c > c2){ c2 = c2 - 1; } if(keyHit(BUTTON_A)){ retreat = retreat + 1; } } //nary tree usage tree2 = (int*)(root->child[1]); if(tree2){ junkVar++; } if(attackCheck(comp_health)){ //if health is ok //attack (int*)(root->child[0]) = 1; if(r < r2){ r2 = r2 - 1; } if(r > r2){ r2 = r2 + 1; } if(c < c2){ c2 = c2 - 1; } if(c > c2){ c2 = c2 + 1; } //see how aggressive the human is being agression = numAttacks/inRange; //see if the human is within striking distance if(inRadius(c2, death_radius, c, human_size, r2, r, size)){ //this function took forever to write inRange++; result = randGen(); if(result){ human_health = human_health - (first.human_health_rate); justAttacked++; } //If I ever get around to implementing this, this will allow the computer to retreat //when the human gets too aggressive /* if(agression > .15){ //retreat if(r < r2){ r2 = r2 + 1; } if(r > r2){ r2 = r2 - 1; } if(c < c2){ c2 = c2 + 1; } if(c > c2){ c2 = c2 = 1; } } */ //set up the health //computer (computer loses health under these conditions if(keyHit(BUTTON_A)){ comp_health = (comp_health - (first.comp_health_rate)); numAttacks++; } } } if(inRadius(c2, death_radius, c, human_size, r2, r, size)){ if(retreat >= retreat_length){ gameState = WIN; break;} if(human_health < 33){ gameState = DIE; next_var2 = 1; break; } } break; case WIN: //if they make it past level 5, display a win screen and reset some variables drawBackground(7); if(junkVar){ newgame = 1; } retreat = 0; if(keyHit(BUTTON_START)) { gameState = CREDITS; //next stop is the credits } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } next_var1 = 1;} break; case CREDITS: //display the Pony Shrapnel logo if(next_var1 == 1){ drawBackground(8); if(keyHit(BUTTON_START)) { gameState = START; //next stop is the start screen } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } } } case DIE: //if they die, then display a death screen, reset some variables, and go back to the start screen if(next_var2){ drawBackground(1); if(junkVar){ newgame = 0; } if(keyHit(BUTTON_START)) { gameState = CREDITS2; //next stop is the credits2 } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } } human_health = 100;} break; case CREDITS2: //display the Pony Shrapnel logo while(next_var2){ drawBackground(8); if(keyHit(BUTTON_START)) { gameState = START; //next stop is the start screen next_var2 = 0; } while(keyHit(BUTTON_START)) { while(!keyHit(BUTTON_START)) { break; } } break;} //end switch statements } } return 0; }
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 == ) // }