Example #1
0
        /// <summary>
        /// Scales the Game Object to match proportions with another.
        /// This is different than ScaleTo as it will make sure both
        /// ZObjectDrawableDrawables have the same width and height in pixels instead of simply matching the scale of both objects.
        /// </summary>
        /// <param name="gobj">The game object with which to match the scale of</param>
        public void RelativeScale(ZObject gobj)
        {
            float hScale = (float)gobj.width / (float)width;
            float vScale = (float)gobj.height / (float)height;

            scale = new Vector2(hScale, vScale);
        }
Example #2
0
        /// <summary>
        /// Move the Game Object away from another
        /// </summary>
        /// <param name="target">the Game Object to move away from</param>
        /// <param name="stepSize">how fast the Game Object should move away from the target</param>
        public void MoveFromObject(ZObject target, float stepSize)
        {
            Vector2 t = target.position - position;

            t.Normalize();
            position -= (t * stepSize);
        }
Example #3
0
 /// <summary>
 /// This will move the Game Object outside of the Game Object by moving it in the given direction until it is no longer colliding with it.
 /// </summary>
 /// <param name="mo">The Game Object to Move Outside of</param>
 /// <param name="dir">The direction to move in</param>
 public void MoveOutside(ZObject mo, float dir)
 {
     while (Collision(mo))
     {
         MoveDirection(dir, 1);
     }
 }
Example #4
0
 /// <summary>
 /// Tests if an object is fully within Game Object
 /// </summary>
 /// <param name="obj">The Game Object to test</param>
 /// <returns>Returns true if "obj" is completely within this Game Object</returns>
 public bool Within(ZObject obj)
 {
     if (PointWithin(obj.position) && PointWithin(obj.position + new Vector2(width, 0)) &&
         PointWithin(obj.position + new Vector2(0, height)) && PointWithin(obj.position + new Vector2(width, height)))
     {
         return(true);
     }
     return(false);
 }
Example #5
0
        /// <summary>
        /// This will move the Game Object outside of another Game Object by moving it in the given direction with a set step size until it is no longer colliding with the object any more.
        /// This will throw an ArgumentException if stepSize is equal to 0.
        /// </summary>
        /// <param name="mo">The Game Object to Move Outise of</param>
        /// <param name="dir">The direction to move in</param>
        /// <param name="stepSize">The size of the step to take between each collision test.</param>
        public void MoveOutside(ZObject mo, float dir, float stepSize)
        {
            if (stepSize == 0) //Test if stepSize is 0 to avoid infinite loops. Throw ArgumentException if it is.
            {
                throw new ArgumentException("Can not execute MoveOutside with a step size of 0");
            }

            while (Collision(mo))
            {
                MoveDirection(dir, stepSize);
            }
        }
Example #6
0
 public View(Vector2 pos)
 {
     position = pos;
     toFollow = null;
 }
Example #7
0
 public View(ZObject gobj)
 {
     toFollow = gobj;
     position = gobj.Position() - new Vector2(136, 240);
 }
Example #8
0
 /// <summary>
 /// This will get the distance between this object's and "obj's" position
 /// </summary>
 /// <param name="obj">The object to compare distances with</param>
 /// <returns>The distance between obj and this Game Object</returns>
 public float DistanceTo(ZObject obj)
 {
     return((obj.position - position).Length());
 }
Example #9
0
 /// <summary>
 /// Tests if an Object is within the set distance
 /// </summary>
 /// <param name="gobj">The Game Object to test</param>
 /// <param name="dist">The distance to test if is within</param>
 /// <returns>True if the point is within the distance of dist</returns>
 public bool IsWithin(ZObject gobj, float dist)
 {
     return(DistanceTo(gobj) <= dist);
 }
        /// <summary>
        /// This will move the Game Object outside of another Game Object by moving it in the given direction with a set step size until it is no longer colliding with the object any more.
        /// This will throw an ArgumentException if stepSize is equal to 0.
        /// </summary>
        /// <param name="mo">The Game Object to Move Outise of</param>
        /// <param name="dir">The direction to move in</param>
        /// <param name="stepSize">The size of the step to take between each collision test.</param>
        public void MoveOutside(ZObject mo, float dir, float stepSize)
        {
            if (stepSize == 0) //Test if stepSize is 0 to avoid infinite loops. Throw ArgumentException if it is.
                throw new ArgumentException("Can not execute MoveOutside with a step size of 0");

            while (Collision(mo))
            {
                MoveDirection(dir, stepSize);
            }
        }
 /// <summary>
 /// This will move the Game Object outside of the Game Object by moving it in the given direction until it is no longer colliding with it.
 /// </summary>
 /// <param name="mo">The Game Object to Move Outside of</param>
 /// <param name="dir">The direction to move in</param>
 public void MoveOutside(ZObject mo, float dir)
 {
     while (Collision(mo))
     {
         MoveDirection(dir, 1);
     }
 }
Example #12
0
 /// <summary>
 /// Sets the Game Object's visibility to match that of the given Game Object.
 /// </summary>
 /// <param name="showLike">The Game Object who's visibility will be matched</param>
 public void ShowLike(ZObject showLike)
 {
     show = showLike.show;
 }
Example #13
0
 /// <summary>
 /// Sets the Game Objects scale to that of another Game Object.
 /// </summary>
 /// <param name="gobj">The game object to match the scale of</param>
 public void ScaleTo(ZObject gobj)
 {
     scale = gobj.scale;
 }
Example #14
0
 public View(Vector2 pos)
 {
     position = pos;
     toFollow = null;
 }
 /// <summary>
 /// Tests if an Object is within the set distance
 /// </summary>
 /// <param name="gobj">The Game Object to test</param>
 /// <param name="dist">The distance to test if is within</param>
 /// <returns>True if the point is within the distance of dist</returns>
 public bool IsWithin(ZObject gobj, float dist)
 {
     return (DistanceTo(gobj) <= dist);
 }
 /// <summary>
 /// Move the Game Object towards another.
 /// </summary>
 /// <param name="target">the Game Object to move towards</param>
 /// <param name="stepSize">the maximum step that the Game Object will take to get to the target position</param>
 public void MoveTowardsObject(ZObject target, float stepSize)
 {
     Vector2 t = target.position - position;
     t.Normalize();
     position += (t * stepSize);
 }
 /// <summary>
 /// Tests if an object is fully within Game Object
 /// </summary>
 /// <param name="obj">The Game Object to test</param>
 /// <returns>Returns true if "obj" is completely within this Game Object</returns>
 public bool Within(ZObject obj)
 {
     if (PointWithin(obj.position) && PointWithin(obj.position + new Vector2(width, 0)) &&
         PointWithin(obj.position + new Vector2(0, height)) && PointWithin(obj.position + new Vector2(width, height)))
             return true;
     return false;
 }
 /// <summary>
 /// Sets the Game Object's visibility to match that of the given Game Object.
 /// </summary>
 /// <param name="showLike">The Game Object who's visibility will be matched</param>
 public void ShowLike(ZObject showLike)
 {
     show = showLike.show;
 }
 /// <summary>
 /// Sets the Game Objects scale to that of another Game Object.
 /// </summary>
 /// <param name="gobj">The game object to match the scale of</param>
 public void ScaleTo(ZObject gobj)
 {
     scale = gobj.scale;
 }
 /// <summary>
 /// Scales the Game Object to match proportions with another.
 /// This is different than ScaleTo as it will make sure both
 /// ZObjects have the same width and height in pixels instead of simply matching the scale of both objects.
 /// </summary>
 /// <param name="gobj">The game object with which to match the scale of</param>
 public void RelativeScale(ZObject gobj)
 {
     float hScale = (float)gobj.width / (float)width;
     float vScale = (float)gobj.height / (float)height;
     scale = new Vector2(hScale, vScale);
 }
Example #21
0
 public View(ZObject gobj)
 {
     toFollow = gobj;
     position = gobj.Position() - new Vector2(136, 240);
 }
 /// <summary>
 /// This will get the distance between this object's and "obj's" position
 /// </summary>
 /// <param name="obj">The object to compare distances with</param>
 /// <returns>The distance between obj and this Game Object</returns>
 public float DistanceTo(ZObject obj)
 {
     return (obj.position - position).Length();
 }