当前位置: 首页>>代码示例>>C++>>正文


C++ Road::getElement方法代码示例

本文整理汇总了C++中Road::getElement方法的典型用法代码示例。如果您正苦于以下问题:C++ Road::getElement方法的具体用法?C++ Road::getElement怎么用?C++ Road::getElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Road的用法示例。


在下文中一共展示了Road::getElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init

//functia care permite adaugarea de obiecte
void DrawingWindow::init()
{
	srand(time(NULL));
	glutFullScreen();
	v2d1 = new Visual2D(-WINDOW_X,-WINDOW_Y,WINDOW_X, WINDOW_Y, 0, 0,DrawingWindow::width,DrawingWindow::height); 
	v2d1->tipTran(true);
	addVisual2D(v2d1);

	// initializari pentru afisaj: scor, vieti, distanta parcursa:
	sDistance	= "Distance:  ";
	sLives		= "Lives:  ";
	sScore		= "Score:  0";
	sTime		= "Time:  ";

	sLives.append(to_string(car.getLives()));
	tDistance = new Text(sDistance, Point2D(-1200,700), Color(1, 1, 1), BITMAP_TIMES_ROMAN_24);
	tLives = new Text(sLives, Point2D(-1200, 650), Color(1, 1, 1), BITMAP_TIMES_ROMAN_24);
	tScore = new Text(sScore, Point2D(900, 700), Color(1, 1, 1), BITMAP_TIMES_ROMAN_24);
	tTime = new Text(sTime, Point2D(900, 650), Color(1, 1, 1), BITMAP_TIMES_ROMAN_24);
	tGameOver = new Text("", Point2D(0, 650), Color(1, 1, 1), BITMAP_TIMES_ROMAN_24);
	tSpeedBonus = new Text("", Point2D(0, 650), Color(1, 1, 1), BITMAP_TIMES_ROMAN_24);

	addText_to_Visual2D(tDistance, v2d1);
	addText_to_Visual2D(tLives, v2d1);
	addText_to_Visual2D(tScore, v2d1);
	addText_to_Visual2D(tTime, v2d1);
	addText_to_Visual2D(tGameOver, v2d1);
	addText_to_Visual2D(tSpeedBonus, v2d1);

	// adaugare masina in teren:
	for (unsigned int i = 0; i < car.getNoOfElements(); i++) {
		addObject3D_to_Visual2D(car.getElement(i),v2d1);
		car.setPosition(Point3D(0,0,200));
	}

	// adaugare inamic1
	for (int j = 0; j < 4; j++) {
		enemies.push_back(new Enemy1());
	}
	for (int j = 0; j < enemies.size(); j++) {
		for (unsigned int i = 0; i < enemies[j]->getNoOfElements(); i++) {
			addObject3D_to_Visual2D(enemies[j]->getElement(i),v2d1);
		}
		// plasez inamicii in afara campului vizual
		enemies[j]->setPosition(Point3D(0,0,800));
		enemies[j]->dontShow();
	}

	// adaugare inamic2
	for (int j = 0; j < 4; j++) {
		enemies.push_back(new Enemy2());
	}
	for (int j = 0; j < enemies.size(); j++) {
		for (unsigned int i = 0; i < enemies[j]->getNoOfElements(); i++) {
			addObject3D_to_Visual2D(enemies[j]->getElement(i),v2d1);
		}
		// plasez inamicii in afara campului vizual
		enemies[j]->setPosition(Point3D(0,0,800));
		Transform3D::loadIdentityModelMatrix();
		Transform3D::translateMatrix(0,0,800);
		Transform3D::applyTransform(enemies[j]->getElement(0));
		enemies[j]->dontShow();
	}

	// adaugare inamic3
	for (int j = 0; j < 1; j++) {
		enemies.push_back(new Enemy3());
	}
	for (int j = 0; j < enemies.size(); j++) {
		for (unsigned int i = 0; i < enemies[j]->getNoOfElements(); i++) {
			addObject3D_to_Visual2D(enemies[j]->getElement(i),v2d1);
		}
		// plasez inamicii in afara campului vizual
		enemies[j]->setPosition(Point3D(0,0,800));
		Transform3D::loadIdentityModelMatrix();
		Transform3D::translateMatrix(0,0,800);
		Transform3D::applyTransform(enemies[j]->getElement(0));
		enemies[j]->dontShow();
	}

	// adaugare inamic4
	for (int j = 0; j < 3; j++) {
		enemies.push_back(new Enemy4());
	}
	for (int j = 0; j < enemies.size(); j++) {
		for (unsigned int i = 0; i < enemies[j]->getNoOfElements(); i++) {
			addObject3D_to_Visual2D(enemies[j]->getElement(i),v2d1);
		}
		// plasez inamicii in afara campului vizual
		enemies[j]->setPosition(Point3D(0,0,800));
		Transform3D::loadIdentityModelMatrix();
		Transform3D::translateMatrix(0,0,800);
		Transform3D::applyTransform(enemies[j]->getElement(0));
		enemies[j]->dontShow();
	}

	// adaugare shield
	for (int j = 0; j < 1; j++) {
		enemies.push_back(new Shield());
//.........这里部分代码省略.........
开发者ID:alexditu,项目名称:EGC_Tema_2,代码行数:101,代码来源:main.cpp

示例2: onIdle

//functia care permite animatia
void DrawingWindow::onIdle()
{
	if (gameOver == false) {

		float oldSpeed = car.getSpeed(), newSpeed;
		newSpeed = oldSpeed - 0.025;
		if (newSpeed > 0) {
			oldSpeed = newSpeed;
		}
		car.setSpeed (oldSpeed);

		// Apasare taste:
		if (specialKeyStates[KEY_UP]) {
			float oldSpeed = car.getSpeed(), newSpeed;
			newSpeed = oldSpeed + 0.15;
			cout << car.getTopSpeed() << endl;
			if (newSpeed <= car.getTopSpeed()) {
				oldSpeed = newSpeed;
			}
			car.setSpeed (oldSpeed);
		}
		if (specialKeyStates[KEY_DOWN]) {
			float oldSpeed = car.getSpeed(), newSpeed;
			newSpeed = oldSpeed - 0.2;
			if (newSpeed >= 0) {
				oldSpeed = newSpeed;
			} else {
				oldSpeed = 0;
			}
			car.setSpeed (oldSpeed);
		}
		if (specialKeyStates[KEY_LEFT]) {
			float newPosX = car.getPosX() - car.getSpeed();
			// verific sa nu iasa de pe drum!
			if (newPosX - car.getWidth() > drum.getMinX()) {
				car.setPosX(newPosX);
			}
		}
		if (specialKeyStates[KEY_RIGHT]) {
			float newPosX = car.getPosX() + car.getSpeed();
			// verific sa nu iasa de pe drum!
			if (newPosX + car.getWidth() < drum.getMaxX()) {
				car.setPosX(newPosX);
			}
		}
		// pentru schimbare perspectiva
		if (keyStates['a']) {
			xc += pasTaste;
		}
		if (keyStates['s']) {
			yc += pasTaste;
		}
		if (keyStates['d']) {
			zc += pasTaste;
		}
		if (keyStates['z']) {
			xc -= pasTaste;
		}
		if (keyStates['x']) {
			yc -= pasTaste;
		}
		if (keyStates['c']) {
			zc -= pasTaste;
		}
		// pentru rotatie masina
		if (keyStates['q']) {
			float oldAngle = car.getAngle();
			car.setAngle(oldAngle - 0.05);
		}
		if (keyStates['e']) {
			float oldAngle = car.getAngle();
			car.setAngle(oldAngle + 0.05);
		}

		// Afisare drum
		Transform3D::loadIdentityModelMatrix();
		Transform3D::loadIdentityProjectionMatrix();
		Transform3D::perspectiveProjectionMatrix(xc, yc, 400);
		for (unsigned int i = 0; i < drum.getNoOfElements(); i++) {
			Transform3D::applyTransform(drum.getElement(i));
		}

		// Animatie benzi intermitente
		for (unsigned int j = 0; j < strips.size(); j++) {
			// calculez noua pozitie
			float px, py, pz;
			px = strips[j].getPosition().x;
			py = strips[j].getPosition().y;
			pz = strips[j].getPosition().z;
			if (pz > 330) {
				pz = -970;
			} else {
				pz += car.getSpeed();
			}
			Point3D newPos(px, py, pz);
			strips[j].setPosition(newPos);

			Transform3D::loadIdentityModelMatrix();
			Transform3D::translateMatrix(px, py, pz);
//.........这里部分代码省略.........
开发者ID:alexditu,项目名称:EGC_Tema_2,代码行数:101,代码来源:main.cpp


注:本文中的Road::getElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。