コード例 #1
0
ファイル: GamePad.cs プロジェクト: adison/Tank-Wars
			internal void TouchesMoved( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, iOSGameView view)
			{
				UITouch []touchesArray = touches.ToArray<UITouch>();
				foreach(UITouch touch in touchesArray)
				{
					var point = touch.LocationInView(touch.View);
					Vector2 location = new Vector2(point.X, point.Y);
					location = view.GetOffsetPosition(location, true);
					
					var oldItem = GetTouchesObject(touch);
					// Check if touch any button
					bool hitInButton = false;
					if (Visible)
					{
						if(oldItem != null && oldItem is ButtonDefinition)
						{
							hitInButton |= UpdateButton((ButtonDefinition)oldItem,location);
						}
						if(!hitInButton)
							foreach(ButtonDefinition button in _buttonsDefinitions)
							{
								hitInButton |= UpdateButton (button, location);
								if(hitInButton)
								{
									UpdateTouch(touch,button);
									continue;
								}
							}
					}
					
					if (!hitInButton) 
					{
						if(oldItem != null && oldItem == _leftThumbDefinition)
						{						
							Vector2 movement = location - LeftThumbStickDefinition.InitialHit;
							if(movement.X > 20)
								movement.X = 20;
							else if(movement.X < -20)
								movement.X = -20;
							
							if(movement.Y > 20)
								movement.Y = 20;
							else if(movement.Y < -20)
								movement.Y = -20;
							_leftThumbDefinition.Offset = movement;
							_leftStick = new Vector2(movement.X / 20,movement.Y / -20);
						}										
						else if (Visible && (_leftThumbDefinition != null) && (CheckThumbStickHit(_leftThumbDefinition,location)))
						{
							Vector2 movement = location - LeftThumbStickDefinition.InitialHit;
								
							UpdateTouch(touch,_leftThumbDefinition);
							LeftThumbStickDefinition.InitialHit = location;
							
							// Keep the stick in the "hole" 
							float radius = (movement.X*movement.X) + (movement.Y*movement.Y);
							
						if (radius <= _thumbStickRadius) 
							{
								_leftThumbDefinition.Offset = movement;
								_leftStick = new Vector2(movement.X / 20,movement.Y / -20);
							}												
						}
						else 
						{
							// reset left thumbstick
							if (_leftThumbDefinition != null) 
							{
								_leftThumbDefinition.Offset = Vector2.Zero;
								_leftStick = Vector2.Zero;
							}
							
											
							if(oldItem != null && oldItem == _rightThumbDefinition)
							{
								Vector2 movement = location - _rightThumbDefinition.InitialHit;
								_rightThumbDefinition.Offset = movement;
								_rightStick = new Vector2(movement.X / 20,movement.Y / -20);
							}										
							else if (Visible && (_rightThumbDefinition != null) && (CheckThumbStickHit(_rightThumbDefinition,location)))
							{
								Vector2 movement = location - _rightThumbDefinition.InitialHit;
								
								// Keep the stick in the "hole" 
								float radius = (movement.X*movement.X) + (movement.Y*movement.Y);
								if (radius <= _thumbStickRadius) 
								{
									_rightThumbDefinition.Offset = movement;
									_rightStick = new Vector2(movement.X / 20,movement.Y / -20);
								}												
							}
							else 
							{
								// reset right thumbstick
								if (_rightThumbDefinition != null) 
								{
									_rightThumbDefinition.Offset = Vector2.Zero;
									_rightStick = Vector2.Zero;
								}
								
								// Handle the mouse
								Mouse.State.X = (int) location.X;
								Mouse.State.Y = (int) location.Y;
							}
						}
					}
				}	
			}
コード例 #2
0
ファイル: GamePad.cs プロジェクト: adison/Tank-Wars
			internal void TouchesEnded( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, iOSGameView view)
			{						
				UITouch []touchesArray = touches.ToArray<UITouch>();
				foreach(UITouch touch in touchesArray)
				{
					var point = touch.LocationInView(touch.View);
					Vector2 location = new Vector2(point.X, point.Y);
					location = view.GetOffsetPosition(location, true);

					// Check where is the touch
					if (Visible)
					{
						var oldItem = GetTouchesObject(touch);
						if(oldItem == null)
							continue;
						if(oldItem is ButtonDefinition)
						{
							ButtonDefinition button = (ButtonDefinition)oldItem;
							if  (CheckButtonHit(button, location)) 
							{
								_buttons &= ~(int)button.Type;
							}
						}
						else if(oldItem  == _leftThumbDefinition)
						{
							LeftThumbStickDefinition.Offset = Vector2.Zero;
							_leftStick = Vector2.Zero;
						}
						else if(oldItem == _rightThumbDefinition)
						{
							_rightThumbDefinition.Offset = Vector2.Zero;
							_rightStick = Vector2.Zero;
						}
						RemoveTouch(touch);
					}
				}	
				Reset();
				
			}	
コード例 #3
0
ファイル: GamePad.cs プロジェクト: adison/Tank-Wars
			internal void TouchesBegan( MonoTouch.Foundation.NSSet touches, MonoTouch.UIKit.UIEvent e, iOSGameView view)
			{
				// Reset State		
				//Reset();
				
				// Check where is the touch
				UITouch []touchesArray = touches.ToArray<UITouch>();
				foreach(UITouch touch in touchesArray)
				{
					var point = touch.LocationInView(touch.View);
					Vector2 location = new Vector2(point.X, point.Y);
					location = view.GetOffsetPosition(location, true);

					// Check where is the touch
					bool hitInButton = false;
					
					if (Visible) 
					{
						foreach(ButtonDefinition button in _buttonsDefinitions)
						{
							hitInButton |= UpdateButton (button, location);	
							UpdateTouch(touch,button);
						}
					}
					if (!hitInButton)
					{
						// check the left thumbstick
						if (Visible &&  (_leftThumbDefinition != null) && (CheckThumbStickHit(_leftThumbDefinition,location)))
						{
							_leftThumbDefinition.InitialHit = location;	
							UpdateTouch(touch,_leftThumbDefinition);
						}
						else 
						{
							// check the right thumbstick
							if (Visible && (_rightThumbDefinition != null) && (CheckThumbStickHit(_rightThumbDefinition,location)))
							{
								_rightThumbDefinition.InitialHit = location;
								UpdateTouch(touch,_rightThumbDefinition);
							}
							else // Handle mouse 
							{
								Mouse.State.X = (int) location.X;
								Mouse.State.Y = (int) location.Y;
							}
						}
						
					}
				}
			}