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; } }
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(); }
public Vertex(Vector2 position, CollisionRectangle parent) { mVersion = ++mCounter; Position = position; ParentRectangle = parent; Connectable = true; mCost = float.MaxValue; mHeuristicCost = float.MaxValue; mAdjacentVertices = new HashSet <Vertex>(); }
private void ResetLocation() { if (!CollisionRectangle.Intersects(InputManager.MouseRectangle)) { Location = InputManager.MousePosition + Camera.Position; } else { Location = Location + Camera.Position; } }
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)); }
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); }
/// <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; }
/// <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; }
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 } } } } } }
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; } }
public bool Intersects(Rectangle rect) { return(CollisionRectangle.Intersects(rect) && !Standable); }
//checks rectangle collision with the passed mouse coordinates public virtual bool CollisionMouse(int x, int y) { return(CollisionRectangle.Contains(x, y)); }
//checks rectangle collision with other rectangles public virtual bool CollisionSprite(Sprite sprite) { return(CollisionRectangle.Intersects(sprite.CollisionRectangle)); }
public bool IsCollidingWith(Sprite spriteToCheck) { return(CollisionRectangle.Intersects(spriteToCheck.CollisionRectangle)); }
public bool Collided(CollisionRectangle r) { return Rect.Intersects(r.Rect); }
public bool Collided(CollisionRectangle r) { return r.Collided(this); }
public bool Equals(MovingEntity other) { return(CollisionRectangle.Intersects(other.CollisionRectangle) && other.Layer > Layer); }