private void ActionRespawn() { this.X = 0; this.Y = 2; this.VelocityX = 0; this.VelocityY = 0; this.VelocityZ = 0; this._State = PlayerState.FallDown; this._Item = ItemType.Grenade; this.ItemCount = 0; this.FaceLeft = false; this._HurtSide = CollisionRectAccess.HitSide.None; this.RotationY = 0; this.RotationX = 0; }
private void ActionHurt(BackgroundAccess Foreground) { //hurt 7 float BigMovement = SpaceAndTime.LengthFrom2DTo3D(30); if (this.Frame != 7) { this.Frame = 7; //First cancel all movement this.VelocityX = 0; this.VelocityY = 0; //Now get the new movement switch (this._HurtSide) { case (CollisionRectAccess.HitSide.TopRight): this.VelocityX = BigMovement; this.VelocityY = -BigMovement; break; case (CollisionRectAccess.HitSide.TopLeft): this.VelocityX = -BigMovement; this.VelocityY = -BigMovement; break; case (CollisionRectAccess.HitSide.BottomRight): this.VelocityX = BigMovement; this.VelocityY = BigMovement; break; case (CollisionRectAccess.HitSide.BottomLeft): this.VelocityX = -BigMovement; this.VelocityY = BigMovement; break; } } else if (this.VelocityX == 0 || this.IsOnGround) { this._HurtSide = CollisionRectAccess.HitSide.None; this._State = PlayerState.RollBack; } this.ApplyNormalGravity(); }
//Check this sprite against other sprites. If it // is hitting them it will change its state accordingly public void CheckEnemyCollision(PlayableCharacterAccess[] PlayersToCheck, uint IndexToSkip) { if (this._HurtSide == CollisionRectAccess.HitSide.None) { for (uint i = 0; i < PlayersToCheck.Length; i++) { //Skip the index of IndexToSkip if (i != IndexToSkip) { //Set this collision this._HurtSide = this.CollisionRects.CheckObjectRectAgainst(PlayersToCheck[i], this.Frame, this.X, this.Y); //Set the other collision switch (this._HurtSide) { case (CollisionRectAccess.HitSide.TopRight): PlayersToCheck[i]._HurtSide = CollisionRectAccess.HitSide.BottomLeft; break; case (CollisionRectAccess.HitSide.TopLeft): PlayersToCheck[i]._HurtSide = CollisionRectAccess.HitSide.BottomRight; break; case (CollisionRectAccess.HitSide.BottomRight): PlayersToCheck[i]._HurtSide = CollisionRectAccess.HitSide.TopLeft; break; case (CollisionRectAccess.HitSide.BottomLeft): PlayersToCheck[i]._HurtSide = CollisionRectAccess.HitSide.TopRight; break; } break; } } } }
/// <summary> /// Used to detect if there has been a collision between two objects such as sprites. /// </summary> public CollisionRectAccess.HitSide CheckObjectRectAgainst(SpriteAccess OtherObject, int CurrFrame, float CurrX, float CurrY) { CollisionRectAccess.HitSide RetVal = HitSide.None; //Get the locations of our rectange's sides in floats float[] RectangleCollisions = (float[])this.RectangleMatrix[CurrFrame]; float RectLeft = CurrX + RectangleCollisions[0]; float RectTop = CurrY + RectangleCollisions[1]; float RectRight = CurrX - RectangleCollisions[2]; float RectBottom = CurrY - RectangleCollisions[3]; //Get the locations the other rectange's sides in floats float[] OtherRectangleCollisions = (float[])OtherObject.CollisionRects.GetIndex(OtherObject.Frame); float OtherRectLeft = OtherObject.X + OtherRectangleCollisions[0]; float OtherRectTop = OtherObject.Y + OtherRectangleCollisions[1]; float OtherRectRight = OtherObject.X - OtherRectangleCollisions[2]; float OtherRectBottom = OtherObject.Y - OtherRectangleCollisions[3]; //Check each side of the rect to see if it is within the other rect bool LeftInBounds = RectLeft >= OtherRectRight && RectRight <= OtherRectLeft; bool TopInBounds = RectTop >= OtherRectTop && RectBottom <= OtherRectTop; bool RightInBounds = RectRight >= OtherRectLeft && RectRight <= OtherRectRight; bool BottomInBounds = RectTop >= OtherRectBottom && RectBottom <= OtherRectBottom; //Check to see if both sides are in the rect //If they are pick one of the sides only depending on which is deeper if (RectTop <= OtherRectTop && RectBottom >= OtherRectBottom) { if (OtherRectTop - RectTop > RectBottom - OtherRectBottom) { BottomInBounds = true; } else { TopInBounds = true; } } if (RectLeft <= OtherRectLeft && RectRight >= OtherRectRight) { if (OtherRectLeft - RectLeft > RectRight - OtherRectRight) { LeftInBounds = true; } else { RightInBounds = true; } } //if this frame's rect is inside the other rect, there is a collision if (LeftInBounds && (BottomInBounds || TopInBounds)) { if (BottomInBounds) { RetVal = HitSide.BottomLeft; } else if (TopInBounds) { RetVal = HitSide.TopLeft; } } else if (RightInBounds && (BottomInBounds || TopInBounds)) { if (TopInBounds) { RetVal = HitSide.TopRight; } else { RetVal = HitSide.BottomRight; } } return(RetVal); }