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


C++ Dot::initialize方法代码示例

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


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

示例1: resetGame

void myGame::resetGame() 
{
	ghosts.clear();
	dots.clear();

	//create patterns
	Pattern* ghostPattern1 = new Pattern(1);

	ghostPattern1->addStep(0, "CAMP", 40, [&] (Entity* e) {

		Ghost* myself = static_cast<Ghost*>(e) ;

		int waypoint = myself->targetWaypoint ;
		VECTOR2 center = *myself->getCenter() ;

		float left_edge = myself->getX();
		float right_edge = myself->getX() + myself->getWidth()*myself->getScale();
		float top_edge = myself->getY();
		float bottom_edge = myself->getY() + myself->getHeight()*myself->getScale();

		VECTOR2 currentWaypoint = waypointSet1[waypoint] ;
		if(	currentWaypoint.x > left_edge && 
			currentWaypoint.x < right_edge &&
			currentWaypoint.y > top_edge &&
			currentWaypoint.y < bottom_edge) 
			myself->targetWaypoint++ ;

		if( myself->targetWaypoint > 3) myself->targetWaypoint = 0 ;

		myself->waypointTrack(waypointSet1[waypoint]);
		myself->vectorTrack(&player, 180);
	}) ;

	Pattern* ghostPattern2 = new Pattern(1);

	ghostPattern2->addStep(0, "CAMP", 40, [&] (Entity* e) {
		Ghost* myself = static_cast<Ghost*>(e) ;

		int waypoint = myself->targetWaypoint ;
		VECTOR2 center = *myself->getCenter() ;

		float left_edge = myself->getX();
		float right_edge = myself->getX() + myself->getWidth()*myself->getScale();
		float top_edge = myself->getY();
		float bottom_edge = myself->getY() + myself->getHeight()*myself->getScale();

		VECTOR2 currentWaypoint = waypointSet2[waypoint] ;
		if(	currentWaypoint.x > left_edge && 
			currentWaypoint.x < right_edge &&
			currentWaypoint.y > top_edge &&
			currentWaypoint.y < bottom_edge) 
			myself->targetWaypoint++ ;

		if( myself->targetWaypoint > 3) myself->targetWaypoint = 0 ;

		myself->waypointTrack(waypointSet2[waypoint]);
		myself->vectorTrack(&player, 180);
	}) ;


	//create entities
	// ghost 1
	Ghost* ghost1 = new Ghost() ;
	if (!ghost1->initialize(this, ghostNS::WIDTH, ghostNS::HEIGHT, 4, &allTM))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ghost entity"));

	ghost1->setX(0);
	ghost1->setY(0);
	ghosts.add(ghost1, new Pattern(ghostPattern1));

	// ghost 2
	Ghost* ghost2 = new Ghost() ;
	if (!ghost2->initialize(this, ghostNS::WIDTH, ghostNS::HEIGHT, 4, &allTM))
		throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ghost entity"));
	
	ghost2->setX(GAME_WIDTH - ghostNS::WIDTH*ghostNS::SCALE);
	ghost2->setY(GAME_HEIGHT - ghostNS::HEIGHT*ghostNS::SCALE);
	ghost2->setCurrentFrame(1);
	ghosts.add(ghost2, new Pattern(ghostPattern2));

	// dots
	rows = 4 ;
	cols = 5 ;
	for(int i = 0; i < rows; ++i)
	{
		for(int j = 0; j < cols; ++j)
		{
			Dot* newDot = new Dot() ;
			if (!newDot->initialize(this, dotNS::WIDTH, dotNS::HEIGHT, 4, &allTM))
				throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing dot entity"));

			newDot->setX( ((GAME_WIDTH/cols)*j) + 50);
			newDot->setY( ((GAME_HEIGHT/rows)*i) + 50);
			newDot->setScale(dotNS::SCALE);

			dots.add(newDot);
		}
	}
	dotsRemaining = rows * cols ;
}
开发者ID:charliemathews,项目名称:pac-man,代码行数:100,代码来源:myGame.cpp


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