public void CollisionCheck(Rectangle rectangle, IPhysicsHandler physics)
 {
     if (CollisionRectangle.Intersects(new Rectangle(rectangle.X, rectangle.Bottom + 1, rectangle.Width, 0)) && physics.JumpingDown == false && rectangle.Bottom - 0.1f < CollisionRectangle.Top)
     {
         physics.OnGround = true;
     }
 }
Пример #2
0
        public void PointOutsideReturnsFalseTest(float x, float y, float z)
        {
            var shape = new CollisionRectangle(Vector2.Zero, Vector2.One);

            var result = shape.IsWithin(new Vector3(x, y, z));

            result.Should().BeFalse();
        }
Пример #3
0
 public Vertex(Vector2 position, CollisionRectangle parent)
 {
     mVersion          = ++mCounter;
     Position          = position;
     ParentRectangle   = parent;
     Connectable       = true;
     mCost             = float.MaxValue;
     mHeuristicCost    = float.MaxValue;
     mAdjacentVertices = new HashSet <Vertex>();
 }
Пример #4
0
 private void ResetLocation()
 {
     if (!CollisionRectangle.Intersects(InputManager.MouseRectangle))
     {
         Location = InputManager.MousePosition + Camera.Position;
     }
     else
     {
         Location = Location + Camera.Position;
     }
 }
Пример #5
0
        public ActionResult <CollisionRectangle> Create(double[] coordinates)
        {
            if (coordinates.Length != 4)
            {
                return(BadRequest("Exactly four doubles has to be inputted!"));
            }
            var collisionRectangle = new CollisionRectangle(new CoordinatePoint(coordinates[0], coordinates[1]),
                                                            new CoordinatePoint(coordinates[2], coordinates[3]));

            _collisionRectangleRepository.Save(collisionRectangle);
            return(Created("", collisionRectangle));
        }
Пример #6
0
        public Vertex GetPath(Vector3 start, Vector3 destination)
        {
            // We need to insert start and destination into the graph
            var edgeHashSet = new HashSet <Edge>(new CompareEdgeVertices());

            // We dont care about the rectanlge
            var    rectagle          = new CollisionRectangle(new Vector2(-1.0f), new Vector2(1.0f), new Vector2(1.0f, -1.0f));
            Vertex startVertex       = new Vertex(new Vector2(start.X, start.Z), rectagle);
            Vertex destinationVertex = new Vertex(new Vector2(destination.X, destination.Z), rectagle);

            mVertices.Add(startVertex);
            mVertices.Add(destinationVertex);
            CalculateVisibleVertices(startVertex, mVertices, ref edgeHashSet);
            CalculateVisibleVertices(destinationVertex, mVertices, ref edgeHashSet);
            mVertices.Remove(startVertex);
            mVertices.Remove(destinationVertex);

            var directEdge = new Edge(startVertex, destinationVertex, 0.0f);

            // If there exists a direct path, we dont have to use A*
            if (edgeHashSet.Contains(directEdge))
            {
                startVertex.mNextVertex = destinationVertex;
                startVertex.mNextVertex.mPreviousVertex = startVertex;
                // We need to remove the vertices which we added
                foreach (var vertex in mVertices)
                {
                    vertex.mAdjacentVertices.Remove(startVertex);
                    vertex.mAdjacentVertices.Remove(destinationVertex);
                }
                return(destinationVertex);
            }

            // Now calculate the path with A*
            startVertex = AStar.Search(startVertex, destinationVertex, mVertices);

            // We need to remove the vertices which we added
            foreach (var vertex in mVertices)
            {
                vertex.mAdjacentVertices.Remove(startVertex);
                vertex.mAdjacentVertices.Remove(destinationVertex);
            }

            return(startVertex.mNextVertex);
        }
Пример #7
0
        /// <summary>
        /// Constructs an <see cref="Actor"/>.
        /// </summary>
        /// <param name="mesh">The <see cref="Mesh"/> which the actor represents in the scene</param>
        public Actor(Mesh mesh)
        {
            mMesh = mesh;

            mAudioSources      = new List <AudioSource>();
            mBoundingRectangle = new CollisionRectangle(mesh.mMeshData.mBoundingRectangle);

            mModelMatrix = mMesh.mMeshData.mRootTransformation * Matrix.Identity;

            mAnimator = new Animator(mesh);

            Color = new Vector3(1.0f);

            // Actor should be rendered
            mRender     = true;
            mCastShadow = true;

            IActor = null;
        }
Пример #8
0
        /// <summary>
        /// Constructs a <see cref="MeshData"/>
        /// </summary>
        public MeshData()
        {
            mVertices    = null;
            mVerticesExt = null;
            mIndices     = null;
            mBones       = null;

            mMaterials  = new List <Material>();
            mSubDatas   = new List <SubData>();
            mAnimations = new List <Animation.Animation>();
            mIsSkinned  = false;

            mPrimitiveType      = PrimitiveType.TriangleList;
            mTotalNumPrimitives = 0;

            mBoundingSphere    = new BoundingSphere(new Vector3(0.0f), 0.0f);
            mBoundingRectangle = new CollisionRectangle(Vector2.Zero, Vector2.Zero, Vector2.Zero);

            mRootTransformation = Matrix.Identity;
            mIsTerrain          = false;
        }
Пример #9
0
        void DoBrickCollision()
        {
            TileMatrix tileMatrix = (TileMatrix)Game.Services.GetService(typeof(TileMatrix));

            if (CollisionRectangle.Intersects(tileMatrix.CollisionRectangle))
            {
                for (int row = 0; row < TileMatrix.NumRows; row++)
                {
                    if (CollisionRectangle.Intersects(tileMatrix[row].CollisionRectangle))
                    {
                        for (int tile = 0; tile < TileRow.TilesPerRow; tile++)
                        {
                            if (!tileMatrix[row][tile].Cleared && CollisionRectangle.Intersects(tileMatrix[row][tile].CollisionRectangle))
                            {
                                ((BrickInvaders)Game).State = GameState.GameOver;
                                break;                                 // only need to hit one tile to die
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
        public bool UpdateButton(MouseState mouse, GameTime gameTime)
        {
            if (mouse.LeftButton == ButtonState.Pressed)
            {
                if (CollisionRectangle.Contains(new Point(mouse.X, mouse.Y)))
                {
                    IsClicked   = true;
                    IsCovered   = true;
                    elapsedTime = gameTime.TotalGameTime.TotalMilliseconds;
                }
            }
            else
            {
                IsCovered = false;
            }

            if (elapsedTime != 0 && gameTime.TotalGameTime.TotalMilliseconds - elapsedTime >= ButtonWait)
            {
                IsClicked   = false;
                elapsedTime = 0f;
                return(true);
            }
            return(false);
        }
        public void CollisionCheck(Rectangle rectangle, IPhysicsHandler physics)
        {
            //Point CollisionTop = new Point(rectangle.Center.X, rectangle.Top - 1);
            //Point CollisionBottom = new Point(rectangle.Center.X, rectangle.Bottom + 1);
            Point CollisionLeft  = new Point(rectangle.Left - 1, rectangle.Center.Y);
            Point CollisionRight = new Point(rectangle.Right + 1, rectangle.Center.Y);

            if (CollisionRectangle.Contains(CollisionLeft))
            {
                physics.CollisionLeft = true;
            }
            if (CollisionRectangle.Contains(CollisionRight))
            {
                physics.CollisionRight = true;
            }
            if (CollisionRectangle.Intersects(new Rectangle(rectangle.X, rectangle.Bottom + 1, rectangle.Width, 0)))
            {
                physics.OnGround = true;
            }
            if (CollisionRectangle.Intersects(new Rectangle(rectangle.X, rectangle.Top - 1, rectangle.Width, 0)))
            {
                physics.CollisionTop = true;
            }
        }
Пример #12
0
 public bool Intersects(Rectangle rect)
 {
     return(CollisionRectangle.Intersects(rect) && !Standable);
 }
Пример #13
0
 //checks rectangle collision with the passed mouse coordinates
 public virtual bool CollisionMouse(int x, int y)
 {
     return(CollisionRectangle.Contains(x, y));
 }
Пример #14
0
 //checks rectangle collision with other rectangles
 public virtual bool CollisionSprite(Sprite sprite)
 {
     return(CollisionRectangle.Intersects(sprite.CollisionRectangle));
 }
Пример #15
0
 public bool IsCollidingWith(Sprite spriteToCheck)
 {
     return(CollisionRectangle.Intersects(spriteToCheck.CollisionRectangle));
 }
Пример #16
0
 public bool Collided(CollisionRectangle r)
 {
     return Rect.Intersects(r.Rect);
 }
Пример #17
0
 public bool Collided(CollisionRectangle r)
 {
     return r.Collided(this);
 }
Пример #18
0
 public bool Equals(MovingEntity other)
 {
     return(CollisionRectangle.Intersects(other.CollisionRectangle) &&
            other.Layer > Layer);
 }