Ejemplo n.º 1
0
void Volley::init()
{
	isReset = true;
	EventManager::get()->addListener((IEventListener*)this, LAUNCH_BALL);
	EventManager::get()->addListener((IEventListener*)this, SCORE);
	field = ActorFactory::get()->createActor("Field.xml");

	createPlayer(1, p1Horiz, p1Vert);
	createPlayer(2, p2Horiz, p2Vert);
	paddles.push_back(p1Horiz);
	paddles.push_back(p2Horiz);
	paddles.push_back(p1Vert);
	paddles.push_back(p2Vert);

	makeBumpers();
	makeBall();
}
Ejemplo n.º 2
0
void Pong::startMatch(void)
{
   inMatch = true;
   app->osmShout.setMessage("FIGHT", 3.0f);
   app->soundPlayer->effect("fight");
   std::ostringstream centerText;
   centerText << "Score " << app->scoreToWin << " points to win";
   app->osmCenter.setMessage(centerText.str(), 3.0f);

   for(std::vector<Player*>::iterator it = app->players.begin(); it != app->players.end(); it++)
   {
      if(*it != 0)
      {
         (*it)->setScore(0);
      }
   }

   makeBall();
}
Ejemplo n.º 3
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){

	switch (key){
        case 'k':
            clearPendulums();
            break;

        case 'b':
            makeBall();
            break;

        case 'x':
            makeBox();
            break;
            
		case 'c':
            clearBallsAndBoxes();
			break;
	}
}
Ejemplo n.º 4
0
/*** メイン関数 ***/
int main(int argc, char *argv[])
{
    dInitODE(); // ODEの初期化
    setDrawStuff(); // 描画関数の設定
    world        = dWorldCreate();              // ワールドの生成
    space        = dHashSpaceCreate(0);         // スペースの生成
    contactgroup = dJointGroupCreate(0);        // 接触点グループの生成
    ground       = dCreatePlane(space,0,0,1,0); // 地面の生成
    dWorldSetGravity(world, 0.0, 0.0, - 9.8); // 重力加速度の設定
    dWorldSetCFM(world,1e-3); // CFMの設定
    dWorldSetERP(world,0.8);  // ERPの設定

    makeOmni(); // 全方向移動ロボットの生成
    makeBall(); // ボールの生成
    makeGoal(); // ゴールの生成
    dsSimulationLoop(argc,argv,640,480,&fn); // シミュレーションループ

    dJointGroupDestroy(contactgroup);  // 接触点グループの破壊
    dSpaceDestroy(space);              // スペースの破壊
    dWorldDestroy(world);              // ワールドの破壊
    dCloseODE(); // ODEの終了
    return 0;
}
Ejemplo n.º 5
0
// return true if ball is out
bool Pong::checkBall(Ball* ball)
{
   bool ballOut = false;
   Vec2d pos = ball->getPosition();

   if(pos.x < 0)
   {
      this->ballOut(app->PLAYER_RIGHT);
      ballOut = true;
   }
   else if(pos.x >= app->x_res)
   {
      this->ballOut(app->PLAYER_LEFT);
      ballOut = true;
   }
   else if(!(pos.y >= 0 && pos.y < app->y_res))
   {
      makeBall();
      ballOut = true;
   }

   return ballOut;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
	/* initialize SDL and its subsystems */
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1) die();
	if (TTF_Init() == -1) die();

	/* set the height and width of the main window, as well as the number
	   of bits per pixel; this needs to be done prior to initializing the 
	   main window (*screen, below) */
	initWindowAttributes();

	/* the frame buffer */
	SDL_Surface *screen = SDL_SetVideoMode(W_WIDTH, W_HEIGHT,
			W_COLOR_DEPTH, SDL_HWSURFACE|SDL_FULLSCREEN);
	if (!screen) die();

	/* hide the mouse cursor */
	SDL_ShowCursor(SDL_DISABLE);

	/* the background color of the screen */
	const Uint32 clearColor = CLEAR_COLOR(screen->format);
	clearScreen(screen, clearColor);

	/* clearColor as an SDL_Color, for use with TTF */
	Uint8 r, g, b;
	SDL_GetRGB(clearColor, screen->format, &r, &g, &b);
	SDL_Color bgColor = { r: r, g: g, b: b };

	/* the score font */
	TTF_Font *font = TTF_OpenFont("resources/VeraMono.ttf", FONT_SIZE);
	if (!font) die();
	SDL_Color fontColor = FONT_COLOR;

	/* the score text; we'll allow three digits plus the terminating '\0' */
	char *lScoreStr = malloc(sizeof(char) * 4);
	char *rScoreStr = malloc(sizeof(char) * 4);
	if (!lScoreStr || !rScoreStr) die();
	SDL_Surface *lScore = NULL, *rScore = NULL;
	SDL_Rect lScorePos = { x: C_X+FONT_SIZE, y: C_HEIGHT/5,
		w: F_WIDTH, h: F_HEIGHT };
	SDL_Rect rScorePos = { x: (C_X+C_WIDTH)-3*FONT_SIZE, y: C_HEIGHT/5,
		w: F_WIDTH, h: F_HEIGHT };

	/* set up the playing court */
	Court *court = makeCourt(screen);
	if (!court) die();

	/* set up the players and their paddles */
	Player *lPlayer = makePlayer(screen);
	Player *rPlayer = makePlayer(screen);
	if (!lPlayer || !rPlayer) die();
	rPlayer->paddle.rect.x = C_X + C_WIDTH - P_WIDTH;

	/* add the ball */
	Ball *ball = makeBall(screen);
	if (!ball) die();

	/* because SDL_KEY(UP|DOWN) occurs only once, not continuously while
	   the key is pressed, we need to keep track of whether a key is
	   (still) pressed */
	bool lPlayerShouldMoveUp = false, lPlayerShouldMoveDown = false,
	     rPlayerShouldMoveUp = false, rPlayerShouldMoveDown = false;

	Uint32 startTime;	/* denotes the beginning of each iteration
				   of the main event loop */
	bool running = true;	/* true till the application should exit */
	while (running) {
		startTime = SDL_GetTicks();

		/* clear the previous frame's paddles and ball */
		SDL_FillRect(screen, &lPlayer->paddle.rect, clearColor);
		SDL_FillRect(screen, &rPlayer->paddle.rect, clearColor);
		SDL_FillRect(screen, &ball->rect, clearColor);

		/* clear the previous frame's score */
		SDL_FillRect(screen, &lScorePos, clearColor);
		SDL_FillRect(screen, &rScorePos, clearColor);

		/* redraw the walls in case they were clipped by the ball
		   in a previous frame */
		SDL_FillRect(screen, &court->upperWall, court->color);
		SDL_FillRect(screen, &court->lowerWall, court->color);

		/* get the current state of the players' controls */
		readPlayerInput(&running,
				&lPlayerShouldMoveUp, &lPlayerShouldMoveDown,
				&rPlayerShouldMoveUp, &rPlayerShouldMoveDown);

		/* save the current position of the paddles */
		lPlayer->paddle.prevY = lPlayer->paddle.rect.y;
		rPlayer->paddle.prevY = rPlayer->paddle.rect.y;

		/* move the paddles if appropriate */
		if (lPlayerShouldMoveUp)
			movePaddle(court, &lPlayer->paddle, UP);
		else if (lPlayerShouldMoveDown)
			movePaddle(court, &lPlayer->paddle, DOWN);
		if (rPlayerShouldMoveUp)
			movePaddle(court, &rPlayer->paddle, UP);
		else if (rPlayerShouldMoveDown)
			movePaddle(court, &rPlayer->paddle, DOWN);

		/* move the ball */
		moveBall(court, ball, lPlayer, rPlayer);

		/* update the score */
		updateScore(ball, lPlayer, rPlayer);

		/* update the on-screen score */
		if (lScore) SDL_FreeSurface(lScore);
		snprintf(lScoreStr, 4, "%2d", lPlayer->points);
		lScore = TTF_RenderText_Shaded(font, lScoreStr, fontColor,
				bgColor);
		if (rScore) SDL_FreeSurface(rScore);
		snprintf(rScoreStr, 4, "%2d", rPlayer->points);
		rScore = TTF_RenderText_Shaded(font, rScoreStr, fontColor,
				bgColor);

		/* draw the score */
		SDL_BlitSurface(lScore, NULL, screen, &lScorePos);
		SDL_BlitSurface(rScore, NULL, screen, &rScorePos);

		/* draw the paddles */
		SDL_FillRect(screen, &lPlayer->paddle.rect,
				lPlayer->paddle.color);
		SDL_FillRect(screen, &rPlayer->paddle.rect,
				rPlayer->paddle.color);

		/* draw the ball */
		SDL_FillRect(screen, &ball->rect, ball->color);

		/* render frame to screen */
		SDL_Flip(screen);

		/* keep a steady frame rate */
		Uint8 elapsedTime = SDL_GetTicks() - startTime;
		if (elapsedTime < FRAME_DURATION)
			SDL_Delay(FRAME_DURATION - elapsedTime);
	}

	/* free resources */
	free(lScoreStr);
	free(rScoreStr);
	free(court);
	free(lPlayer);
	free(rPlayer);
	free(ball);

	TTF_CloseFont(font);
	TTF_Quit();
	SDL_FreeSurface(lScore);
	SDL_FreeSurface(rScore);
	SDL_Quit();

	return EXIT_SUCCESS;
}
Ejemplo n.º 7
0
void Model::makeBall(float radius, size_t step) {
    makeBall(radius, step, glm::vec3());
}
Ejemplo n.º 8
0
void Model::makeBall(float radius, size_t step, const glm::vec3 &center) {
    makeBall(radius, step, 2 * step, center);
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
    GraphType graphType;
    edgefn ef;

    opts.pfx = "";
    opts.name = "";
    opts.cnt = 1;
    graphType = init(argc, argv, &opts);
    if (opts.directed) {
	fprintf(opts.outfile, "digraph %s{\n", opts.name);
	ef = dirfn;
    }
    else {
	fprintf(opts.outfile, "graph %s{\n", opts.name);
	ef = undirfn;
    }

    switch (graphType) {
    case grid:
	makeSquareGrid(opts.graphSize1, opts.graphSize2,
		       opts.foldVal, opts.isPartial, ef);
	break;
    case circle:
	makeCircle(opts.graphSize1, ef);
	break;
    case path:
	makePath(opts.graphSize1, ef);
	break;
    case tree:
	if (opts.graphSize2 == 2)
	    makeBinaryTree(opts.graphSize1, ef);
	else
	    makeTree(opts.graphSize1, opts.graphSize2, ef);
	break;
    case trimesh:
	makeTriMesh(opts.graphSize1, ef);
	break;
    case ball:
	makeBall(opts.graphSize1, opts.graphSize2, ef);
	break;
    case torus:
	if ((opts.parm1 == 0) && (opts.parm2 == 0))
	    makeTorus(opts.graphSize1, opts.graphSize2, ef);
	else
	    makeTwistedTorus(opts.graphSize1, opts.graphSize2, opts.parm1, opts.parm2, ef);
	break;
    case cylinder:
	makeCylinder(opts.graphSize1, opts.graphSize2, ef);
	break;
    case mobius:
	makeMobius(opts.graphSize1, opts.graphSize2, ef);
	break;
    case sierpinski:
	makeSierpinski(opts.graphSize1, ef);
	break;
    case complete:
	makeComplete(opts.graphSize1, ef);
	break;
    case randomg:
	makeRandom (opts.graphSize1, opts.graphSize2, ef);
	break;
    case randomt:
	{
	    int i;
	    treegen_t* tg = makeTreeGen (opts.graphSize1);
	    for (i = 1; i <= opts.cnt; i++) {
		makeRandomTree (tg, ef);
		if (i != opts.cnt) closeOpen ();
	    }
	    freeTreeGen (tg);
	}
	makeRandom (opts.graphSize1, opts.graphSize2, ef);
	break;
    case completeb:
	makeCompleteB(opts.graphSize1, opts.graphSize2, ef);
	break;
    case hypercube:
	makeHypercube(opts.graphSize1, ef);
	break;
    case star:
	makeStar(opts.graphSize1, ef);
	break;
    case wheel:
	makeWheel(opts.graphSize1, ef);
	break;
    default:
	/* can't happen */
	break;
    }
    fprintf(opts.outfile, "}\n");

    exit(0);
}