Example #1
0
void CLaser::Fire()
{
	//Get matrix for current player location and forward vector
	tlx::CMatrix4x4 matrix;
	GetParent()->GetMatrix(matrix.m);

	//Create forward vector (z axis)
	CVector3 direction(matrix.m[8], matrix.m[9], matrix.m[10]);

	//Get position from matrix
	//Since we've already got the matrix it's slightly more efficient than calling GetParent()->GetCenterPoint()
	CVector3 pos(matrix.m[12], OFF_SCREEN_Y, matrix.m[14]);

	//Calculate the rotation of the parent entity, just so it only needs to be calculated once
	float rotation = GetParent()->GetRotation();

	//Makes the space between invisible bullets 2.0f instead of 1.0f
	direction *= 2.0f;

	for (int i = 0; i < 70; i++)
	{
		CProjectile* bullet = new CProjectile();

		bullet->SetPosition(pos);
		bullet->SetRotation(rotation);

		bullet->SetDamage(GetDamage());
		bullet->SetSpeed(GetProjSpeed());
		bullet->SetParent(GetParent());
		bullet->SetExplodeable(false);

		GetBulletList()->push_back(unique_ptr<CProjectile>(bullet));

		//Increment position of next bullet
		pos += direction;
	}

}