Exemple #1
0
void Projectile::Update()
{
	++mTicks;
	if( (mPos.x <0) || 
		(mPos.x>960)||
		(mPos.y<0)||
		(mPos.y>540))
	{
		mbIsDead = true;
	}
	

	switch(mpData->GetType())
	{
	case PT_Vector:
	case PT_VectorGrenade:
		mPos = mPos + mVector*mpData->GetSpeed();
		break;
	case PT_Custom:
		break;
	}

	if(PT_VectorGrenade == mpData->GetType())
	{
		if(mTicks>mpData->GetFuse())
		{
			mbIsDead=true;
			for(int it = 0; it<8;++it)
			{
				Projectile *pProjectile = ModContentManager::Instance().SpawnProjectile(mpData->GetShrapnelName());
				Math::Vector2f refPosition = mPos;
				int vec = 0+45*it;
				refPosition += Math::Vector2f::GetVectorFromDeg(vec)*mpData->GetRadius();
				pProjectile->SetPosition(refPosition);
				pProjectile->SetVector(vec);
				pProjectile->SetOwner(GetOwner());
				if(PO_Enemy==GetOwner())
				{
					Game::Instance().QueueProjectile(pProjectile);
				}
				else if(PO_Player==GetOwner())
				{
					Game::Instance().QueueProjectile(pProjectile);
				}
			}
		}
	}

}
Exemple #2
0
void Player::Update()
{
	mPosition += InputManager::Instance().GetDirection()*mSpeed;
	if(mPosition.x<0){mPosition.x = 0;}
	if(mPosition.y<0){mPosition.y = 0;}
	if(mPosition.x>960){mPosition.x = 960;}
	if(mPosition.y>540){mPosition.y = 540;}

	// shoot
	++ticks;
	if(0==(ticks%rateOfFire))
	{
		Projectile *pProjectile = ModContentManager::Instance().SpawnProjectile("player_bullet");
		Math::Vector2f refPosition = mPosition;
		refPosition.x += 32;
		pProjectile->SetPosition(refPosition);
		pProjectile->SetVector(Math::Vector2f(1.f,0.f));
		pProjectile->SetOwner(PO_Player);
		Game::Instance().AddPlayerProjectile(pProjectile);
	}
}