int main() { Bat b; b.breathe(); b.flap(); b.eat(); Animal &a = b; }
Bat MathUtils::rotateBat(Bat &bat, qint32 angle) { Bat newBat(MathUtils::rotatePoint(bat.getPoints()[0],angle), MathUtils::rotatePoint(bat.getPoints()[1], angle), bat.getId()); return newBat; }
TEST(BatTest, Init) { Bat bat; bat.Init(0, 100, 1, 200, 10); ASSERT_EQ(10, bat._length); ASSERT_EQ(100, bat._y); }
void Game::setBat(const Bat &b) { if (bat) { delete bat; } Bat *bat = new Bat(b.getForce()); bat->hit(*spheres[0]); batCount++; }
Bat* Bat::create(GameLayer * game, int type, CCPoint position) { Bat * sprite = new Bat(game, type, position); if (sprite) { sprite->initBat(); sprite->autorelease(); return sprite; } CC_SAFE_DELETE(sprite); return NULL; }
int Circle::check_collision_with_bat( Bat& bat, PotentialMove **pm, double ftr) { int current_ticks; int n; float future_x_at_bat_y; int vn; int result; double dx; /* Need to get this from the Bat Class - how far the bat moves horizontally. */ double cmx, cmy; double circle_to_bat_angle = principal_value_2(atan2( bat.cy - cc_y, bat.cx - cc_x )); PotentialMove *m; vector <PotentialMove *> moves(0); int move_number = 0; switch( bat.direction ) { case BAT_NOT_MOVING: dx = 0.0f; break; case BAT_MOVING_LEFT: //logfile << "setting \n"; dx = - bat.movement_inc * ftr; break; case BAT_MOVING_RIGHT: dx = bat.movement_inc * ftr; break; } /* check for collision against edges of bat */ for(vn = 0; vn < 4; ++vn) { if( circle_and_line_collision( PONGPING_TRANSLATION, bat.bat_vertices[vn], bat.bat_vertices[vn + 1], bat.get_bat_midpoint_x(), bat.get_bat_midpoint_y(), 0, dx, 0.0, this, *pm, 0, ftr) ) { /* Do I need to distinguish between side collisions and vertex collisions ? */ (*pm)->set_hit_type_and_side(PONGPING_BAT_COLLISION, vn); return 1; } } /* check for collision against vertices of bat */ m = new PotentialMove(); moves.push_back(m); for(vn = 0; vn < 4; ++vn) { logfile << "checking vertex " << vn << "\n\n"; /* int (const unsigned char vertex_move, const double cx, const double cy, const int use_centre_of_mass, const double cmx, const double cmy, const Point v, const double angle, const int dx, const int dy, Circle *c, PotentialMove& move); */ if(cvc( PONGPING_TRANSLATION, 0.0, 0.0, PONGPING_USE_CENTRE_OF_MASS, bat.get_bat_midpoint_x(), bat.get_bat_midpoint_y(), bat.get_mass(), bat.bat_vertices[vn], 0.0, dx, 0.0, this, moves[move_number], ftr)) { moves[move_number]->set_hit_type_and_side(PONGPING_BAT_COLLISION, vn); ++move_number; //logfile << "move_number = " << move_number << "\n"; //pm.hit_type = PONGPING_BAT_COLLISION; m = new PotentialMove(); moves.push_back(m); //return 1; } } vector< PotentialMove* >::iterator it = moves.end(); if(move_number > 0) { --it; sort(moves.begin(), it, compare_distance); (*pm) = moves[0]; //logfile << "got a vertex hit.\n"; //eek(); return 1; } return 0; }
int main( int argc, char* args[] ) { bool quit = false; bool show_menu = true; int score = 0; int cursor = 0; //setup----------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------- if( init() == false ) //Starts up SDL and quits if there is a problem. return 1; //----------------------------------------------------------------------------- Player_1.Display = Display; //Sets Player_1 to be able to blit onscreen Player_2.Display = Display; //Sets Player_2 to be able to blit onscreen Ball.Display = Display; //Sets Ball to be able to blit onscreen Menu.Display = Display; //Sets Menu to be able to blit onscreen //------------------------------------------------------------------------------ //Loads any needed files and quits if there is a problem. //---------------------------------------------------------------------------------------------- if( ( Player_1.load_files() == false ) || ( Player_2.load_files() == false ) || ( Ball.load_files() == false ) || ( Menu.load_files() == false ) ) return 1; //---------------------------------------------------------------------------------------------- //Splash Screen then menu //---------------------------------------------------------------------------------------------- Menu.logo(); Menu.fade( "white" ); //The main loop--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------- while( quit == false ) { if( ! ( Fps.is_paused() ) ) Fps.start(); //While there is an event to handle while( SDL_PollEvent( &event ) ) { //Handle inputs for Player 1 anf 2 //---------------------------------------------- Player_1.handle_event( event ); Player_2.handle_event( event ); //Handles resizing of the window Window.handle_event( event ); quit = Menu.handle_event( event ); //---------------------------------------------- //Handles resizing of the bat and ball //---------------------------------------------- if( event.type == SDL_VIDEOEXPOSE || event.type == SDL_VIDEORESIZE ) { Ball.resize(); Player_1.resize(); Player_2.resize(); } //---------------------------------------------- //If the user presses 'p' it will pause the game //---------------------------------------------- if( ( event.type == SDL_KEYDOWN ) ) { if( ( event.key.keysym.sym == SDLK_p ) && ( show_menu == false ) ) { if( Fps.is_paused() ) Fps.unpause(); else if( !( Fps.is_paused() ) ) Fps.pause(); } if( event.key.keysym.sym == SDLK_ESCAPE ) { if( show_menu == true ) show_menu = false; else if( show_menu == false ) show_menu = true; } } //---------------------------------------------- if( event.type == SDL_QUIT ) { quit = true; } } //Move Player 1 and 2 based on their inputs //---------------------------------------------- if( !( Fps.is_paused() ) && ( show_menu == false ) ) { Player_1.move(); Player_2.move(); //Move the ball and check for scores score = Ball.move( Player_1.hit_box, Player_2.hit_box ); if( score == P1_SCORES ) Player_1.score++; if( score == P2_SCORES ) Player_2.score++; if ( score == P1_SCORES || score == P2_SCORES) Ball.reset(); } //---------------------------------------------- //Render----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- SDL_FillRect( Display, &Display->clip_rect, SDL_MapRGB( Display->format, 0x00, 0x00, 0x00 ) ); if( show_menu == false ) { Player_1.render(); Player_2.render(); Ball.render(); } if( show_menu == true ) Menu.render(); SDL_Flip( Display ); Fps.frame_cap(); //----------------------------------------------------------------------------------------- } //end of main loop------------------------------------------------------------------------------ //---------------------------------------------------------------------------------------------- //Clean up and quit SDL-------- //----------------------------- Player_1.clean_up(); Player_2.clean_up(); Ball.clean_up(); Menu.clean_up(); clean_up(); //----------------------------- return 0; }
void EnvironmentClass::init(const GLint &width, const GLint &height) { for (int i = 0; i < 1; i++) { GLPosition robotPos; robotPos.posX=400; robotPos.posY=400; GLint robotRadius=10; Ball *pRobot = new(std::nothrow) Ball(robotPos, robotRadius, 0); if (NULL == pRobot) continue; //pRobot->type = Object::eRobot; pRobot->setSpeed(100); pRobot->setOrientation(90); //pRobot->direction=120; // pRobot->setTarget(i * 2 + 1010); pRobot->render(glColorVec(0.0f, 80.0f, 100.0f)); // // if (i % 2) // pRobot->setDirectionColor(glColorVec(100, 0, 0)); // else // pRobot->setDirectionColor(glColorVec(200, 0, 100)); vecRobot.push_back(pRobot); //printf("direction is %d\n",pRobot->direction); //printf("direction is %d\n",vecRobot[i]->getOrientation()); } /** *@endcode */ /** *@todo must create 2 robots */ assert(1 == vecRobot.size()); /** * @code * initialize obstacle objects, * rand generater radius for obstacle, it between [16, 48) pixels * generate a rand posion for the obstacle and new circular obstacle instance * set obstacle id,type, default color, * if this obstacle is appointed to a robot, use the robot's direction line color to draw it * add to the obstacle vector */ for (int i = 0; i < 2; i++) { GLPosition obsPos; obsPos.posX=300; obsPos.posY=790-i*790; Bat *pCircObs = new(std::nothrow) Bat(obsPos, 200, 10); if (NULL == pCircObs) continue; pCircObs->direction=90; pCircObs->motionless = false; pCircObs->id = 1010 + i; pCircObs->type = Object::eCircular; pCircObs->render(glColorVec(0, 100, 0)); vecbat.push_back(pCircObs); } /** *@endcode */ /** *@todo must create 6 circular obstacle */ assert(2 == vecbat.size()); /** *@todo remember the gui windows's size */ winWidth = width; winHeight = height; }