BoundingCircle GetBounds(Limb limb) { Vector2 center = new Vector2(limb.Transform.Position.X, limb.Transform.Position.Y); float radius = limb.Size.X + limb.Size.Y; radius /= 2; if (Owner != null) { center.X += Owner.World.Translation.X; center.Y += Owner.World.Translation.Y; Vector3 scl = Vector3.One; EonMathHelper.GetMatrixScale(Owner.World, out scl); radius *= (scl.X + scl.Y) / 2; } radius *= (limb.Transform.Scale.X + limb.Transform.Scale.Y) / 2; center += new Vector2(radius, radius); return(new BoundingCircle(center, radius)); }
/// <summary> /// Used to calculate collisions between /// PerPixelObjects. /// </summary> /// <param name="object1">PerPixelObject 1.</param> /// <param name="object2">PerPixelObject 2.</param> /// <returns>The result of the check.</returns> public static bool PerPixelCollision( PerPixelObject object1, PerPixelObject object2) { Vector2 poc = Vector2.Zero; if (CollisionShapeHelper.Collides(object1.Bounds, object2.Bounds, out poc) != CollisionType.None) { int x1 = (int)EonMathHelper.Max(object1.Bounds.X, object2.Bounds.X); int x2 = (int)EonMathHelper.Min(object1.Bounds.Right, object2.Bounds.Right); int y1 = (int)EonMathHelper.Max(object1.Bounds.Y, object2.Bounds.Y); int y2 = (int)EonMathHelper.Min(object1.Bounds.Bottom, object2.Bounds.Bottom); for (int y = y1; y < y2; y++) { for (int x = x1; x < x2; x++) { Color colour1 = object1.ColourBits[(x - object1.Bounds.X) + (y - object1.Bounds.Y) * object1.Texture.Width]; Color colour2 = object2.ColourBits[(x - object2.Bounds.X) + (y - object2.Bounds.Y) * object2.Texture.Width]; if (colour1.A != 0 && colour2.A != 0) { return(true); } } } } return(false); }
public void ChangeControllerSensitivity(float amount) { if (controllerSensitivity != amount) { controllerSensitivity = EonMathHelper.Clamp(controllerSensitivity, 0.1f, 0.9f); } }
/// <summary> /// Used to set the sensitivity of the Mouse. /// </summary> /// <param name="value">The value to set the sensitivity to.</param> public void SetMouseSensitivity(float value) { if (sensitivity != value) { sensitivity = EonMathHelper.Clamp(sensitivity, 1, 100); } }
/// <summary> /// Sets the volume of this Cinematic. /// </summary> /// <param name="amount">The amount to set the volume by.</param> public void SetVolume(float amount) { if (amount > 1 || amount < 0) { amount = EonMathHelper.Clamp(amount); } vidPlayer.Volume = amount; }
/// <summary> /// Changes the volume of an existing audio category. /// </summary> /// <param name="value">The volume to change to.</param> /// <param name="audioCategory">The audio category to be eddited.</param> public static void ChangeVolume(float value, string audioCategory) { value = EonMathHelper.Clamp(value, 0, 100); if (audioEngine.GetCategory(audioCategory).Name != null) { audioEngine.GetCategory(audioCategory).SetVolume(value); } else { throw new ArgumentNullException("Invalid audio category: " + audioCategory); } }
/// <summary> /// Changes the screen resolution of the game. /// </summary> /// <param name="width">New resolution width.</param> /// <param name="height">New resolution height.</param> public static void ChangeScreenResolution(float width, float height) { if (!EonMathHelper.EqualEnough(width, scrnRes.X) || !EonMathHelper.EqualEnough(height, scrnRes.Y)) { prevScrnRes = scrnRes; scrnRes = new Vector2(width, height); if (OnScreenResChanged != null) { OnScreenResChanged(); } } }
public void SetVibration(float leftMotor, float rightMotor, float duration) { if (IsPadConnected) { if (VibrateEnabled) { leftMotor = EonMathHelper.Clamp(leftMotor, 0.0f, 1.0f); rightMotor = EonMathHelper.Clamp(rightMotor, 0.0f, 1.0f); vibrationDuration = TimeSpan.FromMilliseconds(duration); vibrationIntencity[(int)TriggersIdx.Left] = leftMotor; vibrationIntencity[(int)TriggersIdx.Right] = rightMotor; } } }
/// <summary> /// Gets the maximum size of the text. /// </summary> /// <returns>The maximum size of the text.</returns> public override Vector2 GetTextSize() { Vector2 vec = Vector2.Zero; for (int i = 0; i < lines.Count; i++) { Vector2 temp = font.MeasureString(lines[i]) * scale; if (EonMathHelper.IsGreaterThanOrEqualTo(temp, vec)) { vec = temp; } } return(vec); }
void CreateBlocks(Rectangle worldSize) { Vector2 bottom = new Vector2(worldSize.X, worldSize.Bottom); Vector2 maxBlocks = new Vector2( EonMathHelper.Round(worldSize.Width / BLOCK_SIZE), EonMathHelper.Round(worldSize.Height / BLOCK_SIZE)); for (int x = 0; x < maxBlocks.X; x++) { for (int y = 0; y < maxBlocks.Y; y++) { blocks.Add(new Block(x, y, BLOCK_SIZE)); } } }
/// <summary> /// Used to check if a rectangle collides with the BoundingCircle. /// </summary> /// <param name="rectangle">The rectangle to check aginst.</param> /// <param name="circle">The BoundingCircle to collide with.</param> /// <param name="pointOfContact">The point of contact between the two shapes.</param> /// <returns>The result of the check.</returns> public static CollisionType Collides(Rectangle rectangle, BoundingCircle circle, out Vector2 pointOfContact) { Vector2 rectCenter = new Vector2(rectangle.Center.X, rectangle.Center.Y); float dist = Vector2.Distance(circle.Center, rectCenter); pointOfContact = EonMathHelper.Midpoint(circle.Center, new Vector2(rectangle.Center.X, rectangle.Center.Y)); if (dist - (circle.Radius + rectangle.Width) <= 0 && dist - (circle.Radius + rectangle.Height) <= 0) { return(CollisionType.Full); } else if (dist > circle.Radius + rectangle.Height && dist > circle.Radius + rectangle.Width) { return(CollisionType.None); } return(CollisionType.Partial); }
/// <summary> /// Used to determine if two rectangles collide. /// </summary> /// <param name="rectangle1">Rectangle 1.</param> /// <param name="rectangle2">Rectangle 2.</param> /// <param name="pointOfContact">The point of contact between the two shapes.</param> /// <returns>The result of the check.</returns> public static CollisionType Collides(Rectangle rectangle1, Rectangle rectangle2, out Vector2 pointOfContact) { pointOfContact = EonMathHelper.Midpoint(new Vector2(rectangle1.Center.X, rectangle1.Center.Y), new Vector2(rectangle2.Center.X, rectangle2.Center.Y)); if (rectangle1.Right < rectangle2.X || rectangle1.X > rectangle2.Right || rectangle1.Bottom < rectangle2.Y || rectangle1.Y > rectangle2.Bottom) { return(CollisionType.None); } else if (rectangle1.X <= rectangle2.X && rectangle1.Right >= rectangle2.Right && rectangle1.Y < rectangle2.Y && rectangle1.Bottom >= rectangle2.Bottom) { return(CollisionType.Full); } return(CollisionType.Partial); }
/// <summary> /// Used to check if two BoundingCircles collides. /// </summary> /// <param name="otherCircle">The BoundingCircle to check aginst.</param> /// <param name="circle">The BoundingCircle to collide with.</param> /// <param name="pointOfContact">The point of contact between the two shapes.</param> /// <returns>The result of the check.</returns> public static CollisionType Collides(BoundingCircle circle, BoundingCircle otherCircle, out Vector2 pointOfContact) { float radialDistance = circle.Radius + otherCircle.Radius; float centerDistance; centerDistance = Vector2.Distance(circle.Center, otherCircle.Center); pointOfContact = EonMathHelper.Midpoint(circle.Center, otherCircle.Center); if (centerDistance > radialDistance) { return(CollisionType.None); } else if (radialDistance - centerDistance >= 0) { return(CollisionType.Full); } return(CollisionType.Partial); }