public BoxCollider(float _x, float _y, float _width, float _height) { // // Special BoxCollider that is stationary and will not move // likke a building or card pile // Rectangle _boxToCollide = new Rectangle(_x, _y, _width, _height); OriginLocal = new Vector2(_x / 2, _y / 2); boxContainer = new Rectangle(_boxToCollide.x, _boxToCollide.y, _boxToCollide.width, _boxToCollide.height); CollisionBox = new BoxAABB(); boxContainer.x = (_boxToCollide.x - OriginLocal.X) + 10; boxContainer.y = (_boxToCollide.y - OriginLocal.Y / 2) + 10; BoxPoints = new List <Vector2>(); Vector2 topL = new Vector2(boxContainer.x, boxContainer.y); Vector2 topR = new Vector2(topL.X + boxContainer.width, topL.Y); Vector2 botL = new Vector2(topL.X, topL.Y + boxContainer.height); Vector2 botR = new Vector2(topR.X, topR.Y + boxContainer.height); BoxPoints.Add(topL); BoxPoints.Add(botL); BoxPoints.Add(botR); BoxPoints.Add(topR); // // Find the min & max vectors for collision // CollisionBox.Fit(BoxPoints); //updates the position of this collider RenderLayer = Global.BOXCOLLIDER_LAYER; //make sure this is drawn first fixedCollider = true; }
public override void Update(float deltaTime) { base.Update(deltaTime); // // Has Entity been assigned yet? // if (CompEntity == null) { return; } if (!Enabled) { return; } // // update location of box containing the collider // if (!fixedCollider) { boxContainer.x = Transform.Position.X - OriginLocal.X; boxContainer.y = Transform.Position.Y - OriginLocal.Y; BoxPoints = new List <Vector2>(); Vector2 topL = new Vector2(boxContainer.x, boxContainer.y); Vector2 topR = new Vector2(topL.X + boxContainer.width, topL.Y); Vector2 botL = new Vector2(topL.X, topL.Y + boxContainer.height); Vector2 botR = new Vector2(topR.X, topR.Y + boxContainer.height); BoxPoints.Add(topL); BoxPoints.Add(botL); BoxPoints.Add(botR); BoxPoints.Add(topR); // // Find the min & max vectors for collision // CollisionBox.Fit(BoxPoints); //updates the position of this collider } if (!setSceneColliders) { // // update the database of colliders in this scene (happens only once) // SceneColliderDatabase.SetCollider(CompEntity, CollidreShape.Box); setSceneColliders = true; } }