Exemplo n.º 1
0
 public Minigame3(ZoomLevels zoom)
     : base(zoom)
 {
     TimeInHill = 0.0f;
     HarmonyInsideHill = false;
     HillShape = null;
 }
Exemplo n.º 2
0
        public Bullet(Node parent, string name)
            : base(parent, name)
        {
            Render = new ImageRender(this, "Render");
            Render.SetTexture(GetRoot<State>().GetService<AssetCollector>().GetAsset<Texture2D>("bullet"));
            Render.Layer = .1f;
            Render.Scale = new Vector2(.1f);
            Render.Color = Color.White;
            Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

            //Make our collision rectangles the size of the rendered sprite.
            Body.Bounds = Render.Bounds;
            Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);

            Shape = new Circle(this, "Shape", Body.Width / 2);
            Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
            Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

            Collision.Group.AddMask(1);
            Collision.Pair.AddMask(2);
            Collision.Immovable = true;
            Collision.CollideEvent += collision => Recycle();
            Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
            Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

            DeathTimer = new Timer(this, "DeathTimer");
            DeathTimer.Milliseconds = 2000;
            DeathTimer.LastEvent += Recycle;
            DeathTimer.LastEvent += DeathTimer.Stop;
        }
Exemplo n.º 3
0
        public void Circle_ContainsVector2()
        {
            var circle = new Circle(new Vector2(200.0f, 300.0f), 100.0f);

            var p1 = new Vector2(-1, -1);
            var p2 = new Vector2(110, 300);
            var p3 = new Vector2(200, 300);
            var p4 = new Vector2(290, 300);
            var p5 = new Vector2(400, 400);

            bool result;

            circle.Contains(ref p1, out result);
            Assert.AreEqual(false, result);
            circle.Contains(ref p2, out result);
            Assert.AreEqual(true, result);
            circle.Contains(ref p3, out result);
            Assert.AreEqual(true, result);
            circle.Contains(ref p4, out result);
            Assert.AreEqual(true, result);
            circle.Contains(ref p5, out result);
            Assert.AreEqual(false, result);

            Assert.AreEqual(false, circle.Contains(p1));
            Assert.AreEqual(true, circle.Contains(p2));
            Assert.AreEqual(true, circle.Contains(p3));
            Assert.AreEqual(true, circle.Contains(p4));
            Assert.AreEqual(false, circle.Contains(p5));
        }
Exemplo n.º 4
0
        public Hero(string name, HeroClass heroClass)
        {
            Collect = false;
            Online = TimeSpan.Zero;
            Target = Position;
            AcceptArrows = true;
            zLastPosition = Position;
            Netid = 0;
            Name = name;
            Class = heroClass;
            Position.Z = ZLayer.Npc;
            WalkingSpeed = 10;

            SpriteManager.AddPositionedObject(this);

            Collider = ShapeManager.AddCircle();
            Collider.AttachTo(this, false);
            Collider.Visible = false;

            Sprite = LoadSprite();
            Sprite.AttachTo(this, false);
            Sprite.Resize(4);
            Sprite.AnimationSpeed = 0.1f;            

            Label = TextManager.AddText(name, Globals.Font);
            Label.AttachTo(this, false);
            Label.HorizontalAlignment = HorizontalAlignment.Center;
            Label.RelativePosition = new Vector3(0, 4, ZLayer.NpcLabel - Position.Z);            

            InitStats();
        }
        public SplinePointSelectionMarker()
        {
            mRectangle = ShapeManager.AddAxisAlignedRectangle();
            mLine = ShapeManager.AddLine();
            mRectangle.Color = Color.LightBlue;

            mEndpoint1 = ShapeManager.AddCircle();
            mEndpoint1.Color = Color.Yellow;
            mEndpoint2 = ShapeManager.AddCircle();
            mEndpoint2.Color = Color.Yellow;
        }
Exemplo n.º 6
0
        public Shark()
            : base(0, 0, 160, 96, 60, 20)
        {
            this.MaxAccDash = SHARK_DASH_ACCELERATION;
            this.MaxVelDash = SHARK_DASH_SPEED;
            this.calories = SHARK_BASE_HEALTH;
            this.DashTime = 0.5f;

            mouthCircle = new Circle(this.Bounds.center.X + 100, this.Bounds.center.Y, 35);
            mouthPoint = Vector2.Zero;
        }
Exemplo n.º 7
0
 public TriggerTile(Vector3 pos, float radius, string name)
 {
     Collect = false;
     Name = name;
     Collider = ShapeManager.AddCircle();
     Collider.Position = pos;
     Collider.Radius = radius;
     Globals.EventManager.AddEvent(Trigger, $"trigger{Id}");
     Id++;
     InitializeEvent();
 }
Exemplo n.º 8
0
        /*
        public static bool checkCollision(Sprite s1, Sprite s2, bool perPixel)
        {
            if (s1.getBounds().Intersects(s2.getBounds()))
            {
                if (perPixel)
                {
                    return pixelPerfect(s1, s2);
                }

                return true;
            }

            return false;
        }*/
        public static bool checkCollision(Circle c1, Circle c2)
        {
            float distance  = (c1.position - c2.position).LengthSquared();
            float radiusSumSquare = (float)Math.Pow(c1.radius + c2.radius, 2);

            if (distance < radiusSumSquare)
            {
                return true;
            }

            return false;
        }
Exemplo n.º 9
0
        public static bool Collides(Rectangle r, Circle c)
        {
            // check if the center of the circle is in the rectangle
            if (r.Contains(c.Center))
                return true;

            // check if the circle's "outer box" doesn't intersect the rectangle
            Rectangle outerBounds = new Rectangle(new Point(c.Left, c.Top), new Point(c.Radius * 2));
            if (!r.Intersects(outerBounds))
                return false;

            // check if the circle contains any of the rectangle's corners
            Point corner = new Point(r.Left, r.Top);
            if (c.Contains(corner))
                return true;
            corner.X = r.Right;
            if (c.Contains(corner))
                return true;
            corner.Y = r.Bottom;
            if (c.Contains(corner))
                return true;
            corner.X = r.Left;
            if (c.Contains(corner))
                return true;

            // check for a top/bottom rectangle edge collision
            if(AxisMath.Between(c.Center.X, r.Left, r.Right))
            {
                // check top edge
                if (c.Bottom >= r.Top)
                    return true;

                // check bottom edge
                if (c.Top <= r.Bottom)
                    return true;
            }

            // check for a left/right rectangle edge collision
            if(AxisMath.Between(c.Center.Y, r.Top, r.Bottom))
            {
                // check left edge
                if (c.Right >= r.Left)
                    return true;

                // check right edge
                if (c.Left <= r.Right)
                    return true;
            }

            // if all else fails, return false
            return false;
        }
Exemplo n.º 10
0
 public void TestDistancePointCircle()
 {
     var p1 = new Vector2(-9, 10);
     var p2 = new Vector2(10, 30);
     var p3 = new Vector2(11, 30);
     var p4 = new Vector2(-990, -2990);
     var c1 = new Circle(new Vector2(10, 10), 20);
     var delta = 0.0001f; // amount of acceptable error
     Assert.AreEqual(0, Geometry.Distance(p1, c1), delta); // interior
     Assert.AreEqual(0, Geometry.Distance(p2, c1), delta); // edge
     Assert.AreEqual(Math.Sqrt(1 * 1 + 20 * 20) - 20, Geometry.Distance(p3, c1), delta); // exterior near
     Assert.AreEqual(Math.Sqrt(1000 * 1000 + 3000 * 3000) - 20, Geometry.Distance(p4, c1), delta); // exterior far
 }
        private void CreateRotationHandleForPositionedObject(PositionedObject posObj)
        {
            float size = 10;

            Circle circ = new Circle();
            circ.Radius = size / SpriteManager.Camera.PixelsPerUnitAt(posObj.Z);
            circ.Position = new Vector3(posObj.X, posObj.Y + 2, posObj.Z);
            circ.Color = Color.LightBlue;

            Handle handle = new Handle(Layer, circ);

            circ.AttachTo(posObj, true);
        }
Exemplo n.º 12
0
 public static CollisionData CircleCircle(Circle a, Circle b)
 {
     Vector2 delta = b.Entity.Position - a.Entity.Position;
     float length = delta.Length();
     float distance = a.Radius + b.Radius;
     if (length < distance)
     {
         CollisionData result = new CollisionData(distance-length);
         result.Normal = delta.Normalized();
         result.Position = a.Entity.Position;
         result.Position += (-a.Radius + result.Interpenetration * .5f) * result.Normal;
         return result;
     }
     return CollisionData.Empty;
 }
Exemplo n.º 13
0
        public void Circle_ConstructorsAndProperties()
        {
            var circle = new Circle(new Vector2(200.0f, 300.0f), 100.0f);

            Assert.AreEqual(new Circle() { Center = new Vector2(200.0f, 300.0f), Radius = 100.0f }, circle);
            Assert.AreEqual(200.0f - 100.0f, circle.Left);
            Assert.AreEqual(200.0f + 100.0f, circle.Right);
            Assert.AreEqual(300.0f - 100.0f, circle.Top);
            Assert.AreEqual(300.0f + 100.0f, circle.Bottom);
            Assert.AreEqual(new Point(200, 300), circle.Location);
            Assert.AreEqual(new Vector2(200.0f, 300.0f), circle.Center);
            Assert.AreEqual(100.0f, circle.Radius);
            Assert.AreEqual(false, circle.IsEmpty);
            Assert.AreEqual(true, new Circle().IsEmpty);
            Assert.AreEqual(new Circle(), Circle.Empty);
        }
Exemplo n.º 14
0
        public Asteroid(Node parent, string name)
            : base(parent, name)
        {
            Body.X = RandomHelper.GetFloat() * EntityGame.Viewport.Right;
            Body.Y = RandomHelper.GetFloat() * EntityGame.Viewport.Bottom;
            Body.Angle = MathHelper.TwoPi * RandomHelper.GetFloat();

            Physics.Thrust(RandomHelper.GetFloat(30, 60));
            Physics.Restitution = 1.5f;

            Render = new ImageRender(this, "Render");
            Render.SetTexture(GetRoot<State>().GetService<AssetCollector>().GetAsset<Texture2D>("circle"));
            Render.Scale = new Vector2(RandomHelper.GetFloat(.25f, .5f));
            Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

            Body.Width = Render.DrawRect.Width;
            Body.Height = Render.DrawRect.Height;
            Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);

            Physics.Mass = Render.Scale.X;

            Health = new Health(this, "Health", 3);
            Health.DiedEvent += entity => Destroy(this);

            Shape = new Circle(this, "Circle", Body.Width / 2);
            Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
            Shape.Debug = true;
            Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

            Collision.Pair.AddMask(0);
            Collision.Pair.AddMask(1);
            Collision.Group.AddMask(2);
            Collision.Pair.AddMask(2);
            Collision.ResolutionGroup.AddMask(2);
            Collision.CollideEvent += OnCollide;
            Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
            Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

            _ghoster = new AsteroidGhoster(this, "Ghoster");
            _ghoster.LinkDependency(AsteroidGhoster.DEPENDENCY_BODY, Body);
            _ghoster.LinkDependency(AsteroidGhoster.DEPENDENCY_RENDER, Render);
            _ghoster.LinkDependency(AsteroidGhoster.DEPENDENCY_COLLISION, Collision);
            _ghoster.Initialize();
            _ghoster.SetOnCollide(OnCollide);
        }
        public PlayerShip(Node parent, string name)
            : base(parent, name)
        {
            Body.X = EntityGame.Viewport.Width / 2f;
            Body.Y = EntityGame.Viewport.Height / 2f;

            Physics.Drag = 0.97f;
            Physics.AngularDrag = 0.9f;

            Render = new ImageRender(this, "Render");
            Render.SetTexture(GetRoot<State>().GetService<AssetCollector>().GetAsset<Texture2D>("ship"));
            Render.Layer = .01f;
            Render.Scale = new Vector2(.128f);
            Render.LinkDependency(ImageRender.DEPENDENCY_BODY, Body);

            Body.Bounds = Render.Bounds;
            Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);

            Gun = new SimpleGun(this, "SimpleGun");
            Gun.LinkDependency(SimpleGun.DEPENDENCY_BODY, Body);
            Gun.LinkDependency(SimpleGun.DEPENDENCY_PHYSICS, Physics);
            Shape = new Circle(this, "Circle", Body.Width * .8f);
            Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
            Shape.Debug = true;
            Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

            Collision.Group.AddMask(0);
            Collision.Pair.AddMask(2);
            Collision.CollideEvent += OnCollide;
            Collision.Immovable = true;
            Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
            Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

            //Control
            UpButton = new DoubleInput(this, "UpButton", Keys.W, Buttons.DPadUp, PlayerIndex.One);
            DownButton = new DoubleInput(this, "DownButton", Keys.S, Buttons.DPadDown, PlayerIndex.One);
            LeftButton = new DoubleInput(this, "LeftButton", Keys.A, Buttons.DPadLeft, PlayerIndex.One);
            RightButton = new DoubleInput(this, "RightButton", Keys.D, Buttons.DPadRight, PlayerIndex.One);
            FireButton = new DoubleInput(this, "FireButton", Keys.Space, Buttons.A, PlayerIndex.One);
            ThrustTrigger = new GamePadTrigger(this, "ThrustTrigger", Triggers.Right, PlayerIndex.One);
            //GravityTrigger = new GamePadTrigger(this, "GravityTrigger", Triggers.Left, PlayerIndex.One);

            LookAnalog = new GamePadAnalog(this, "LookAnalog", Sticks.Left, PlayerIndex.One);
        }
Exemplo n.º 16
0
 public void Circle_ToRectangleTest()
 {
     var actual = new Circle(center: new Vector2(200, 300), radius: 100).ToRectangle();
     var expected = new Rectangle(100, 200, 200, 200);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 17
0
 public void Circle_Inflate()
 {
     var circle = new Circle(new Vector2(200.0f, 300.0f), 100.0f);
     circle.Inflate(100.0f);
     Assert.AreEqual(new Circle(new Vector2(100.0f, 200.0f), 300.0f), circle);
 }
Exemplo n.º 18
0
        public void Circle_IntersectionTest()
        {
            var circle = new Circle(new Vector2(200.0f, 300.0f), 100.0f);

            var circ1 = new Circle(new Vector2(350.0f, 300.0f), 100.0f);
            var circ2 = new Circle(new Vector2(400.0f, 300.0f), 100.0f);

            var rect1 = new Rectangle(250, 300, 100, 100);
            var rect2 = new Rectangle(400, 300, 100, 100);

            bool result;

            circle.Intersects(ref circ1, out result);
            Assert.AreEqual(true, result);
            circle.Intersects(ref circ2, out result);
            Assert.AreEqual(false, result);

            circle.Intersects(ref rect1, out result);
            Assert.AreEqual(true, result);
            circle.Intersects(ref rect2, out result);
            Assert.AreEqual(false, result);

            Assert.AreEqual(true, circle.Intersects(circ1));
            Assert.AreEqual(false, circle.Intersects(circ2));

            Assert.AreEqual(true, circle.Intersects(rect1));
            Assert.AreEqual(false, circle.Intersects(rect2));
        }
Exemplo n.º 19
0
        public void Circle_ContainsCircle()
        {
            var circle = new Circle(new Vector2(200.0f, 300.0f), 100.0f);
            var circle1 = new Circle(new Vector2(199.0f, 299.0f), 100.0f);
            var circle2 = new Circle(new Vector2(200.0f, 300.0f), 25.0f);
            var circle3 = new Circle(new Vector2(200.0f, 300.0f), 100.0f);
            var circle4 = new Circle(new Vector2(201.0f, 301.0f), 100.0f);

            bool result;

            circle.Contains(ref circle1, out result);
            Assert.AreEqual(false, result);

            circle.Contains(ref circle2, out result);
            Assert.AreEqual(true, result);

            circle.Contains(ref circle3, out result);
            Assert.AreEqual(true, result);

            circle.Contains(ref circle4, out result);
            Assert.AreEqual(false, result);

            Assert.AreEqual(false, circle.Contains(circle1));
            Assert.AreEqual(true, circle.Contains(circle2));
            Assert.AreEqual(true, circle.Contains(circle3));
            Assert.AreEqual(false, circle.Contains(circle4));
        }
            public CircleNode(State stateref, string name)
                : base(stateref, name)
            {
                Shape = new Circle(this, "Circle", 30);
                Shape.Offset = new Vector2((Shape as Circle).Radius);
                Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);
                Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);

                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);

                Body.Bounds = new Vector2((Shape as Circle).Diameter);

                ImageRender.Scale = new Vector2(Body.Width, Body.Height);
                ImageRender.Layer = .5f;

                TextRender.Color = Color.White;
                TextRender.Font = Assets.Font;
                TextRender.Text = Name;
                TextRender.Layer = 1f;
            }
Exemplo n.º 21
0
        public static float MinimumDistance(Segment2D segment, Circle circle)
        {
            if (Segment2D.Intersects(segment, circle))
            {
                return 0;
            }

            // okay this Max *should be* unnecessary, but lets keep it just for sure
            return FlaiMath.Max(0, Segment2D.MinimumDistance(segment, circle.Position) - circle.Radius); 
        }
Exemplo n.º 22
0
        /// <summary>
        /// Modifies the first Polygon so that it is the result of both merged polygons.  
        /// This method assumes that the polygons collide and that both are drawn
        /// clockwise.
        /// </summary>
        /// <param name="polygon">The first polygon.  This one will be modified.</param>
        /// <param name="otherPolygon">The second polygon which will not be modified.</param>
        #endregion
        public static void Merge(Polygon polygon, Polygon otherPolygon)
        {
            // Vic says:  This is useful for debugging merging.  Don't remove it!!!
            bool shouldDebug = false;
            Segment[] firstSegments;
            Segment[] secondSegments;
            List<ContactPoint> contactPoints = GetContactPoints(polygon, otherPolygon, out firstSegments, out secondSegments);

#if !SILVERLIGHT && !WINDOWS_PHONE && !XBOX360 && !IOS && !MONODROID

            if (shouldDebug)
            {
                ShapeCollection sc = new ShapeCollection();
                sc.Polygons.Add(polygon);
                sc.Polygons.Add(otherPolygon);

                for (int i = 0; i < contactPoints.Count; i++)
                {
                    Circle circle = new Circle();
                    circle.Radius = .5f;
                    circle.Position = contactPoints[i].Position;

                    if (contactPoints[i].ContactType == ContactType.SegmentIntersection)
                    {
                        circle.Color = Color.Orange;
                    }
                    else
                    {
                        circle.Color = Color.Green;
                    }

                    sc.Circles.Add(circle);

                }



                FlatRedBall.Content.Math.Geometry.ShapeCollectionSave scs =
                    new FlatRedBall.Content.Math.Geometry.ShapeCollectionSave();

                scs.AddPolygonList(sc.Polygons);
                scs.AddCircleList(sc.Circles);

                string fileName = 
                    FlatRedBall.IO.FileManager.MyDocuments + "mergeTest.shcx";

                scs.Save(fileName);

                sc.Clear();
            }
#endif

            int firstPointToStartAt = GetPointToStartAt(polygon, otherPolygon);

            if (firstPointToStartAt == -1)
            {
                throw new NotImplementedException();
                // return a polygon that is the same shape as the rectangle
            }

            List<Vector3> thisVertices = GetAbsoluteVertices(firstSegments);
            List<Vector3> otherVertices = GetAbsoluteVertices(secondSegments);

            SetPointsFromContactPointsAndVertices(polygon, otherPolygon, contactPoints, firstPointToStartAt, thisVertices, otherVertices);
        }
Exemplo n.º 23
0
        public Penguin(PlayerIndex playerIndex, Vector2 pos, string colorCode)
            : base(pos.X, pos.Y, 36, 32, SMALL_SIZE, SMALL_MASS)
        {
            if (colorCode == "")
                color = Color.Blue;
            else if (colorCode == "_r")
                color = Color.Red;
            else if (colorCode == "_p")
                color = Color.Black;
            else
                color = Color.Green;

            this.colorCode        = colorCode;
            this.controller       = playerIndex;
            this.startingPosition = pos;
            this.Calories         = START_CALORIES;
            this.CurrentSize      = Size.Small;

            this.DashCost         = DASH_SMALL_COST;
            this.SpearCost        = SPEAR_SMALL_COST;
            this.MeleeCost        = MELEE_SMALL_COST;

            this.meleeCooldown    = MELEE_COOLDOWN;
            this.fireCooldown     = FIRE_COOLDOWN;

            this.isHit = false;
            this.canMelee = true;
            meleeTime = 0.0f;
            resetBlink();

            spearPoint = Vector2.Zero;
            spearCircle = new Circle(this.Bounds.center.X + 60, this.Bounds.center.Y, 50);
            spearDeflectorAura = new Circle(0, 0, 75);
        }
Exemplo n.º 24
0
        public static CollisionData CirclePolygon(Circle a, Polygon b)
        {
            Matrix rotation = Matrix.CreateRotationZ(b.Entity.Orientation);
            Matrix inverseRotation = Matrix.CreateTranslation(new Vector3(-b.Entity.Position, 0)) * Matrix.CreateRotationZ(-b.Entity.Orientation) * Matrix.CreateTranslation(new Vector3(b.Entity.Position, 0));
            Vector2 circlePosition = Vector2.Transform(a.Entity.Position, inverseRotation);

            Vector2 delta = b.Entity.Position - circlePosition;

            Polygon.Projection proj;
            CollisionData result = new CollisionData(float.MaxValue);

            float inter1 = 0, inter2 = 0;
            for (int i = 0; i < b.normals.Length; i++)
            {
                proj = a.Project(b.normals[i], -delta);
                inter1 = b.projections[i].Max - proj.Min;
                inter2 = -(b.projections[i].Min - proj.Max);

            #if DEBUG && SATDEBUG
                Vector2 p = b.Entity.Position;
                Integrator.line(p + Vector2.TransformNormal(b.normals[i], rotation) * proj.Min, p + Vector2.TransformNormal(b.normals[i], rotation) * proj.Max, Color.LimeGreen);
            #endif

                if (inter1 < 0 || inter2 < 0)
                    return CollisionData.Empty;

                if (inter1 < inter2 && inter1 < result.Interpenetration)
                {
                    result.Interpenetration = inter1;
                    result.Normal = -Vector2.TransformNormal(b.normals[i], rotation);
                }
                else if (inter2 < result.Interpenetration)
                {
                    result.Interpenetration = inter2;
                    result.Normal = Vector2.TransformNormal(b.normals[i], rotation);
                }
            }

            Vector2 closest = Vector2.UnitX;
            float maxDist = float.MaxValue;
            for (int i = 0; i < b.Vertices.Length; i++)
            {
                Vector2 v = b.Vertices[i] + b.Entity.Position;
                Vector2 d = v - circlePosition;

                if (d.LengthSquared() < maxDist)
                {
                    closest = d;
                    maxDist = d.LengthSquared();
                }
            }
            Vector2 normal = closest.Normalized();

            proj = b.Project(normal, delta);
            Polygon.Projection self = a.Project(normal, Vector2.Zero);
            inter1 = self.Max - proj.Min;
            inter2 = -(self.Min - proj.Max);

            #if DEBUG && SATDEBUG
            Vector2 p2 = a.Entity.Position;
            Integrator.line(p2 + Vector2.TransformNormal(normal, rotation) * proj.Min, p2 + Vector2.TransformNormal(normal, rotation) * proj.Max, Color.LimeGreen);
            #endif

            if (inter1 < 0 || inter2 < 0)
                return CollisionData.Empty;

            if (inter1 < inter2 && inter1 < result.Interpenetration)
            {
                result.Interpenetration = inter1;
                result.Normal = Vector2.TransformNormal(normal, rotation);
            }
            else if (inter2 < result.Interpenetration)
            {
                result.Interpenetration = inter2;
                result.Normal = -Vector2.TransformNormal(normal, rotation);
            }

            #if DEBUG && SATDEBUG
            Vector2 pos = a.Entity.Position;
            Integrator.line(pos, pos + result.Normal * result.Interpenetration, Color.White);
            #endif

            return result;
        }
Exemplo n.º 25
0
 public static bool Collides(Circle c1, Circle c2)
 {
     return c1.Intersects(c2);
 }
Exemplo n.º 26
0
            public override void Initialize()
            {
                base.Initialize();
                Body.Width = Render.DrawRect.Width;
                Body.Height = Render.DrawRect.Height;
                Body.Origin = new Vector2(Render.Texture.Width / 2f, Render.Texture.Height / 2f);

                Shape = new Circle(this, "Circle", Body.Width / 2);
                Shape.Offset = new Vector2(Body.Width / 2, Body.Height / 2);
                Shape.Debug = true;
                Shape.LinkDependency(Circle.DEPENDENCY_BODY, Body);

                Collision.LinkDependency(Collision.DEPENDENCY_SHAPE, Shape);
                Shape.LinkDependency(Circle.DEPENDENCY_COLLISION, Collision);
            }
Exemplo n.º 27
0
        public void Circle_ContainsFloats()
        {
            var circle = new Circle(new Vector2(200.0f, 300.0f), 100.0f);

            float x1 = -1; float y1 = -1;
            float x2 = 110; float y2 = 300;
            float x3 = 200; float y3 = 300;
            float x4 = 290; float y4 = 300;
            float x5 = 400; float y5 = 400;

            Assert.AreEqual(false, circle.Contains(x1, y1));
            Assert.AreEqual(true, circle.Contains(x2, y2));
            Assert.AreEqual(true, circle.Contains(x3, y3));
            Assert.AreEqual(true, circle.Contains(x4, y4));
            Assert.AreEqual(false, circle.Contains(x5, y5));
        }
Exemplo n.º 28
0
        public float DistanceTo(Circle circle)
        {
            float distanceToCenter = DistanceTo(circle.Position);

            return distanceToCenter - circle.Radius;
        }
Exemplo n.º 29
0
        private Circle AddHandle(float x, float y, float z, float size, float ScaleXCoef, float ScaleYCoef)
        {
            Circle circ = new Circle();
            circ.Radius = size / SpriteManager.Camera.PixelsPerUnitAt(z);
            circ.Position = new Vector3(x, y, z);
            circ.Color = Color.LightBlue;
            circ.AttachTo((PositionedObject)mCurrentElement, true);

            Handle handle = new Handle(Layer, circ);
            handle.ScaleXCoefficient = ScaleXCoef;
            handle.ScaleYCoefficient = ScaleYCoef;
            handle.HandleSize = mHandleSize;
            //Add the handle to the lists
            mHandles.Add(handle);

            return circ;
        }
Exemplo n.º 30
0
        protected override void Reset()
        {
            TimeInHill = 0.0f;
            HarmonyInsideHill = false;
            HillShape = PhysicsData3.GetHillCircle(WorldData.ZoomScaleAmount[CurrentZoom]);

            Blockers.Add(new Jousting.Blocker(new AnimatedSprite(ArtAssets3.DogHouseSprite),
                                              ArtAssets3.GetDoghouseShape(WorldData.ZoomScaleAmount[CurrentZoom],
                                                                          PhysicsData3.GetDoghouseCenter(WorldData.ZoomScaleAmount[CurrentZoom])),
                                              true, 0.0f, 999.0f));
            DogHouse = Blockers[0];
            Utilities.Math.Shape.Rectangle bounds = World.WorldBounds;
            Interval xInt = bounds.XEnds,
                     yInt = bounds.YEnds;
            for (int i = 0; i < PhysicsData3.NumbTennisBalls; ++i)
            {
                Blockers.Add(new Jousting.Blocker(new AnimatedSprite(ArtAssets3.TennisBall),
                                                  ArtAssets3.GetTennisBallShape(WorldData.ZoomScaleAmount[CurrentZoom],
                                                                                new Vector2(xInt.Random(), yInt.Random())),
                                                  false, PhysicsData3.TennisBallMaxVelocity, PhysicsData3.TennisBallMass));
            }
        }