Exemplo n.º 1
0
        /// <summary>
        /// Handles when another Entity collides into us. Not synonymous CollideInto since the
        /// <paramref name="collider"/> Entity is the one who collided into us. For example, if the
        /// two entities in question were a moving Character and a stationary wall, this Entity would be
        /// the Wall and <paramref name="collider"/> would be the Character.
        /// </summary>
        /// <param name="collider">Entity that collided into us.</param>
        /// <param name="displacement">Displacement between the two Entities.</param>
        public override void CollideFrom(Entity collider, SFML.Graphics.Vector2 displacement)
        {
            // When a character touches this, teleport the character to the destination
            Character character = collider as Character;

            if (character == null)
            {
                return;
            }

            // Only let users use teleports
            if (character is NPC)
            {
                return;
            }

            // Teleport to a new map
            if (DestinationMap > 0)
            {
                if (character.Map.ID != DestinationMap)
                {
                    var newMap = character.World.GetMap(DestinationMap);
                    if (newMap == null)
                    {
                        const string errmsg = "Failed to teleport Character `{0}` - Invalid DestMap `{1}`.";
                        Debug.Fail(string.Format(errmsg, character, this));
                        if (log.IsErrorEnabled)
                        {
                            log.ErrorFormat(errmsg, character, this);
                        }
                        return;
                    }

                    character.Teleport(newMap, Destination);
                }
            }

            // Teleport the CharacterEntity to our predefined location
            character.Position = Destination;
        }
Exemplo n.º 2
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a rotation.
 /// 
 /// The center of rotation is provided for convenience as a second
 /// argument, so that you can build rotations around arbitrary points
 /// more easily (and efficiently) than the usual
 /// Translate(-center); Rotate(angle); Translate(center).
 /// </summary>
 /// <param name="angle">Rotation angle, in degrees</param>
 /// <param name="center">Center of rotation</param>
 ////////////////////////////////////////////////////////////
 public void Rotate(float angle, Vector2f center)
 {
     Rotate(angle, center.X, center.Y);
 }
Exemplo n.º 3
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Transform a 2D point.
 /// </summary>
 /// <param name="point">Point to transform</param>
 /// <returns>Transformed point</returns>
 ////////////////////////////////////////////////////////////
 public Vector2f TransformPoint(Vector2f point)
 {
     return(sfTransform_transformPoint(ref this, point));
 }
Exemplo n.º 4
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a scaling.
 ///
 /// The center of scaling is provided for convenience as a second
 /// argument, so that you can build scaling around arbitrary points
 /// more easily (and efficiently) than the usual
 /// Translate(-center); Scale(factors); Translate(center).
 /// </summary>
 /// <param name="factors">Scaling factors</param>
 /// <param name="center">Center of scaling</param>
 ////////////////////////////////////////////////////////////
 public void Scale(Vector2f factors, Vector2f center)
 {
     Scale(factors.X, factors.Y, center.X, center.Y);
 }
Exemplo n.º 5
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a rotation.
 ///
 /// The center of rotation is provided for convenience as a second
 /// argument, so that you can build rotations around arbitrary points
 /// more easily (and efficiently) than the usual
 /// Translate(-center); Rotate(angle); Translate(center).
 /// </summary>
 /// <param name="angle">Rotation angle, in degrees</param>
 /// <param name="center">Center of rotation</param>
 ////////////////////////////////////////////////////////////
 public void Rotate(float angle, Vector2f center)
 {
     Rotate(angle, center.X, center.Y);
 }
Exemplo n.º 6
0
 static extern void sfView_setCenter(IntPtr View, Vector2f center);
Exemplo n.º 7
0
Arquivo: View.cs Projeto: Furt/netgore
 static extern void sfView_setSize(IntPtr View, Vector2f size);
Exemplo n.º 8
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Convert a point from world coordinates to target coordinates
 ///
 /// This function finds the pixel of the render-target that matches
 /// the given 2D point. In other words, it goes through the same process
 /// as the graphics card, to compute the final position of a rendered point.
 ///
 /// Initially, both coordinate systems (world units and target pixels)
 /// match perfectly. But if you define a custom view or resize your
 /// render-target, this assertion is not true anymore, ie. a point
 /// located at (150, 75) in your 2D world may map to the pixel
 /// (10, 50) of your render-target -- if the view is translated by (140, 25).
 ///
 /// This version uses a custom view for calculations, see the other
 /// overload of the function if you want to use the current view of the
 /// render-target.
 /// </summary>
 /// <param name="point">Point to convert</param>
 /// <param name="view">The view to use for converting the point</param>
 /// <returns>The converted point, in target coordinates (pixels)</returns>
 ////////////////////////////////////////////////////////////
 public Vector2i MapCoordsToPixel(Vector2f point, View view)
 {
     return sfRenderTexture_mapCoordsToPixel(CPointer, point, view != null ? view.CPointer : IntPtr.Zero);
 }
Exemplo n.º 9
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Convert a point from world coordinates to target coordinates
 ///
 /// This function finds the pixel of the render-target that matches
 /// the given 2D point. In other words, it goes through the same process
 /// as the graphics card, to compute the final position of a rendered point.
 ///
 /// Initially, both coordinate systems (world units and target pixels)
 /// match perfectly. But if you define a custom view or resize your
 /// render-target, this assertion is not true anymore, ie. a point
 /// located at (150, 75) in your 2D world may map to the pixel
 /// (10, 50) of your render-target -- if the view is translated by (140, 25).
 ///
 /// This version uses a custom view for calculations, see the other
 /// overload of the function if you want to use the current view of the
 /// render-target.
 /// </summary>
 /// <param name="point">Point to convert</param>
 /// <param name="view">The view to use for converting the point</param>
 /// <returns>The converted point, in target coordinates (pixels)</returns>
 ////////////////////////////////////////////////////////////
 public Vector2i MapCoordsToPixel(Vector2f point, View view)
 {
     return(sfRenderWindow_mapCoordsToPixel(CPointer, point, view != null ? view.CPointer : IntPtr.Zero));
 }
Exemplo n.º 10
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Convert a point from world coordinates to target
 /// coordinates, using the current view
 ///
 /// This function is an overload of the mapCoordsToPixel
 /// function that implicitely uses the current view.
 /// It is equivalent to:
 /// target.MapCoordsToPixel(point, target.GetView());
 /// </summary>
 /// <param name="point">Point to convert</param>
 /// <returns>The converted point, in target coordinates (pixels)</returns>
 ////////////////////////////////////////////////////////////
 public Vector2 MapCoordsToPixel(Vector2f point)
 {
     return(MapCoordsToPixel(point, GetView()));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Handles when another Entity collides into us. Not synonymous CollideInto since the
        /// <paramref name="collider"/> Entity is the one who collided into us. For example, if the
        /// two entities in question were a moving Character and a stationary wall, this Entity would be
        /// the Wall and <paramref name="collider"/> would be the Character.
        /// </summary>
        /// <param name="collider">Entity that collided into us.</param>
        /// <param name="displacement">Displacement between the two Entities.</param>
        public override void CollideFrom(Entity collider, SFML.Graphics.Vector2 displacement)
        {
            // When a character touches this, teleport the character to the destination
            User character = collider as User;

            if (character == null)
            {
                return;
            }

            // Teleport to a new map
            if (DestinationMap > 0)
            {
                if (character.Map.ID != DestinationMap)
                {
                    var newMap = character.World.GetMap(DestinationMap);
                    if (newMap == null)
                    {
                        const string errmsg = "Failed to teleport Character `{0}` - Invalid DestMap `{1}`.";
                        Debug.Fail(string.Format(errmsg, character, this));
                        if (log.IsErrorEnabled)
                        {
                            log.ErrorFormat(errmsg, character, this);
                        }
                        return;
                    }

                    // Teleport the CharacterEntity to our predefined location
                    character.Teleport(newMap, Destination);
                    character.Position = Destination;
                }
            }
            // Teleport to an instanced map
            else if (DestinationMapInstance > 0)
            {
                // Check for a valid map
                var newMapInstance = character.World.GetMap(DestinationMapInstance);
                if (newMapInstance == null)
                {
                    const string errmsg = "Failed to teleport Character `{0}` - Invalid DestMap Instance `{1}`.";
                    Debug.Fail(string.Format(errmsg, character, this));
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, character, this);
                    }
                    return;
                }

                // Try to create the map
                MapInstance instance;
                try
                {
                    instance = new MapInstance(newMapInstance.ID, character.World);
                }
                catch (System.Exception ex)
                {
                    string errmsg = "Failed to create instance: " + ex;
                    Debug.Fail(errmsg);
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg);
                    }
                    return;
                }

                // Check if the map placement is valid
                if (instance.IsValidPlacementPosition(Destination, character.Size))
                {
                    // Add the user to the map
                    character.Teleport(instance, Destination);
                    character.Position = Destination;
                }
                else
                {
                    string errmsg = "Failed to create instance: Not a valid map placement.";
                    Debug.Fail(errmsg);
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg);
                    }
                    return;
                }

                // Does this entity also teleport group members?
                if (TeleportGroupMembers)
                {
                    // Check if the user is in a group
                    if (character.Group == null)
                    {
                        return;
                    }

                    if (!character.Group.Members.IsEmpty())
                    {
                        // If yes, teleport those users too
                        foreach (var groupMember in character.Group.Members.OfType <User>())
                        {
                            groupMember.Teleport(instance, Destination);
                            groupMember.Position = Destination;
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Set the position of a point.
 ///
 /// Don't forget that the polygon must remain convex, and
 /// the points need to stay ordered!
 /// PointCount must be set first in order to set the total
 /// number of points. The result is undefined if index is out
 /// of the valid range.
 /// </summary>
 /// <param name="index">Index of the point to change, in range [0 .. PointCount - 1]</param>
 /// <param name="point">New position of the point</param>
 ////////////////////////////////////////////////////////////
 public void SetPoint(uint index, Vector2f point)
 {
     myPoints[index] = point;
 }
Exemplo n.º 13
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the view from its center and size
 /// </summary>
 /// <param name="center">Center of the view</param>
 /// <param name="size">Size of the view</param>
 ////////////////////////////////////////////////////////////
 public View(Vector2f center, Vector2f size) :
     base(sfView_create())
 {
     Center = center;
     Size   = size;
 }
Exemplo n.º 14
0
 static extern void sfView_move(IntPtr View, Vector2f offset);
Exemplo n.º 15
0
 static extern void sfView_setSize(IntPtr View, Vector2f size);
Exemplo n.º 16
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a scaling.
 /// 
 /// The center of scaling is provided for convenience as a second
 /// argument, so that you can build scaling around arbitrary points
 /// more easily (and efficiently) than the usual
 /// Translate(-center); Scale(factors); Translate(center).
 /// </summary>
 /// <param name="factors">Scaling factors</param>
 /// <param name="center">Center of scaling</param>
 ////////////////////////////////////////////////////////////
 public void Scale(Vector2f factors, Vector2f center)
 {
     Scale(factors.X, factors.Y, center.X, center.Y);
 }
Exemplo n.º 17
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Transform a 2D point.
 /// </summary>
 /// <param name="point">Point to transform</param>
 /// <returns>Transformed point</returns>
 ////////////////////////////////////////////////////////////
 public Vector2f TransformPoint(Vector2f point)
 {
     return sfTransform_transformPoint(ref this, point);
 }
Exemplo n.º 18
0
 static extern Vector2i sfRenderWindow_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View);
Exemplo n.º 19
0
Arquivo: View.cs Projeto: Furt/netgore
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Move the view
 /// </summary>
 /// <param name="offset">Offset to move the view</param>
 ////////////////////////////////////////////////////////////
 public void Move(Vector2f offset)
 {
     sfView_move(CPointer, offset);
 }
Exemplo n.º 20
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position
 /// The vertex color is white and texture coordinates are (0, 0).
 /// </summary>
 /// <param name="position">Vertex position</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position) :
     this(position, Color.White, new Vector2f(0, 0))
 {
 }
Exemplo n.º 21
0
Arquivo: View.cs Projeto: Furt/netgore
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the view from its center and size
 /// </summary>
 /// <param name="center">Center of the view</param>
 /// <param name="size">Size of the view</param>
 ////////////////////////////////////////////////////////////
 public View(Vector2f center, Vector2f size) :
     base(sfView_create())
 {
     Center = center;
     Size = size;
 }
Exemplo n.º 22
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position and color
 /// The texture coordinates are (0, 0).
 /// </summary>
 /// <param name="position">Vertex position</param>
 /// <param name="color">Vertex color</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position, Color color) :
     this(position, color, new Vector2f(0, 0))
 {
 }
Exemplo n.º 23
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a translation.
 /// </summary>
 /// <param name="offset">Translation offset to apply</param>
 ////////////////////////////////////////////////////////////
 public void Translate(Vector2f offset)
 {
     Translate(offset.X, offset.Y);
 }
Exemplo n.º 24
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position and texture coordinates
 /// The vertex color is white.
 /// </summary>
 /// <param name="position">Vertex position</param>
 /// <param name="texCoords">Vertex texture coordinates</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position, Vector2f texCoords) :
     this(position, Color.White, texCoords)
 {
 }
Exemplo n.º 25
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a scaling.
 /// </summary>
 /// <param name="factors">Scaling factors</param>
 ////////////////////////////////////////////////////////////
 public void Scale(Vector2f factors)
 {
     Scale(factors.X, factors.Y);
 }
Exemplo n.º 26
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position, color and texture coordinates
 /// </summary>
 /// <param name="position">Vertex position</param>
 /// <param name="color">Vertex color</param>
 /// <param name="texCoords">Vertex texture coordinates</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position, Color color, Vector2f texCoords)
 {
     Position  = position;
     Color     = color;
     TexCoords = texCoords;
 }
Exemplo n.º 27
0
 static extern Vector2f sfTransform_transformPoint(ref Transform transform, Vector2f point);
Exemplo n.º 28
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the shape with an initial size
 /// </summary>
 /// <param name="size">Size of the shape</param>
 ////////////////////////////////////////////////////////////
 public RectangleShape(Vector2f size)
 {
     Size = size;
 }
Exemplo n.º 29
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a translation.
 /// </summary>
 /// <param name="offset">Translation offset to apply</param>
 ////////////////////////////////////////////////////////////
 public void Translate(Vector2f offset)
 {
     Translate(offset.X, offset.Y);
 }
Exemplo n.º 30
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the shape with an initial size
 /// </summary>
 /// <param name="size">Size of the shape</param>
 ////////////////////////////////////////////////////////////
 public RectangleShape(Vector2f size)
 {
     Size = size;
 }
Exemplo n.º 31
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Combine the current transform with a scaling.
 /// </summary>
 /// <param name="factors">Scaling factors</param>
 ////////////////////////////////////////////////////////////
 public void Scale(Vector2f factors)
 {
     Scale(factors.X, factors.Y);
 }
Exemplo n.º 32
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Change a 2-components vector parameter of the shader
 ///
 /// "name" is the name of the variable to change in the shader.
 /// The corresponding parameter in the shader must be a 2x1 vector
 /// (vec2 GLSL type).
 /// </summary>
 /// <param name="name">Name of the parameter in the shader</param>
 /// <param name="vector">Vector to assign</param>
 ////////////////////////////////////////////////////////////
 public void SetParameter(string name, Vector2f vector)
 {
     SetParameter(name, vector.X, vector.Y);
 }
Exemplo n.º 33
0
 static extern Vector2f sfTransform_transformPoint(ref Transform transform, Vector2f point);
Exemplo n.º 34
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position
 /// The vertex color is white and texture coordinates are (0, 0).
 /// </summary>
 /// <param name="position">Vertex position</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position) :
     this(position, Color.White, new Vector2f(0, 0))
 {
 }
Exemplo n.º 35
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Convert a point from world coordinates to target
 /// coordinates, using the current view
 ///
 /// This function is an overload of the mapCoordsToPixel
 /// function that implicitely uses the current view.
 /// It is equivalent to:
 /// target.MapCoordsToPixel(point, target.GetView());
 /// </summary>
 /// <param name="point">Point to convert</param>
 /// <returns>The converted point, in target coordinates (pixels)</returns>
 ////////////////////////////////////////////////////////////
 public Vector2 MapCoordsToPixel(Vector2f point)
 {
     return MapCoordsToPixel(point, GetView());
 }
Exemplo n.º 36
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position and color
 /// The texture coordinates are (0, 0).
 /// </summary>
 /// <param name="position">Vertex position</param>
 /// <param name="color">Vertex color</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position, Color color) :
     this(position, color, new Vector2f(0, 0))
 {
 }
Exemplo n.º 37
0
 static extern Vector2i sfRenderTexture_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View);
Exemplo n.º 38
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position and texture coordinates
 /// The vertex color is white.
 /// </summary>
 /// <param name="position">Vertex position</param>
 /// <param name="texCoords">Vertex texture coordinates</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position, Vector2f texCoords) :
     this(position, Color.White, texCoords)
 {
 }
Exemplo n.º 39
0
Arquivo: View.cs Projeto: Furt/netgore
 static extern void sfView_setCenter(IntPtr View, Vector2f center);
Exemplo n.º 40
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct the vertex from its position, color and texture coordinates
 /// </summary>
 /// <param name="position">Vertex position</param>
 /// <param name="color">Vertex color</param>
 /// <param name="texCoords">Vertex texture coordinates</param>
 ////////////////////////////////////////////////////////////
 public Vertex(Vector2f position, Color color, Vector2f texCoords)
 {
     Position = position;
     Color = color;
     TexCoords = texCoords;
 }
Exemplo n.º 41
0
Arquivo: View.cs Projeto: Furt/netgore
 static extern void sfView_move(IntPtr View, Vector2f offset);
Exemplo n.º 42
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Change a 2-components vector parameter of the shader
 ///
 /// "name" is the name of the variable to change in the shader.
 /// The corresponding parameter in the shader must be a 2x1 vector
 /// (vec2 GLSL type).
 /// </summary>
 /// <param name="name">Name of the parameter in the shader</param>
 /// <param name="vector">Vector to assign</param>
 ////////////////////////////////////////////////////////////
 public void SetParameter(string name, Vector2f vector)
 {
     SetParameter(name, vector.X, vector.Y);
 }
Exemplo n.º 43
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Set the position of a point.
 ///
 /// Don't forget that the polygon must remain convex, and
 /// the points need to stay ordered!
 /// PointCount must be set first in order to set the total
 /// number of points. The result is undefined if index is out
 /// of the valid range.
 /// </summary>
 /// <param name="index">Index of the point to change, in range [0 .. PointCount - 1]</param>
 /// <param name="point">New position of the point</param>
 ////////////////////////////////////////////////////////////
 public void SetPoint(uint index, Vector2f point)
 {
     myPoints[index] = point;
 }
Exemplo n.º 44
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Move the view
 /// </summary>
 /// <param name="offset">Offset to move the view</param>
 ////////////////////////////////////////////////////////////
 public void Move(Vector2f offset)
 {
     sfView_move(CPointer, offset);
 }