Esempio n. 1
0
		/// <summary>
		/// Create a new MouseHandler for the given target.
		/// </summary>
		/// <param name="target">Target.</param>
		public MouseHandler (GameObject target)
		{
			_target = target;
			_game = _target.game;
			_game.OnAfterStep += HandleOnStep;
			_lastX = Input.mouseX;
			_lastY = Input.mouseY;
		}
Esempio n. 2
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        Remove()
 //------------------------------------------------------------------------------------------------------------------------
 public void Remove(GameObject gameObject)
 {
     colliderList.Remove (gameObject);
     if (_collisionReferences.ContainsKey (gameObject)) {
         ColliderInfo colliderInfo = _collisionReferences [gameObject];
         activeColliderList.Remove (colliderInfo);
         _collisionReferences.Remove (gameObject);
     }
 }
Esempio n. 3
0
		//------------------------------------------------------------------------------------------------------------------------
		//												 GetCurrentCollisions()
		//------------------------------------------------------------------------------------------------------------------------
		public GameObject[] GetCurrentCollisions (GameObject gameObject)
		{
			List<GameObject> list = new List<GameObject>();
			for (int j=colliderList.Count-1; j>=0; j--) {
				if (j >= colliderList.Count) continue; //fix for removal in loop
				GameObject other = colliderList[j];
				if (gameObject != other) {
					if (gameObject.HitTest(other)) {
						list.Add(other);
					}
				}
			}
			return list.ToArray();
		}
Esempio n. 4
0
 public DebugMouseEvent(GameObject gameObject)
 {
     _gameObject = gameObject;
     _ballHandler = new MouseHandler(_gameObject);
     _ballHandler.OnMouseClick += OnMouseEvent;
     _ballHandler.OnMouseDown += OnMouseEvent;
     _ballHandler.OnMouseDownOnTarget += OnMouseEvent;
     //_ballHandler.OnMouseMove += OnMouseEvent;
     //_ballHandler.OnMouseMoveOnTarget += OnMouseEvent;
     _ballHandler.OnMouseOffTarget += OnMouseEvent;
     _ballHandler.OnMouseOverTarget += OnMouseEvent;
     _ballHandler.OnMouseUp += OnMouseEvent;
     _ballHandler.OnMouseUpOnTarget += OnMouseEvent;
 }
Esempio n. 5
0
        /// <summary>
        /// responds to a collision when it's encountered
        /// </summary>
        /// <returns><c>true</c>, If player should be allowed through, <c>false</c> otherwise.</returns>
        /// <param name="other">Other.</param>
        /// <param name="moveX">Move x.</param>
        /// <param name="moveY">Move y.</param>
        bool handleCollision(GameObject other, float moveX, float moveY)
        {
            if (other is Tile) {
                Tile tile = other as Tile;

                if (tile.currentFrame == 2) {
                    //Slightly darken ground tiles you touch
                    tile.SetColor (0.9f,0.9f,0.9f);

                    //Slightly force the tile downward
                    if(moveY >= 16)
                    tile.y += 3;

                    return resolveCollision (other as Sprite, moveX, moveY);
                }
            }
            return true;
        }
Esempio n. 6
0
        /// <summary>
        /// This draws the highscore and adds it as a child of the gameobject it is called from
        /// </summary>
        /// <param name="pSize">
        /// The pSize represents the size of the drawn highscorelist,
        /// With a value between 1 and 20.
        /// </param>
        public void DrawHighScore(float pSize, GameObject pParent)
        {
            if (pSize < 1) { pSize = 1; }
            if (pSize > 20) { pSize = 20; }

            Canvas highscorecv = new Canvas(1028, (int)pSize * 30);
            pParent.AddChild(highscorecv);

            Font font = new Font("Arial", pSize, FontStyle.Regular);
            Brush brush = new SolidBrush(Color.White);

            int placementValue = 0;
            for (int i = 9; i >= 0; i--)
            {
                placementValue++;
                PointF posI = new PointF(0, placementValue * pSize * 2);
                string message = _highScoreNames[i] + " " + _highScores[i];
                highscorecv.graphics.DrawString(message, font, brush, posI);
            }
        }
Esempio n. 7
0
		//------------------------------------------------------------------------------------------------------------------------
		//														Add()
		//------------------------------------------------------------------------------------------------------------------------
		public void Add(GameObject gameObject) {
			if (gameObject.collider != null && !colliderList.Contains (gameObject)) {
				colliderList.Add(gameObject);
			}

			MethodInfo info = gameObject.GetType().GetMethod("OnCollision", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

			if (info != null) {

				CollisionDelegate onCollision = (CollisionDelegate)Delegate.CreateDelegate(typeof(CollisionDelegate), gameObject, info, false);
				if (onCollision != null && !_collisionReferences.ContainsKey (gameObject)) {
					ColliderInfo colliderInfo = new ColliderInfo(gameObject, onCollision);
					_collisionReferences[gameObject] = colliderInfo;
					activeColliderList.Add(colliderInfo);
				}

			} else {
				validateCase(gameObject);
			}
		}
Esempio n. 8
0
		//------------------------------------------------------------------------------------------------------------------------
		//														GetGameObjectCollisions()
		//------------------------------------------------------------------------------------------------------------------------
		internal GameObject[] GetGameObjectCollisions (GameObject gameObject)
		{
			return _collisionManager.GetCurrentCollisions(gameObject);
		}
Esempio n. 9
0
		//------------------------------------------------------------------------------------------------------------------------
		//														Contains()
		//------------------------------------------------------------------------------------------------------------------------
		public Boolean Contains(GameObject gameObject) {
			return _gameObjectsContained.Contains(gameObject);
		}
Esempio n. 10
0
		//------------------------------------------------------------------------------------------------------------------------
		//														Remove()
		//------------------------------------------------------------------------------------------------------------------------
		internal void Remove (GameObject gameObject)
		{
			if (_gameObjectsContained.Contains (gameObject)) {
				_updateManager.Remove (gameObject);
				_collisionManager.Remove (gameObject);
				_gameObjectsContained.Remove (gameObject);
			}
		}
Esempio n. 11
0
		private void onMouseUpHandler (GameObject target , MouseEventType type) {
			OnMouseUp -= onMouseUpHandler;
			OnMouseMove -= onMouseMoveHandler;
		}
Esempio n. 12
0
		//------------------------------------------------------------------------------------------------------------------------
		//														addChild()
		//------------------------------------------------------------------------------------------------------------------------
		private void addChild(GameObject child) {
			if (child.HasChild(this)) return; //no recursive adding
			_children.Add(child);
			return;
		}
Esempio n. 13
0
		//------------------------------------------------------------------------------------------------------------------------
		//														RemoveChild()
		//------------------------------------------------------------------------------------------------------------------------
		/// <summary>
		/// Removes the specified child GameObject from this object.
		/// </summary>
		/// <param name='child'>
		/// Child object to remove.
		/// </param>
		public void RemoveChild (GameObject child)
		{
			if (child.parent == this) {
				child.parent = null;
			}
		}
Esempio n. 14
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        validateCase()
 //------------------------------------------------------------------------------------------------------------------------
 private void validateCase(GameObject gameObject)
 {
     MethodInfo info = gameObject.GetType ().GetMethod ("OnCollision", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
     if (info != null) {
         throw new Exception ("'OnCollision' function was not binded. Please check it's correct case (capital O?)");
     }
 }
Esempio n. 15
0
		private void onTargetMouseDownHandler (GameObject target, MouseEventType type) {
			OnMouseMove += onMouseMoveHandler;
			OnMouseUp += onMouseUpHandler;
		}
Esempio n. 16
0
        void OnCollision(GameObject other)
        {
            if (other.y - 32 < y)
            {
                _position.y = other.y - 32;
                _velocity.y = 0;
                onGround = true;

            }
        }
Esempio n. 17
0
		public DragHandler (GameObject target):base (target)
		{
			OnMouseDownOnTarget+= onTargetMouseDownHandler;
		}
Esempio n. 18
0
        private void OnMouseEvent(GameObject target,MouseEventType type)
        {
            Console.WriteLine("Event: " + type + " triggered on " + target);

        }
Esempio n. 19
0
		//------------------------------------------------------------------------------------------------------------------------
		//														AddChild()
		//------------------------------------------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the specified GameObject as a child to this one.
		/// </summary>
		/// <param name='child'>
		/// Child object to add.
		/// </param>
		public void AddChild(GameObject child) {
			child.parent = this;	
		}
Esempio n. 20
0
 //------------------------------------------------------------------------------------------------------------------------
 //                                                        ColliderInfo()
 //------------------------------------------------------------------------------------------------------------------------
 public ColliderInfo(GameObject gameObject, CollisionDelegate onCollision)
 {
     this.gameObject = gameObject;
     this.onCollision = onCollision;
 }
Esempio n. 21
0
		//------------------------------------------------------------------------------------------------------------------------
		//														removeChild()
		//------------------------------------------------------------------------------------------------------------------------
		private void removeChild(GameObject child) {
			_children.Remove(child);

		}
Esempio n. 22
0
		//------------------------------------------------------------------------------------------------------------------------
		//														SetChildIndex()
		//------------------------------------------------------------------------------------------------------------------------
		/// <summary>
		/// Inserts the specified object in this object's child list at given location.
		/// This will alter the position of other objects as well.
		/// You can use this to determine the layer order (z-order) of child objects.
		/// </summary>
		/// <param name='child'>
		/// Child.
		/// </param>
		/// <param name='index'>
		/// Index.
		/// </param>
		public void SetChildIndex(GameObject child, int index) {
			if (child.parent != this) AddChild(child);
			if (index < 0) index = 0;
			if (index >= _children.Count) index = _children.Count - 1;
			_children.Remove(child);
			_children.Insert(index, child);
		}
Esempio n. 23
0
		//------------------------------------------------------------------------------------------------------------------------
		//														HasChild()
		//------------------------------------------------------------------------------------------------------------------------
		/// <summary>
		/// Returns 'true' if the specified object is a child of this object.
		/// </summary>
		/// <param name='gameObject'>
		/// The GameObject that should be tested.
		/// </param>
		public bool HasChild(GameObject gameObject) {
			GameObject par = gameObject;
			while (par != null) {
				if (par == this) return true;
				par = par.parent;
			}
			return false;
		}
Esempio n. 24
0
		private void onMouseMoveHandler (GameObject target, MouseEventType type) {
			target.x = Input.mouseX + offsetToTarget.x;
			target.y = Input.mouseY + offsetToTarget.y;
		}
Esempio n. 25
0
		//------------------------------------------------------------------------------------------------------------------------
		//														HitTest()
		//------------------------------------------------------------------------------------------------------------------------
		/// <summary>
		/// Tests if this object overlaps the one specified. 
		/// </summary>
		/// <returns>
		/// <c>true</c>, if test was hit, <c>false</c> otherwise.
		/// </returns>
		/// <param name='other'>
		/// Other.
		/// </param>
		virtual public bool HitTest(GameObject other) {
			return _collider != null && other._collider != null && _collider.HitTest (other._collider);
		}
Esempio n. 26
0
		//------------------------------------------------------------------------------------------------------------------------
		//														Add()
		//------------------------------------------------------------------------------------------------------------------------
		internal void Add (GameObject gameObject)
		{
			if (!_gameObjectsContained.Contains (gameObject)) {
				_updateManager.Add (gameObject);
				_collisionManager.Add (gameObject);
				_gameObjectsContained.Add (gameObject);
			}
		}