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


C++ Sprite::GetPosX方法代码示例

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


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

示例1: Shoot

//
// Shoot
//
void Game::Shoot()
{
	static Uint32 lShot = SDL_GetTicks() - RELOAD_TIME;
	static list<SprDraw> killableSprites;
	static list<SprDraw>::iterator ksIt;
	static float distance, a, b, c, d;

	if(SDL_GetTicks() - lShot > RELOAD_TIME)
	{
		list<Sprite *>::iterator it;
		Sprite *spr;

		if(player->GetWeapon() == 0)
		{
			player->DecrementAmmo(1);
			if(player->GetAmmo() == 0)
			{
				AddMessage("Out of ammo!");
				return;
			}
		}
		else if(player->GetWeapon() == 1)
		{
			player->DecrementMGAmmo(1);
			if(player->GetMGAmmo() == 0)
			{
				AddMessage("Out of ammo!");
				return;
			}
		}



		fireStart = SDL_GetTicks();
		fireVisible = true;

		if(player->GetWeapon()==0)
			framework->PlaySound(shootSnd);
		else if(player->GetWeapon()==1)
			framework->PlaySound(MGshootSnd);

		for(it = sprites.begin(); it != sprites.end(); it++)
		{
			spr = *it;
			if(spr->GetLookingAt() && spr->GetId() == ET_FURBY)
			{
				SprDraw ks;
				ks.original = spr;
				ks.x = spr->GetPosX();
				ks.y = spr->GetPosY();
				ks.image = spr->GetImage();
				a = raycaster->GetPosX() - ks.x;
				b = raycaster->GetPosY() - ks.y;
				distance = sqrt(a*a+b*b);
				ks.distance = distance;
				killableSprites.push_back(ks);
			}

			if(spr->GetLookingAt() && spr->GetId() == ET_SKULL)
			{
				SprDraw ks;
				ks.original = spr;
				ks.x = spr->GetPosX();
				ks.y = spr->GetPosY();
				ks.image = spr->GetImage();
				c = raycaster->GetPosX() - ks.x;
				d = raycaster->GetPosY() - ks.y;
				distance = sqrt(a*a+b*b);
				ks.distance = distance;
				killableSprites.push_back(ks);
			}
		}



		if(!killableSprites.empty())
		{
			killableSprites.sort();
			killableSprites.reverse();

			ksIt = killableSprites.begin();

			Furby *thisFurby = (Furby *)(*ksIt).original;
		    Skull *thisSkull = (Skull*)(*ksIt).original;

			if(!thisFurby->IsDead()&&thisFurby->GetId()==ET_FURBY)
			{
				thisFurby->NextImage();
				framework->PlaySound(EnemyHurt);
			}
			else if(thisFurby->IsDead() && thisFurby->GetId()==ET_FURBY)
			{
				SDL_Surface *daFrames[NUM_DEATH_ANIM_FRAMES];

				daFrames[0] = spriteImgs[11];
				daFrames[1] = spriteImgs[12];
				daFrames[2] = spriteImgs[13];
//.........这里部分代码省略.........
开发者ID:richi902,项目名称:FurbyKill-3D,代码行数:101,代码来源:lin32_Game.cpp

示例2: DrawSprites

//
// DrawSprites
//
// Note: My version of the calculations for the sprite distance and x-coord using only trigonometric functions
// was giving pretty ugly results. Of course it was working, but in small rooms you could see some wrong clipping
// and other messy things. Therefore I replaced these calculations by others using vectors and matrizes in order
// to get the right values for the x-coord of the projected sprite and the distance for correct clipping. And
// I have to say that this solution is very much based on what Lode Vandevenne explains in his raycasting tutorial.
//
void Raycaster::DrawSprites()
{
	static SDL_Rect sprRect;
	
	int i, j, startX, startY;
	float distance, height;
	float a, b;
	
	list<Sprite *>::iterator sprIt;
	list<SprDraw>::iterator it;
	SprDraw curSpr;
	Sprite *anotherSpr;
	Uint32 color;
	bool partlyDrawn = false;
	
	float sprX, sprY;
	float yStepWidth, xStepWidth;
	
	//float beta;
	float inverse, transX, transY;
	
	// Put sprites into list for sorting
	for(sprIt = sprites->begin(); sprIt != sprites->end(); sprIt++)
	{
		anotherSpr = (*sprIt);
		
		SprDraw spr;
		
		spr.x = anotherSpr->GetPosX();
		spr.y = anotherSpr->GetPosY();
		
		spr.original = anotherSpr;
		
		a = spr.x - posX;
		b = spr.y - posY;
		
		distance = sqrt(a*a+b*b);
		
		spr.image = anotherSpr->GetImage();
		
		spr.distance = distance;
		
		sprsToDraw.push_back(spr);
	}
	
	// Sort from far away to near
	sprsToDraw.sort();
	
	// Draw them from the back
	for(it = sprsToDraw.begin(); it != sprsToDraw.end(); it++)
	{
		// Draw sprite
		curSpr = *it;
		
		a = curSpr.x - posX;
		b = curSpr.y - posY;
		
		inverse = 1.0f / (camPlane.x * lookDir.y - lookDir.x * camPlane.y);
		transX = inverse * (lookDir.y * a - lookDir.x * b);
		transY = inverse * (-camPlane.y * a + camPlane.x * b);
		
		height = DistToWallHeight(transY) * 1.0f;
		
		startX = (int)(-height / 2 + (target->w / 2) * (1 + transX / transY));
		
		startY = (target->h - (int)height) / 2;
		
		sprX = sprY = 0;
		
		xStepWidth = (float)SPRITE_WIDTH / (float)height;
		yStepWidth = (float)SPRITE_HEIGHT / (float)height;
		
		if(startX + height < 0 || startX >= target->w || curSpr.distance < SPR_NEAR_CLIP_DIST)
			continue;
		
		partlyDrawn = false;
		
		// Horizontal
		for(i=0; i<height; i++)
		{											
			if(startX + i < 0 || startX + i >= target->w || transY > zBuffer[i+startX])
			{
				sprX += xStepWidth;
				continue;
			}
			
			// Vertical
			for(j=0; j<height; j++)
			{
				if(!badQuality || j % 4 == 0)
					color = framework->GetPixelColor(curSpr.image, (int)sprX, (int)sprY);
//.........这里部分代码省略.........
开发者ID:richi902,项目名称:FurbyKill-3D,代码行数:101,代码来源:Raycaster.cpp


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