/// <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; }
//////////////////////////////////////////////////////////// /// <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); }
//////////////////////////////////////////////////////////// /// <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)); }
//////////////////////////////////////////////////////////// /// <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); }
static extern void sfView_setCenter(IntPtr View, Vector2f center);
static extern void sfView_setSize(IntPtr View, Vector2f size);
//////////////////////////////////////////////////////////// /// <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); }
//////////////////////////////////////////////////////////// /// <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)); }
//////////////////////////////////////////////////////////// /// <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())); }
/// <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; } } } } }
//////////////////////////////////////////////////////////// /// <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; }
//////////////////////////////////////////////////////////// /// <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; }
static extern void sfView_move(IntPtr View, Vector2f offset);
//////////////////////////////////////////////////////////// /// <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); }
static extern Vector2i sfRenderWindow_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View);
//////////////////////////////////////////////////////////// /// <summary> /// Move the view /// </summary> /// <param name="offset">Offset to move the view</param> //////////////////////////////////////////////////////////// public void Move(Vector2f offset) { sfView_move(CPointer, offset); }
//////////////////////////////////////////////////////////// /// <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)) { }
//////////////////////////////////////////////////////////// /// <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)) { }
//////////////////////////////////////////////////////////// /// <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); }
//////////////////////////////////////////////////////////// /// <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) { }
//////////////////////////////////////////////////////////// /// <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); }
//////////////////////////////////////////////////////////// /// <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; }
static extern Vector2f sfTransform_transformPoint(ref Transform transform, Vector2f point);
//////////////////////////////////////////////////////////// /// <summary> /// Construct the shape with an initial size /// </summary> /// <param name="size">Size of the shape</param> //////////////////////////////////////////////////////////// public RectangleShape(Vector2f size) { Size = size; }
//////////////////////////////////////////////////////////// /// <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); }
//////////////////////////////////////////////////////////// /// <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()); }
static extern Vector2i sfRenderTexture_mapCoordsToPixel(IntPtr CPointer, Vector2f point, IntPtr View);