Beispiel #1
0
        public static bool Collision(CircleCollider self, ParticleCollider other)
        {
            Vector2 center   = new Vector2((float)self.x, (float)self.y);
            Vector2 particle = new Vector2((float)other.x, (float)other.y);

            return(Vector2.Distance(center, particle) < self.radius);
        }
Beispiel #2
0
 /// <summary>
 /// Check for a collision between a LineSegmentCollider and a ParticleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(LineSegmentCollider self, ParticleCollider other)
 {
     return(GeometryUtils.IsPointOnSegment(other.x, other.y, self.x1, self.y1, self.x2, self.y2));
 }
Beispiel #3
0
 /// <summary>
 /// Check for a collision between a RectCollider and a ParticleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(RectCollider self, ParticleCollider other)
 {
     return((self.x <= other.x && other.x <= self.x + self.width) &&
            (self.y <= other.y && other.y <= self.y + self.height));
 }
 /// <summary>
 /// Check for a collision between a ParticleCollider and a CircleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(ParticleCollider self, CircleCollider other)
 {
     return Collision(other, self);
 }
 /// <summary>
 /// Check for a collision between a ParticleCollider and a ParticleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(ParticleCollider self, ParticleCollider other)
 {
     return (self.x == other.x && self.y == other.y);
 }
 /// <summary>
 /// Check for a collision between a ParticleCollider and a LineSegmentCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(ParticleCollider self, LineSegmentCollider other)
 {
     return Collision(other, self);
 }
Beispiel #7
0
 /// <summary>
 /// Check for a collision between a RectCollider and a ParticleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(RectCollider self, ParticleCollider other)
 {
     return (self.x <= other.x && other.x <= self.x + self.width) &&
            (self.y <= other.y && other.y <= self.y + self.height);
 }
Beispiel #8
0
 public static bool Collision(CircleCollider self, ParticleCollider other)
 {
     Vector2 center = new Vector2((float)self.x, (float)self.y);
     Vector2 particle = new Vector2((float)other.x, (float)other.y);
     return Vector2.Distance(center, particle) < self.radius;
 }
Beispiel #9
0
        /// <summary>
        /// Return the currently selected menu button based on the previous
        /// menu parameters.
        /// </summary>
        /// <param name="current_selected">The index of the currently selected button.</param>
        /// <param name="buttons">The array of buttons.</param>
        /// <param name="increment">The key that increments the selection.</param>
        /// <param name="decrement">The key that decrements the selection.</param>
        /// <param name="wrap">
        /// Determines what happens when the selection becomes < 0 or greater than the
        /// length of the array. If true, then the selection is modded by the length of
        /// the array. If false it is clamped.
        /// </param>
        /// <returns></returns>
        public static int? GetMenuSelection(
            int? current_selected, SceneButton[] buttons, 
            Keys increment, Keys decrement, 
            bool wrap = true, int default_selection = 0)
        {
            // Local aliases for previous and current mouse and keyboard states.
            MouseState pms = Globals.previousMouseState;
            MouseState cms = Globals.currentMouseState;

            KeyboardState pks = Globals.previousKeyboardState;
            KeyboardState cks = Globals.currentKeyboardState;

            // If the mouse states are valid, and the positions are different (implying
            // the mouse has moved).
            if (pms != null && cms.Position != pms.Position)
            {
                ParticleCollider mouse_pos = new ParticleCollider(cms.Position);
                // Find the first button that collides with the mouse.
                for (int i = 0; i < buttons.Length; i++)
                {
                    if (CollisionChecker.Collision(buttons[i].CollisionMask, mouse_pos))
                        return i;
                }
            }
            // Else if the keyboard states are valid.
            else if (pks != null)
            {
                // If the increment key was pressed once.
                if (
                    cks.IsKeyDown(increment) &&
                    !pks.IsKeyDown(increment))
                {
                    // Return the default value if current_selected == null.
                    if (!current_selected.HasValue)
                        return default_selection;
                    int new_selection = current_selected.Value - 1;
                    // Clamp or wrap the selection.
                    if (wrap)
                        return new_selection % buttons.Length;
                    return wrap ? new_selection % buttons.Length
                                : (int)MathHelper.Clamp(new_selection, 0, buttons.Length);
                }
                // If the decrement key was pressed once.
                else if (
                    cks.IsKeyDown(decrement) &&
                    !pks.IsKeyDown(decrement))
                {
                    // Return the default value if current_selected == null.
                    if (!current_selected.HasValue)
                        return default_selection;
                    int new_selection = current_selected.Value - 1;
                    // Clamp or wrap the selection.
                    if (wrap)
                        return new_selection % buttons.Length;
                    return wrap ? new_selection % buttons.Length
                                : (int)MathHelper.Clamp(new_selection, 0, buttons.Length);
                }
            }
            // Return the current_selected value or null.
            return current_selected ?? null;
        }
Beispiel #10
0
 /// <summary>
 /// Check for a collision between a ParticleCollider and a CircleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(ParticleCollider self, CircleCollider other)
 {
     return(Collision(other, self));
 }
Beispiel #11
0
 /// <summary>
 /// Check for a collision between a ParticleCollider and a LineSegmentCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(ParticleCollider self, LineSegmentCollider other)
 {
     return(Collision(other, self));
 }
Beispiel #12
0
 /// <summary>
 /// Check for a collision between a ParticleCollider and a ParticleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(ParticleCollider self, ParticleCollider other)
 {
     return(self.x == other.x && self.y == other.y);
 }
Beispiel #13
0
 /// <summary>
 /// Check for a collision between a RayCollider and a ParticleCollider.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="other"></param>
 public static bool Collision(RayCollider self, ParticleCollider other)
 {
     return GeometryUtils.IsPointOnRay(other.x, other.y, self.x1, self.y1, self.x2, self.y2);
 }