コード例 #1
0
ファイル: Raycaster.cpp プロジェクト: richi902/FurbyKill-3D
//
// CheckCollWithSprite
//
bool Raycaster::CheckCollWithSprite(bool *wasPickup, int *pickupId)
{
	list<Sprite *>::iterator it;
	Sprite *spr;
	
	*wasPickup = false;
	
	for(it = sprites->begin(); it != sprites->end(); it++)
	{
		spr = *it;
		if(spr->PointCollWith(posX, posY) && spr->GetId() != CORPSE_INDEX)
		{		
			if(spr->GetId() >= PICKUP_INDEX && spr->GetId() < ET_SKULL)
			{
				*wasPickup = true;
				*pickupId = spr->GetId();
				delete spr;
				it = sprites->erase(it);
				return false;
			}
			
			return true;
		}
	}
	
	return false;
}
コード例 #2
0
ファイル: lin32_Game.cpp プロジェクト: richi902/FurbyKill-3D
//
// 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];

				DeathAnimation *deathAnim = new DeathAnimation(daFrames, (*ksIt).original->GetPosX(), (*ksIt).original->GetPosY());

				sprites.push_back(deathAnim);

				delete (*ksIt).original;
				sprites.remove((*ksIt).original);

				framework->PlaySound(killSnd);


					AddMessage("You killed a furby!");
			}

			if(!thisSkull->IsDead() && thisSkull->GetId()==ET_SKULL)
			{
				thisSkull->NextImage();
				framework->PlaySound(EnemyHurt);

			}
			else if(thisSkull->IsDead() && thisSkull->GetId()==ET_SKULL)
			{
				SDL_Surface *skdaFrames[NUM_DEATH_ANIM_FRAMES];

				skdaFrames[0] = spriteImgs[17];
				skdaFrames[1] = spriteImgs[18];
				skdaFrames[2] = spriteImgs[19];

				SKDeathAnimation *skdeathAnim = new SKDeathAnimation(skdaFrames, (*ksIt).original->GetPosX(), (*ksIt).original->GetPosY());

				sprites.push_back(skdeathAnim);

				delete (*ksIt).original;
				sprites.remove((*ksIt).original);

				framework->PlaySound(killSnd);

				AddMessage("You killed a skull!");
			}

		//}
		killableSprites.clear();
		}

		lShot = SDL_GetTicks();
	}
}
コード例 #3
0
ファイル: lin32_Game.cpp プロジェクト: richi902/FurbyKill-3D
//
// Update
//
void Game::Update()
{
	list<Sprite *>::iterator it;
	Sprite *curSpr;
	static bool HPwarning = false;
	static int chan = NULL;

	if(showExitConfirm)
		return;

	UpdateMessages();

	if(player->GetWeapon()==0)
		RELOAD_TIME = 650;
	if(player->GetWeapon()==1)
		RELOAD_TIME = 280;

	// Update sprites
	for(it = sprites.begin(); it != sprites.end(); it++)
	{
		curSpr = *it;

		if(curSpr->GetId() == ET_FURBY)
		{
			Furby *fb = (Furby *)curSpr;
			fb->Update(raycaster);

		}
		else if(curSpr->GetId() == SHOT_INDEX)
		{
			Shot *shot = (Shot *)curSpr;
			shot->Update(raycaster);

			if(shot->PointCollWith(raycaster->GetPosX(), raycaster->GetPosY()))
			{
				if(player->GetHealth() != 0)
				{
					framework->PlaySound(PlayerHurt);
				}
			AddMessage("You got hit by a shot from a furby!");
				player->DecrementHealth(10);

				it = sprites.erase(it);

			}
			if(shot->IsVanished())
				it = sprites.erase(it);
		}
		else if(curSpr->GetId() == DEATH_ANIMATION_INDEX)
		{
			DeathAnimation *da = (DeathAnimation *)curSpr;
			da->Update();

			if(da->HasEnded())
			{
				float itsX, itsY;
				itsX = da->GetPosX();
				itsY = da->GetPosY();

				delete da;
				it = sprites.erase(it);


				Sprite *corpse = new Sprite(spriteImgs[2], itsX, itsY, 2);
				sprites.push_back(corpse);
			}
		}

		if(curSpr->GetId() == ET_SKULL)
		{
			Skull *sk = (Skull *)curSpr;
			sk->Update(raycaster);
		}
		else if(curSpr->GetId() == SK_SHOT_INDEX)
		{
			SkullShot *skullshot = (SkullShot *)curSpr;
			skullshot->Update(raycaster);

			if(skullshot->PointCollWith(raycaster->GetPosX(), raycaster->GetPosY()))
			{
				if(player->GetHealth() !=0)
				{
					framework->PlaySound(PlayerHurt);
				}

				AddMessage("You got hit by a shot from a Skull!");
				player->DecrementHealth(20);

				it = sprites.erase(it);
			}
			if(skullshot->IsVanished())
				it = sprites.erase(it);
		}
		else if(curSpr->GetId() == SKDEATH_ANIMATION_INDEX)
		{
			SKDeathAnimation *skda = (SKDeathAnimation *)curSpr;
			skda->Update();

			if(skda->HasEnded())
			{
				float itsX, itsY;
				itsX = skda->GetPosX();
				itsY = skda->GetPosY();

 				delete skda;
				it = sprites.erase(it);

				Sprite *skcorpse = new Sprite(spriteImgs[20], itsX, itsY, 2);
				sprites.push_back(skcorpse);
			}
		}



	}

	if(player->GetHealth() <= 30 && HPwarning == false)
	{
		chan = framework->PlaySound(HeartBeat, -1);
		Mix_Volume(chan, MIX_MAX_VOLUME);
		HPwarning = true;
	}

	if(player->GetHealth() > 30 && HPwarning == true)
	{
			Mix_HaltChannel(chan);
			HPwarning = false;
	}

	if(player->GetHealth() == 0)
	{

		framework->PlaySound(PlayerDead);
		GameOver();
	}

	if(raycaster->MapChangeNeeded())
        NextMap();
}