示例#1
0
	void GameScene::ReceiveNote(const std::string &note)
	{
		if (note == "BallOffLeft")
		{
            p2Score++;
            scoreText->SetText(GetScoreString());
			ResetBall();
		}
		else if (note == "BallOffRight")
		{
            p1Score++;
            scoreText->SetText(GetScoreString());
			ResetBall();
		}
	}
示例#2
0
Ball::Ball(float x, float y, float width, float height):GameObject(x, y, width, height)
{
	if (!texture.loadFromFile("Textures/ball.png"))
		abort();
	sprite.setTexture(texture);
	//ball.setTextureRect(sf::IntRect(0, 0, 16, 16));
	//centerPivotPoint();
	ResetBall(x, y);

	//TODO: sprite.setOrigin(8, 8);
}
示例#3
0
static void ProcessGameOver(struct BALL *Ball, struct PADDLE *Paddle)
{
	char OutBuf[255];
	
	snprintf(OutBuf, sizeof OutBuf, "GAME OVER! Score is %d. Hit ESC to exit or space to play again.", Score);

	Lives = 0;
	
	DrawStats();
	
	Lives = 3;
	Score = 0;
	
	DrawMessage(OutBuf);
	
	cbreak();
	
AskAgain:
	switch (getch())
	{
		case 27: /*27 is ESC.*/
			endwin();
			exit(0);
			break;
		case ' ':
			break;
		default:
			goto AskAgain;
	}
	
	halfdelay(1);
	DeleteMessage();
	
	DeleteBall(Ball);
	DeletePaddle(Paddle);
	DeleteAllBricks();
	DeleteAllCharms();
	SetLevel(1); /*Set back to the default level again.*/
	
	ResetPaddle(Paddle);
	ResetBricks();
	
	DrawPaddle(Paddle);
	DrawAllBricks();
	
	DrawStats();
	
	/*Assume they want to play again.*/
	WaitForUserLaunch();
	ResetBall(Ball);
	DrawBall(Ball);
	DrawAllBricks(); /*Redraw to fix WaitForUserLaunch() goofing.*/

}
void MyPS2Application::CheckBall()
{
	if (ball->get_z_position() >= 935)
	{
		if (player->get_health() > 0)
		{
			player->LoseLife();
			ResetBall();
		}
		else 
			game_state = GAME_OVER;
	}
	
}
void BouncyBallMain::StartGame()
{
  sbe::Rect const& bound = main_loop_.world()->Boundary();

  title_screen_.Hide();
  ShowEntities();

  left_paddle_->SetX(30);
  left_paddle_->SetY(bound.width() / 3);
  left_paddle_->Reset();

  right_paddle_->SetX(bound.width() - 30 - right_paddle_->width());
  right_paddle_->SetY(bound.height() / 2);
  right_paddle_->Reset();

  left_->Reset();
  right_->Reset();

  ResetBall();
}
void BouncyBallMain::SetupGame()
{
  sbe::EntityCreator ec;
  sbe::Rect const& bound = main_loop_.world()->Boundary();

  unsigned ball_id       = ec.GetUniqueId();
  unsigned left_padd_id  = ec.GetUniqueId();
  unsigned right_padd_id = ec.GetUniqueId();

  int half_width = bound.width() / 2;

  sbe::Rect left_boundary = {bound.x(), bound.y(), half_width, bound.height()};
  left_paddle_ = std::make_shared<Paddle>(left_padd_id);
  left_paddle_->EnableKeyEvents(SDLK_w, SDLK_s);
  left_paddle_->SetInputBoundary(left_boundary);

  sbe::Rect right_boundary = {bound.x() + half_width, bound.y(), half_width, bound.height()};
  right_paddle_ = std::make_shared<PaddleAI>(right_padd_id, ball_id);
  right_paddle_->EnableKeyEvents(SDLK_UP, SDLK_DOWN);
  right_paddle_->SetInputBoundary(right_boundary);
  right_paddle_->DisableEvents();

  ball_ = std::make_shared<Ball>(ball_id, left_padd_id, right_padd_id);
  ResetBall();

  right_ = std::make_shared<Score>(ec.GetUniqueId(), main_loop_.Renderer());
  right_->SetX(bound.width() / 2 + 20);
  right_->SetY(20);

  left_ = std::make_shared<Score>(ec.GetUniqueId(), main_loop_.Renderer());
  left_->SetX(bound.width() / 2 - 50);
  left_->SetY(20);

  game_layer_->AddEntity(left_);
  game_layer_->AddEntity(right_);
  game_layer_->AddEntity(left_paddle_);
  game_layer_->AddEntity(right_paddle_);
  game_layer_->AddEntity(ball_);
}
void BouncyBallMain::CheckIfWinning()
{
  bool win = false;
  if (left_->GetScore() >= WIN)
  {
    losing_screen_.SetPlayer1Wins();
    win = true;
  }
  else if (right_->GetScore() >= WIN)
  {
    losing_screen_.SetPlayer2Wins();
    win = true;
  }

  ResetBall();

  if (win)
  {
    HideEntities();
    losing_screen_.Show();
    losing_ = true;
  }
}
示例#8
0
static void GameLoop(struct BALL *const Ball, struct PADDLE *const Paddle)
{ /*Primary loop where most events get processed.*/
	
	struct BRICKSTRIKE Strike;
	int Key = 0;
	int SecTick = 0;
	Bool PaddleMovedLastTick;
	DirectionX PaddleMoveDir;
	int Inc = 0;
	Bool Flip = false;
	int SlowBallTicks = 0, BallNukeTicks = 0;
	
	while ((Key = getch()) != 27) /*27 is ESC*/
	{		
		if (SecTick == 10)
		{ /*We get score every second for just surviving.*/
			Score += 2;
			DrawStats();
			SecTick = 0;
		}
		++SecTick;

		if (Ball->Y == 1)
		{ /*We hit the ceiling.*/
			BounceBallY(Ball, DOWN);
		}
		else if (Ball->Y >= BRICKTICK_MAX_Y - 2)
		{ /*More happens when we hit the floor.*/
			if (!CheckBallHitPaddle(Ball, Paddle))
			{
				DeleteBall(Ball);
				Ball->Y = BRICKTICK_MAX_Y - 1;
				DrawBall(Ball);
				
				if (Lives == 1)
				{ /*We ran out of lives.*/
					ProcessGameOver(Ball, Paddle);
				}
				else
				{
					--Lives;
					DrawStats();
					
					WaitForUserLaunch();
							
					DeleteBall(Ball);
					DeletePaddle(Paddle);
					
					ResetBall(Ball);
					ResetPaddle(Paddle);
					
					DrawPaddle(Paddle);
					DrawBall(Ball);
					
					/*Redraw but don't reset.*/
					DrawAllBricks();
				}
			}
			else
			{
				BounceBallY(Ball, UP);
				
				if (PaddleMovedLastTick)
				{ /*We can "whack" the ball with our Paddle->*/
					Ball->DirX = PaddleMoveDir;
				}
				else
				{ /*We cut the paddle into thirds for the X direction after bounce.*/
#define PADDLE_THIRD (Paddle->Length / 3)
					if (Ball->X <= Paddle->X + PADDLE_THIRD)
					{
						Ball->DirX = LEFT;
					}
					else if (Ball->X  > Paddle->X + PADDLE_THIRD && Ball->X <= Paddle->X + (PADDLE_THIRD * 2))
					{
						/*Make whether we hit up or not as a chance.*/
						Bool StraightUp = rand() & 1;
						if (StraightUp) Ball->DirX = X_NEUTRAL;
					}
					else
					{
						Ball->DirX = RIGHT;
					}
				}
			}
		}
		PaddleMovedLastTick = false;
		/*Bounce off left and right walls.*/
		if (Ball->X >= BRICKTICK_MAX_X - 1)
		{
			Ball->X = BRICKTICK_MAX_X - 1;
			BounceBallX(Ball, LEFT);
		}
		else if (Ball->X <= 0)
		{
			Ball->X = 0;
			BounceBallX(Ball, RIGHT);
		}
			
	
		/*Check if a charm hit the paddle.*/
		for (Inc = 0; Inc < BRICK_MAX_NUMLINES * BRICK_MAX_PERLINE; ++Inc)
		{
			if (Charms[Inc].Type == CHARM_NONE || !Charms[Inc].Dropped || Charms[Inc].Y != BRICKTICK_MAX_Y - 2) continue;
			
			if (CheckCharmHitPaddle(Paddle, Charms + Inc))
			{
				void *Ptr = NULL;
				const char *const Strings[] = { "+1,000 Score", "+1 Lives",
											"10 Second Slow Ball", "3 second nuke mode" };
					
				switch (Charms[Inc].Type)
				{
					case CHARM_SCORE:
						Ptr = &Score;
						break;
					case CHARM_LIFE:
						Ptr = &Lives;
						break;
					case CHARM_SLOW:
						Ptr = &SlowBallTicks;
						break;
					case CHARM_NUKE:
						Ptr = &BallNukeTicks;
						break;
					default:
						break;
				}
				
				if (Charms[Inc].Type != CHARM_NONE)
				{ /*Show a message on what type of charm we have here.*/
					DrawMessage(Strings[Charms[Inc].Type - 1]); fflush(NULL);
					usleep(500000);
					DeleteMessage();
					DrawAllBricks();
					DrawStats();
				}
				
				/*Do the thing the charm does.*/
				ProcessCharmAction(Charms + Inc, Ptr);
			}
			
			/*In any case, we're done with it.*/
			DeleteCharm(Charms + Inc);
			Charms[Inc].Type = CHARM_NONE;
		}
		
		/*We hit a brick.*/
		if (BallStruckBrick(Ball, &Strike))
		{
			
			if (BallNukeTicks == 0) /*Nuclear ball passes through.*/
			{
				switch (Strike.StrikeV)
				{
					case STRIKE_TOP:
						Ball->DirY = UP;
						break;
					case STRIKE_BOTTOM:
						Ball->DirY = DOWN;
						break;
					default:
						break;
				}
				
				switch (Strike.StrikeH)
				{
					case STRIKE_LEFT:
						Ball->DirX = LEFT;
						break;
					case STRIKE_RIGHT:
						Ball->DirX = RIGHT;
						break;
					default:
					{
						if (Ball->DirX != X_NEUTRAL) break;
						else
						{
							Bool Dir = rand() & 1;
							Ball->DirX = (DirectionX)Dir;
						}
						break;
					}
				}
			}
			
			DeleteBrick(Strike.Brick);
			Score += 100;
			DrawStats();
			
			if (!BricksLeft())
			{ /*Move to next level.*/

				if (SetLevel(Level + 1))
				{ /*We have more levels to go before we win.*/
					DeleteAllBricks();
					DeleteAllCharms();
					DeleteBall(Ball);
					DeletePaddle(Paddle);
					DrawStats();
					
					Score += 1000; /*Reward for making it this far.*/
					Lives = BRICKTICK_NUMLIVES;
					
					ResetBall(Ball);
					ResetPaddle(Paddle);
					ResetBricks();
					
					DrawAllBricks();
					DrawPaddle(Paddle);
					WaitForUserLaunch();
					DrawBall(Ball);
					DrawAllBricks(); /*Redraw to fix WaitForUserLaunch() goofing.*/
				}
				else
				{ /*WE WON!!!!*/
					char WonBuf[256];
					
					snprintf(WonBuf, sizeof WonBuf, "You Won! Score is %d! Hit ESC to exit or space to play again.", Score);
					DrawMessage(WonBuf);
					
				WinRegetch:
					switch (getch())
					{
						case 27: /*27 is ESC*/
							endwin();
							exit(0);
							break;
						case ' ':
						{
							DeleteMessage();
							
							SetLevel(1);
							
							Lives = BRICKTICK_NUMLIVES;
							Score = 0;
							
							DeleteAllBricks();
							DeleteAllCharms();
							DeleteBall(Ball);
							DeletePaddle(Paddle);
							DrawStats();
							
							ResetBall(Ball);
							ResetPaddle(Paddle);
							ResetBricks();
							
							DrawAllBricks();
							DrawPaddle(Paddle);
							WaitForUserLaunch();
							DrawBall(Ball);
							DrawAllBricks(); /*Redraw to fix WaitForUserLaunch() goofing.*/

							continue; /*For the loop we are in.*/
						}
						default:
							goto WinRegetch;
					}
				}

				continue;
			}
			else
			{ /*Charm drops.*/
				struct CHARM *Charm = GetCharmByBrick(Strike.Brick);
				
				if (Charm)
				{ /*We DO have a charm for this brick.*/
					PerformCharmDrop(Charm); /*Mark it dropped.*/

					/*Now draw the charm.*/
					DrawCharm(Charm);
				}
			}
		}
		
		switch (Key)
		{ /*Paddle movement.*/
			case KEY_LEFT:
				MovePaddle(Paddle, LEFT);
				PaddleMovedLastTick = true;
				PaddleMoveDir = LEFT;
				break;
			case KEY_RIGHT:
				MovePaddle(Paddle, RIGHT);
				PaddleMovedLastTick = true;
				PaddleMoveDir = RIGHT;
				break;
			case 's': /*They want to save the game.*/
				if (SaveGame(Ball, Paddle))
				{
					DrawMessage("Game saved.");
				}
				else
				{
					DrawMessage("Failed to save game.");
				}
				fflush(NULL);
				usleep(500000);
				
				DeleteMessage();
				DrawAllBricks(); /*Redraw bricks if damaged.*/
				
				break;
			case 'o': /*They want us to load a game.*/
			{
				const Bool LoadedOk = LoadGame(Ball, Paddle);
				
				if (LoadedOk)
				{
					/*Restore the state.*/
					clear();
					DrawBorders(); /*Need to redraw these after clearing the screen.*/
					
					DrawBall(Ball);
					DrawPaddle(Paddle);
					DrawStats();
					DrawAllBricks();
					
					DrawMessage("Game loaded.");
				}
				else
				{
					DrawMessage("Failed to load game.");
				}

				fflush(NULL);
				usleep(500000);
				
				DeleteMessage();
				DrawAllBricks();
				break;
			}
			case ' ':
			{
				DrawMessage("PAUSED");
				cbreak();
				
			PauseRegetch:
				switch (getch())
				{
					case ' ':
						DeleteMessage();
						DrawAllBricks(); /*Redraw to fix what deleting the message messed up.*/
						halfdelay(1);
						break;
					case 27: /*27 is ESC*/
						endwin();
						exit(0);
						break;
					default:
						goto PauseRegetch;
				}
			}
			default:
				break;
		}
		
		Flip = !Flip;

		/*Ball movement, obviously. Flip is used to keep it at half speed if we got a 'slow' charm.*/
		if (Flip || SlowBallTicks == 0) MoveBall(Ball);
		
		/*Decrement slow ball ticks until zero, then the ball goes fast again.*/
		if (SlowBallTicks > 0) --SlowBallTicks;
		
		/*Decrement nuclear ball until ticks hit zero.*/
		if (BallNukeTicks > 0) --BallNukeTicks;
		
		/*Charm movement.*/		
		for (Inc = 0; Inc < BRICK_MAX_NUMLINES * BRICK_MAX_PERLINE; ++Inc)
		{
			if (Charms[Inc].Type == CHARM_NONE || !Charms[Inc].Dropped) continue;
			
			if (Flip) MoveCharm(Charms + Inc);
		}
		
		/*Redraw borders in case of terminal resize.*/
		DrawBorders();
	}
}
示例#9
0
int main(int argc, char **argv)
{
	int Inc = 1;
	struct BALL Ball = { 0 };
	struct PADDLE Paddle = { 0 };
	Bool DoLoadGame = false;
	int GotoLevel = 0;
	
	for (; Inc < argc; ++Inc)
	{ /*Argument parsing.*/
		if (!strcmp("--nocolor", argv[Inc]))
		{
			UseColor = false;
		}
		else if (!strcmp("--version", argv[Inc]))
		{
			printf("Bricktick brick breaker v" BRICKTICK_VERSION "\n"
					"By Subsentient.\n");
			fflush(NULL);
			exit(0);
		}
		else if (!strcmp("--help", argv[Inc]))
		{
			printf("Command line options:\n\t"
					"--help: Show this help.\n\t"
					"--nocolor: Run Bricktick with no color.\n\t"
					"--version: Display version and exit.\n");
			fflush(NULL);
			exit(0);
		}
		else if (!strncmp("--level=", argv[Inc], sizeof "--level=" - 1))
		{
			GotoLevel = atoi(argv[Inc] + sizeof "--level=" - 1);
			
			if (GotoLevel > sizeof Levels / sizeof *Levels)
			{
				fprintf(stderr, "The maximum level is %d.\n", sizeof Levels / sizeof *Levels); fflush(NULL);
				exit(1);
			}
		}
		else
		{
			fprintf(stderr, "Bad command line argument \"%s\".\n"
					"Use --help for command line options.\n", argv[Inc]);
			exit(1);
		}
	}
	
	
	initscr(); /*Fire up ncurses.*/
	
	if (COLS < BRICKTICK_MAX_X || LINES < BRICKTICK_MAX_Y)
	{
		endwin();
		fprintf(stderr, "Please use a console with a resolution of at least %dx%d.\n", BRICKTICK_MAX_X, BRICKTICK_MAX_Y);
		exit(1);
		
	}
	
	/*Color not supported.*/
	if (!has_colors()) UseColor = false;
	
	/*Various ncurses things.*/
	noecho();
	
	if (UseColor)
	{ /*Color fireup.*/
		start_color();
		init_pair(1, COLOR_CYAN, COLOR_BLACK);
		init_pair(2, COLOR_GREEN, COLOR_BLACK);
		init_pair(3, COLOR_BLACK, COLOR_WHITE);
		init_pair(4, COLOR_BLUE, COLOR_BLACK);
		init_pair(5, COLOR_GREEN, COLOR_BLACK);
		init_pair(6, COLOR_YELLOW, COLOR_BLACK);
		init_pair(7, COLOR_RED, COLOR_BLACK);
		
		
		/*Fire up colors for the bricks.*/
		init_pair(BRICK_COLORS_START, COLOR_GREEN, COLOR_BLACK);
		init_pair(BRICK_COLORS_START + 1, COLOR_BLUE, COLOR_BLACK);
		init_pair(BRICK_COLORS_START + 2, COLOR_YELLOW, COLOR_BLACK);
		init_pair(BRICK_COLORS_START + 3, COLOR_MAGENTA, COLOR_BLACK);
		init_pair(BRICK_COLORS_START + 4, COLOR_CYAN, COLOR_BLACK);
		init_pair(BRICK_COLORS_END, COLOR_RED, COLOR_BLACK);
	}
	
	/*Draw borders for consoles bigger than our 80x24 playing area.*/
	DrawBorders();
	
	/*Greeting.*/
GreetAsk:

	if (!GotoLevel)
	{ /*If they specified a level let them go straigth to game start.*/
		DrawGreeting();
		switch (getch())
		{
			case 27: /*27 is ESC key*/
				endwin();
				exit(0);
				break;
			case ' ':
				clear(); /*Wipe the message from the screen.*/
				DrawBorders(); /*Redraw borders.*/
				break;
			case 'o':
				clear();
				DrawBorders();
				DoLoadGame = true;
				LoadGame(&Ball, &Paddle);
				break;
			default:
				goto GreetAsk;
		}
	}
	else
	{
		clear();
		DrawBorders();
	}
	
	halfdelay(1);
	keypad(stdscr, true);
#if NCURSES_VERSION_MAJOR >= 5 && NCURSES_VERSION_MINOR >=4
	set_escdelay(25);
#endif
	curs_set(0);
	

	if (DoLoadGame)
	{
		DrawStats();
		DrawBall(&Ball);
		DrawPaddle(&Paddle);
		DrawAllBricks();
	}
	else
	{
		/*Show our initial lives count.*/
		DrawStats();
	
		/*Reset to level 1 if we haven't specified a level.*/
		SetLevel(GotoLevel ? GotoLevel : 1);
		
		ResetBall(&Ball);
		ResetPaddle(&Paddle);
		
		DrawBall(&Ball);
		DrawPaddle(&Paddle);
		ResetBricks();
		DrawAllBricks();
	}
	
	/*Wait for L key.*/
	WaitForUserLaunch();
	DrawAllBricks(); /*Redraw to fix goofing by WaitForUserLaunch().*/
	
	/*Set up the number generator.*/
	srand(time(NULL));

	/**
	 * Main loop for the game!
	 **/
Reloop:
	GameLoop(&Ball, &Paddle);
	
	DrawMessage("Really quit Bricktick? y/n");
	cbreak();
	
	/*When the game loop exits.*/
	switch (getch())
	{
		case 'y':
		case 'Y':
			break;
		default:
			DeleteMessage();
			refresh();
			halfdelay(1);
			DrawAllBricks(); /*Fix damage to brick display resulting from the message.*/
			goto Reloop;
			break;
	}
	DeleteBall(&Ball);
	DeletePaddle(&Paddle);
	
	endwin();
	
	return 0;
}
示例#10
0
void Main::UpdateStateFrame(double simulation_frame_time) {
    mBallSpeed *= 1.0 + (simulation_frame_time * 0.05);

    // move paddle 1
    float move1 = 0;
    if(dt::InputManager::Get()->GetKeyboard()->isKeyDown(OIS::KC_W)) {
        move1 += 1;
    }
    if(dt::InputManager::Get()->GetKeyboard()->isKeyDown(OIS::KC_S)) {
        move1 -= 1;
    }
    float new_y1 = mPaddle1Node->GetPosition().y + move1 * simulation_frame_time * 8;
    if(new_y1 > FIELD_HEIGHT / 2 - PADDLE_SIZE / 2)
        new_y1 = FIELD_HEIGHT / 2 - PADDLE_SIZE / 2;
    else if(new_y1 < - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2)
        new_y1 = - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2;

    mPaddle1Node->SetPosition(Ogre::Vector3(
                mPaddle1Node->GetPosition().x,
                new_y1,
                mPaddle1Node->GetPosition().z));

    // move paddle 2
    float move2 = 0;
    if(dt::InputManager::Get()->GetKeyboard()->isKeyDown(OIS::KC_UP)) {
        move2 += 1;
    }

    if(dt::InputManager::Get()->GetKeyboard()->isKeyDown(OIS::KC_DOWN)) {
        move2 -= 1;
    }

    float new_y2 = mPaddle2Node->GetPosition().y + move2 * simulation_frame_time * 8;
    if(new_y2 > FIELD_HEIGHT / 2 - PADDLE_SIZE / 2)
        new_y2 = FIELD_HEIGHT / 2 - PADDLE_SIZE / 2;
    else if(new_y2 < - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2)
        new_y2 = - FIELD_HEIGHT / 2  + PADDLE_SIZE / 2;

    mPaddle2Node->SetPosition(Ogre::Vector3(
                mPaddle2Node->GetPosition().x,
                new_y2,
                mPaddle2Node->GetPosition().z));

    // move ball
    Ogre::Vector3 newpos(mBallNode->GetPosition() + mBallSpeed * simulation_frame_time);
    if(newpos.y >= FIELD_HEIGHT / 2 - 0.5 || newpos.y <= -FIELD_HEIGHT / 2 + 0.5) {
        mBallSpeed.y *= -1;
    }

    if(newpos.x >= FIELD_WIDTH / 2 - 0.5) {
        float paddle_y = mPaddle2Node->GetPosition().y;
        if(newpos.y < paddle_y - PADDLE_SIZE / 2 - 0.5 || newpos.y > paddle_y + PADDLE_SIZE / 2 + 0.5) {
            dt::Logger::Get().Info("Player lost!");
            ++mScore1;
            ResetBall();
        } else {
            mBallSpeed.x *= -1;
        }
    } else if(newpos.x <= -FIELD_WIDTH / 2 + 0.5) {
        float paddle_y = mPaddle1Node->GetPosition().y;
        if(newpos.y < paddle_y - PADDLE_SIZE / 2 - 0.5 || newpos.y > paddle_y + PADDLE_SIZE / 2 + 0.5) {
            dt::Logger::Get().Info("Computer lost!");
            ++mScore2;
            ResetBall();
        } else {
            mBallSpeed.x *= -1;
        }
    }

    mBallNode->SetPosition(mBallNode->GetPosition() + mBallSpeed * simulation_frame_time);

    Ogre::Quaternion q;
    q.FromAngleAxis(Ogre::Radian(Ogre::Math::Cos(Ogre::Radian(dt::Root::GetInstance().GetTimeSinceInitialize() * 0.2))) * 0.1, Ogre::Vector3::UNIT_X);
    Ogre::Quaternion w;
    w.FromAngleAxis(Ogre::Radian(Ogre::Math::Sin(Ogre::Radian(dt::Root::GetInstance().GetTimeSinceInitialize() * 0.2))) * 0.1, Ogre::Vector3::UNIT_Y);
    mGameNode->SetRotation(q * w);
}
示例#11
0
void Main::OnInitialize() {
    mScore1 = 0;
    mScore2 = 0;

    dt::Scene* scene = AddScene(new dt::Scene("testscene"));
    OgreProcedural::Root::getInstance()->sceneManager = scene->GetSceneManager();

    dt::ResourceManager::Get()->AddResourceLocation("","FileSystem", true);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    Ogre::FontManager::getSingleton().load("DejaVuSans", "General");

    dt::Node* camnode = scene->AddChildNode(new dt::Node("camnode"));
    camnode->SetPosition(Ogre::Vector3(0, 0, 30));
    camnode->AddComponent(new dt::CameraComponent("cam"))->LookAt(Ogre::Vector3(0, 0, 0));

    dt::Node* lightnode = scene->AddChildNode(new dt::Node("lightnode"));
    lightnode->SetPosition(Ogre::Vector3(-20, 20, 10));
    lightnode->AddComponent(new dt::LightComponent("light"));

    // generate meshes
    OgreProcedural::BoxGenerator().setSizeX(FIELD_WIDTH + 1).setSizeY(FIELD_HEIGHT).setSizeZ(1.f).realizeMesh("Field");
    OgreProcedural::BoxGenerator().setSizeX(1.0).setSizeY(1.f).setSizeZ(1.f).realizeMesh("Ball");
    OgreProcedural::BoxGenerator().setSizeX(1.0).setSizeY(3.f).setSizeZ(1.f).realizeMesh("Paddle");

    mGameNode = scene->AddChildNode(new dt::Node("game"));

    mFieldNode = mGameNode->AddChildNode(new dt::Node("field"));
    mFieldNode->SetPosition(Ogre::Vector3(0, 0, -1));
    mFieldNode->AddComponent(new dt::MeshComponent("Field", "SimplePongField", "mesh"));

    mBallNode = mGameNode->AddChildNode(new dt::Node("ball"));
    mBallNode->SetPosition(Ogre::Vector3(0, 0, 0));
    mBallNode->AddComponent(new dt::MeshComponent("Ball", "SimplePongBall", "mesh"));

    mPaddle1Node = mGameNode->AddChildNode(new dt::Node("paddle1"));
    mPaddle1Node->SetPosition(Ogre::Vector3(- FIELD_WIDTH / 2 - 0.5, 0, 0));
    mPaddle1Node->AddComponent(new dt::MeshComponent("Paddle", "SimplePongPaddle", "mesh"));

    mPaddle2Node = mGameNode->AddChildNode(new dt::Node("paddle2"));
    mPaddle2Node->SetPosition(Ogre::Vector3(FIELD_WIDTH / 2 + 0.5, 0, 0));
    mPaddle2Node->AddComponent(new dt::MeshComponent("Paddle", "SimplePongPaddle", "mesh"));

    dt::Node* score1_node = mGameNode->AddChildNode(new dt::Node("score1"));
    score1_node->SetPosition(Ogre::Vector3(-10, FIELD_HEIGHT / 2 + 2, 0));
    mScore1Text = score1_node->AddComponent(new dt::TextComponent("0", "text"));
    mScore1Text->SetFont("DejaVuSans");
    mScore1Text->SetFontSize(64);

    dt::Node* score2_node = mGameNode->AddChildNode(new dt::Node("score2"));
    score2_node->SetPosition(Ogre::Vector3(10, FIELD_HEIGHT / 2 + 2, 0));
    mScore2Text = score2_node->AddComponent(new dt::TextComponent("0", "text"));
    mScore2Text->SetFont("DejaVuSans");
    mScore2Text->SetFontSize(64);

    dt::Node* info_node = scene->AddChildNode(new dt::Node("info"));
    info_node->SetPosition(Ogre::Vector3(0, - FIELD_HEIGHT / 2 - 3, 0));
    dt::TextComponent* info_text = info_node->AddComponent(new dt::TextComponent("Left player: W/S -- Right player: Up/Down", "text"));
    info_text->SetFont("DejaVuSans");
    info_text->SetFontSize(20);

    ResetBall();
}