⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shots.cs

📁 Beginning C# Game Programming 的源代码
💻 CS
字号:
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;


	/// <summary>
	///  Handles the collision detection and returns the array of shots for sending to other players 
	/// </summary>
[Serializable]
public class Shots
{

	Photon[] shots;
	[NonSerialized]	
	float timeSinceShot = 0;
	[NonSerialized]	
	Rectangle screenBounds;	
		

	public Shots(Device device)
	{
		shots = new Photon[Constants.NumShots];
		for (int count = 0; count < Constants.NumShots; count++)
		{
			shots[count] = new Photon(device);
		}
	}

	public Rectangle ScreenBounds
	{
		get
		{
			return screenBounds;
		}
		set
		{
			screenBounds = value;
		}
	}
	public Photon[] GetShotArray()
	{
		lock(this)
		{
			return shots;
		}
	}

	public void SetShotArray(Photon[] shotArray)
	{
		lock(this)
		{
			this.shots = shotArray;
		}
	}

	public bool Shoot(Vector3 position, Vector3 launchVector)
	{
		if (timeSinceShot < Constants.ShotDeltaTime)
			return false;

		timeSinceShot = 0;


		foreach (Photon shot in shots)
		{
			if (!shot.Alive)
			{
				shot.SetShot(position, launchVector);
				return true;
			}
		}
		return false;
	}

	public void UpdatePosition(float elapsedTime)
	{
		timeSinceShot += elapsedTime;

		foreach (Photon shot in shots)
		{
			shot.UpdatePosition(elapsedTime);
		}
	}

	public void Clear()
	{
		foreach (Photon shot in shots)
		{
			shot.Alive = false;
		}
	}
	public bool TestShots(Ship ship)
	{
		foreach (Photon shot in shots)
		{
			if (shot.Alive)
			{
				float distance = Vector3.Length(shot.Location - ship.Position.Location);
				if (distance < Constants.ShotCollisionLimit)
				{
					shot.Alive = false;
					return true;
				}
			}
		}
		return false;
	}

	public void Render()
	{
		foreach (Photon shot in shots)
		{
			shot.Render();
		}
	}

	public void RestoreDeviceObjects()
	{
		foreach (Photon shot in shots)
		{
			shot.RestoreDeviceObjects();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -