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

📄 gameinput.cs

📁 Game Engine Desing Direct X and C#.rar
💻 CS
📖 第 1 页 / 共 2 页
字号:
					}
				}

				// only process the action map if the console is not visible
				if ( !GameEngine.Console.IsVisible )
				{
					foreach ( Mapping map in m_ActionMap ) 
					{
						// if this is against the keyboard
						if ( map.key < 256 ) 
						{
							if ( m_keydata[(Key)map.key]  ) 
							{
								if ( !map.bOnTransition || oldkeydata[(Key)map.key]  ) 
								{
									map.action();
								}
							}
						} 
						else if ( map.key < 264 )  // space for 8 mouse buttons
						{
							if ( (m_mousedata.GetMouseButtons()[map.key-256] & 0x80) != 0 ) 
							{
								if ( !map.bOnTransition || (oldmousedata.GetMouseButtons()[map.key-256] & 0x80) == 0 ) 
								{
									map.action();
								}
							}
						}
						else  // joystick buttons
						{
							if ( (m_joystick.GetButtons()[map.key-264] & 0x80) != 0 ) 
							{
								if ( !map.bOnTransition || (oldjoystickdata.GetButtons()[map.key-264] & 0x80) == 0 ) 
								{
									map.action();
								}
							}
						}
					}
				}
			}
			catch {}
		}

		public bool IsMouseButtonDown( int nButton )
		{
			return (m_mousedata.GetMouseButtons()[nButton] & 0x80) != 0;
		}

		// Check if any buttons were pressed
		public bool IsKeyPressed()
		{
			bool bPressed = false;

///TODO			foreach ( byte b in m_keydata ) 
//			{
//				if ( (b & 0x80) > 0 ) bPressed = true;
//			}
			return bPressed;
		}

		// Check if any buttons were pressed
		public bool IsKeyPressed(Key key)
		{
			bool bPressed = false;
			try 
			{
				bPressed = m_keydata[key] ;
			}
			catch
			{
			}

			return bPressed;
		}

		// method to map a key to an action
		public void MapKeyboardAction( Key key, ButtonAction proc, bool bTransition )
		{
			Mapping map = new Mapping();
			map.key = (int)key;
			map.action = proc;
			map.bOnTransition = bTransition;
			m_ActionMap.Add(map);
		}

		// method to map a mouse button to an action
		public void MapMouseButtonAction( int nButton, ButtonAction proc, bool bTransition )
		{
			Mapping map = new Mapping();
			map.key = nButton + 256;
			map.action = proc;
			map.bOnTransition = bTransition;
			m_ActionMap.Add(map);
		}

		// method to map a joystick button to an action
		public void MapJoystickButtonAction( int nButton, ButtonAction proc, bool bTransition )
		{
			Mapping map = new Mapping();
			map.key = nButton + 264;
			map.action = proc;
			map.bOnTransition = bTransition;
			m_ActionMap.Add(map);
		}

		// method to map a mouse axis to an action
		public void MapMouseAxisAction( int nAxis, AxisAction proc )
		{
			AxisMapping map = new AxisMapping();
			map.key = nAxis;
			map.action = proc;
			m_AxisActionMap.Add(map);
		}

		// method to map a joystick axis to an action
		public void MapJoystickAxisAction( int nAxis, AxisAction proc )
		{
			AxisMapping map = new AxisMapping();
			map.key = nAxis + 3;
			map.action = proc;
			m_AxisActionMap.Add(map);
		}

		public void UnMapKeyboardAction( Key key )
		{
			foreach ( Mapping map in m_ActionMap ) 
			{
				if ( map.key == (int)key ) 
				{
					m_ActionMap.Remove(map);
				}
			}
		}

		public void UnMapMouseButtonAction( int nButton )
		{
			foreach ( Mapping map in m_ActionMap ) 
			{
				if ( map.key == (nButton + 256) ) 
				{
					m_ActionMap.Remove(map);
				}
			}
		}

		public void UnMapMouseAxisAction( int nAxis )
		{
			foreach ( AxisMapping map in m_AxisActionMap ) 
			{
				if ( map.key == nAxis ) 
				{
					m_AxisActionMap.Remove(map);
				}
			}
		}

		public void UnMapJoystickButtonAction( int nButton )
		{
			foreach ( Mapping map in m_ActionMap ) 
			{
				if ( map.key == (nButton + 264) ) 
				{
					m_ActionMap.Remove(map);
				}
			}
		}

		public void UnMapJoystickAxisAction( int nAxis )
		{
			foreach ( AxisMapping map in m_AxisActionMap ) 
			{
				if ( map.key == (nAxis+3) ) 
				{
					m_AxisActionMap.Remove(map);
				}
			}
		}

		public void ClearActionMaps()
		{
			m_ActionMap.Clear();
			m_AxisActionMap.Clear();
		}


		/// <summary>
		/// Get the current mouse X value
		/// </summary>
		public int GetMouseX()
		{
			int nResult = m_MouseX;

			m_MouseX = 0;
			return nResult;
		}

		/// <summary>
		/// Get the current mouse Y value
		/// </summary>
		public int GetMouseY()
		{
			int nResult = m_MouseY;

			m_MouseY = 0;
			return nResult;
		}

		/// <summary>
		/// Get the current mouse Z value (mouse wheel)
		/// </summary>
		public int GetMouseZ()
		{
			int nResult = m_MouseZ;

			m_MouseZ = 0;
			return nResult;
		}

		/// <summary>
		/// Get joystick axis data
		/// </summary>
		public int GetJoystickX( )
		{
			if ( m_bJoystickSet ) 
			{
				return m_joystick.X;
			} 
			else 
			{
				return 0;
			}
		}

		/// <summary>
		/// Get normalized joystick axis data
		/// </summary>
		public float GetJoystickNormalX( )
		{
			if ( m_bJoystickSet ) 
			{
				return (float)m_joystick.X/(float)short.MaxValue;
			} 
			else 
			{
				return 0;
			}
		}

		/// <summary>
		/// Get joystick axis data
		/// </summary>
		public int GetJoystickY( )
		{
			if ( m_bJoystickSet ) 
			{
				return m_joystick.Y;
			} 
			else 
			{
				return 0;
			}
		}

		/// <summary>
		/// Get normalized joystick axis data
		/// </summary>
		public float GetJoystickNormalY( )
		{
			if ( m_bJoystickSet ) 
			{
				return (float)m_joystick.Y/(float)short.MaxValue;
			} 
			else 
			{
				return 0;
			}
		}

		/// <summary>
		/// Get joystick axis data
		/// </summary>
		public int GetJoystickZ( )
		{
			if ( m_bJoystickSet ) 
			{
				return m_joystick.Z;
			} 
			else 
			{
				return 0;
			}
		}

		/// <summary>
		/// Get joystick button data
		/// </summary>
		public bool GetJoystickButton( int nIndex )
		{
			if ( m_bJoystickSet && nIndex < 32 ) 
			{
				return m_joystick.GetButtons()[nIndex] != 0;
			} 
			else 
			{
				return false;
			}
		}

		/// <summary>
		/// Get joystick slider data
		/// </summary>
		public int GetJoystickSlider( int nIndex )
		{
			if ( m_bJoystickSet && nIndex < 2 ) 
			{
				return m_joystick.GetSlider()[nIndex];
			} 
			else 
			{
				return 0;
			}
		}

		//Dispose method
		public void Dispose()
		{
			KeyboardDev.Unacquire();
			KeyboardDev.Dispose();
			MouseDev.Unacquire();
			MouseDev.Dispose();
			if ( m_bJoystickSet ) 
			{
				JoystickDev.Unacquire();
				JoystickDev.Dispose();
			}
		}

	}
}

⌨️ 快捷键说明

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