Esempio n. 1
0
//Updates all the projectile in the clip to meet the guns stats
void Gun::loadNewMag(Magazine* newMag)
{
	mag = newMag;
	isMagInGun = true;
	newMag->setProjectileStats(damage, minRange, maxRange, muzzelVelocity);
	chamberNextProjectile();
}
Esempio n. 2
0
void Gun::multiFire(float frameTime)
{
	int count = frameTime/fireRate.fireTime;
	float recoilTime = frameTime/count;
	if(fireMode != AUTO)//accounts for burst fire
	{
		if(gunState == NONE && count == 0)
		{
			count = 1;
		}
		count = min(burstCount, count);
		burstCount -= count;
	}
	timeSinceLastFired -= fireRate.fireTime*count;
	while(count > 0)
	{
		chamberNextProjectile();
		if(chamberedProjectile != 0)
		{
			float fireAngle = spriteData.angle + spread*PI*(((rand()%1000)-500)/1000.0)/180;
			D3DXVECTOR2 fp(getCenterX() + cos(spriteData.angle)*fireLocation.x - sin(spriteData.angle)*fireLocation.y, getCenterY() + cos(spriteData.angle)*fireLocation.y + sin(spriteData.angle)*fireLocation.x);
			//fire(fp, fireAngle);
			fire(fp + D3DXVECTOR2(((count-1)*fireRate.fireTime*chamberedProjectile->muzzelVelocity)*cos(fireAngle), ((count-1)*fireRate.fireTime*chamberedProjectile->muzzelVelocity)*sin(fireAngle)), fireAngle);
			recoil(recoilTime);
		}
		count--;
	}
}
Esempio n. 3
0
//Places the mag in the gun
void Gun::loadMag()
{
	if(mag != 0)
	{
		isMagInGun = true;
		chamberNextProjectile();
	}
}
Esempio n. 4
0
//Input1 is fire, input2 reload, input3 is for gunMod1, input4 is for gunMod2, input 5 is for gunMod3;
void Gun::act(float frameTime, bool input1, bool input2, bool input3, bool input4, bool input5)
{
	timeSinceLastFired += frameTime;
	if(chamberedProjectile == 0 && timeSinceLastFired > fireRate.fireTime && mag != 0)
	{
		chamberNextProjectile();
	}
	if(chamberedProjectile != 0)
	{
		if(fireMode == AUTO)
		{
			if(input1)
			{
				if(gunState == NONE)
				{
					multiFire(frameTime);
					timeSinceLastFired = 0;
					gunState = FIREING;
				}
				else if(gunState == FIREING)
				{
					multiFire(timeSinceLastFired);
				}
				
			}
			else if(gunState == FIREING)
			{
				gunState = NONE;
			}
		}
		else//For Burst fire weapons
		{
			if(gunState == NONE)
			{
				if(input1)
				{
					burstCount = fireMode;
					multiFire(frameTime);
					timeSinceLastFired = 0;
					gunState = FIREING;
				}
			}
			else if(gunState == FIREING && burstCount > 0)
			{
				multiFire(timeSinceLastFired);
			}
			else if(!input1)
			{
				gunState = NONE;
			}
		}

	}
	else if(!isMagInGun)
	{
		timeSinceLastFired = 0;
	}
}