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

📄 gamesettings.cs

📁 这是网上下载的很好的串口发短信的程序! 是用VC++来做的
💻 CS
字号:
using System;
using System.Reflection;
using System.IO;
using System.Collections;
using System.Drawing;
using DDGameHelper;
using Microsoft.DirectX.DirectDraw;
using Microsoft.DirectX.DirectInput;

namespace ddt2
{
	/// <summary>
	/// GameSettings 的摘要说明。
	/// </summary>
	public class GameSettings
	{
		public static int _screenWidth = 640;
		public static int _screenHeight = 480;

		public static void GameLoopSetAndStart(ref GameLoopHandler gl)
		{
			GameMain g=new GameMain(ref gl);
			gl.IsSpeedLimitMode=false;

			gl.On_Loop_Form_GetFocus+=new On_Loop_Form_GetFocus(g.gl_On_Loop_Form_GetFocus);
			gl.On_Loop_Form_LostFocus+=new On_Loop_Form_LostFocus(g.gl_On_Loop_Form_LostFocus);
			gl.On_Loop_Form_Paint+=new On_Loop_Form_Paint(g.gl_On_Loop_Form_Paint);

			gl.On_Loop_Before+=new On_Loop_Before(g.gl_On_Loop_Before);
			gl.On_Loop_After+=new On_Loop_After(g.gl_On_Loop_After);
			gl.On_Loop_Progress+=new On_Loop_Progress(g.gl_On_Loop_Progress);
			//gl...xxxx += .........

			gl.Loop();
		}
		public GameSettings()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public static Stream GetResourceStream(string resource)
		{
			return Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
		}
	}

	public class GameMain
	{
		/// <summary>
		/// 公用随机数发生器
		/// </summary>
		protected Random _r;

		/// <summary>
		/// 显示 fps 用的类
		/// </summary>
		protected DDFPSPainter _DDFPSPainter;

//		/// <summary>
//		/// 游戏内用资料库
//		/// </summary>
//		protected NameBmpRectComboCollection _nbrcc;

		/// <summary>
		/// 定位到 GameLoop
		/// </summary>
		protected GameLoopHandler _glh;

		public GameMain(ref GameLoopHandler glh)
		{
			_glh = glh;
			_r=new Random(System.Environment.TickCount);
		}

		public void gl_On_Loop_Before(object sender, EventGameLoopArgs e)
		{
			e.DDHandleR.IsFullScreen=false;			//窗口模式
			_DDFPSPainter=new DDFPSPainter(e.DDHandleR.Device, e.DDHandleR.RenderSurface);	//初始化 FPS 显示

//			double x,y,vx,vy;
//			for(int i=0;i<1;i++)
//			{
//				x=_glh.RandoM.NextDouble()*(GameSettings._screenWidth - 50);
//				y=_glh.RandoM.NextDouble()*(GameSettings._screenHeight - 56);
//				vx=_glh.RandoM.NextDouble()*10+1;
//				vy=_glh.RandoM.NextDouble()*10+1;
//
//				_glh.GameObjectCollection.Add(new GameObject_Player_Plane(x,y,vx,vy,60,ref _glh));
//
//			}
			_glh.GameObjectCollection.Add(new GameObject_Player_Plane(100,100,2,2,60,ref _glh));
		}

		public void gl_On_Loop_After(object sender, EventGameLoopArgs e)
		{

		}

		public void gl_On_Loop_Progress(object sender, EventGameLoopArgs e)
		{
			Microsoft.DirectX.DirectInput.KeyboardState ks=e.DIHandleR.GetKeyboardState();
			if(ks!=null)
			{
				if(ks[Key.Escape])e.OwnerForm.Close();
				for(int i=0;i<_glh.GameObjectCollection.Count;i++)
				{
					GameObject go=(GameObject)_glh.GameObjectCollection[i];
					go.Process(ref ks);
				}
			}

			e.DDHandleR.RenderSurface.ColorFill(Color.Blue);

			for(int i=0;i<_glh.GameObjectCollection.Count;i++)
			{
				GameObject go=(GameObject)_glh.GameObjectCollection[i];
				go.Process();
				go.Draw();
				if(!go.IsAlive)
				{
					if(go.Type() == (int)GameObject_Enum.Sprite)_glh.GameObjectCollection.Add(new GameObject_Blast1(go.XCurrent-11,go.YCurrent-11,0,0,80,ref _glh));
					_glh.GameObjectCollection.RemoveAt(i);
					i--;
				}
			}

			RelXPos relativeXPosition= RelXPos.Unknown;
			RelYPos relativeYPosition= RelYPos.Unknown;
			bool isColl=false;

			if(_glh.GameObjectCollection.Count>1)
			{
				for(int i=0;i<_glh.GameObjectCollection.Count;i++)
				{
					for(int j=i+1;j<_glh.GameObjectCollection.Count;j++)
					{
						string s=_glh.GameObjectCollection[i].GetType().ToString();
						GameObject go1 = (GameObject)_glh.GameObjectCollection[i];
						GameObject go2 = (GameObject)_glh.GameObjectCollection[j];
						if(go1.Type() == (int)GameObject_Enum.Blast1 && go2.Type() == (int)GameObject_Enum.Blast1 || go1.Type() == (int)GameObject_Enum.Player_Plane && go2.Type() == (int)GameObject_Enum.Blast1)
						{

						}
						else
						{
							isColl = CollisionDetection.DoIntersect(go1,go2,Color.FromArgb(255,Color.Black),ref relativeXPosition, ref relativeYPosition);
							if(isColl)
							{
								if(go1.Type() == (int)GameObject_Enum.Sprite && !(bool)go1.Properties())
								{
									go1.IsAlive = false;
								}
								if(go2.Type() == (int)GameObject_Enum.Sprite && !(bool)go2.Properties())
								{
									go2.IsAlive = false;
								}
							}
						}
					}
				}
			}

			_DDFPSPainter.PaintFPS(e.DXTimeR, " rc: "+GameObject.BmpRectComboCollection.Count.ToString() + " oc: " + _glh.GameObjectCollection.Count.ToString() +" " +isColl.ToString()  +" " + relativeXPosition + " " + relativeYPosition);//显示 fps
			e.DDHandleR.Flip();//绘制后台缓冲区图到屏幕
		}


		public void gl_On_Loop_Form_GetFocus(Object sender, EventGameLoopArgs e)
		{
			e.DXTimeR.Timer(TimerCmd.Start);
			e.DDHandleR.Device.RestoreAllSurfaces();
		}

		public void gl_On_Loop_Form_LostFocus(Object sender, EventGameLoopArgs e)
		{
			e.DXTimeR.Timer(TimerCmd.Stop);
		}
		
		public void gl_On_Loop_Form_Paint(Object sender, EventGameLoopArgs e)
		{
			e.DDHandleR.RenderSurface.ColorFill(Color.Blue);

			for(int i=0;i<_glh.GameObjectCollection.Count;i++)
			{
				((GameObject)_glh.GameObjectCollection[i]).Draw();
			}


			_DDFPSPainter.PaintFPS(e.DXTimeR, " rc: "+GameObject.BmpRectComboCollection.Count.ToString() + " oc: " + _glh.GameObjectCollection.Count.ToString());//显示 fps

			//绘制后台缓冲区图到屏幕
			e.DDHandleR.Flip();
		}
	}
}

⌨️ 快捷键说明

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