Esempio n. 1
0
 public void AddSprite(int portalNumber, Actor spr)
 {
     (portalNumber == 0 ? mInPortal1 : mInPortal2).Add(spr);
     mState = PortalState.InUse;
 }
Esempio n. 2
0
        private void HandleSpriteInPortal(Actor spr, Sprite portalIn,  Sprite portalOut, float currentTime)
        {
            spr.PortalAngle = MathHelper.WrapAngle(MathHelper.PiOver2 * (2 - (portalIn.Oriented - portalOut.Oriented)));
            Matrix rotation = Matrix.CreateRotationZ(spr.PortalAngle);

            Vector2 dXY = new Vector2(spr.Position.X - portalIn.CollisionSurface.Center.X,
                                      spr.Position.Y - portalIn.CollisionSurface.Center.Y);

            spr.PortalPosition = new Vector2(portalOut.CollisionSurface.Center.X, portalOut.CollisionSurface.Center.Y) + Vector2.Transform(dXY, rotation);

            bool swap = false;
            switch (portalIn.Oriented)
            {
                case Orientation.Up:
                    swap = portalIn.CollisionSurface.Center.Y < spr.CollisionSurface.Center.Y;
                    break;
                case Orientation.Right:
                    swap = portalIn.CollisionSurface.Center.X > spr.CollisionSurface.Center.X;
                    break;
                case Orientation.Down:
                    swap = portalIn.CollisionSurface.Center.Y > spr.CollisionSurface.Center.Y;
                    break;
                case Orientation.Left:
                    swap = portalIn.CollisionSurface.Center.X < spr.CollisionSurface.Center.X;
                    break;
                default:
                    break;
            }

            if (swap && (currentTime - spr.LastSwapTime > .2))
            {
                spr.LastSwapTime = currentTime;

                var temp = spr.PortalPosition;
                spr.PortalPosition = spr.Position;
                spr.Position = temp;

                var temp2 = spr.PortalAngle;
                spr.PortalAngle = spr.Angle;
                spr.Angle = temp2;

                spr.Velocity = Vector2.Transform(spr.Velocity, rotation);
                spr.Acceleration = Vector2.Transform(spr.Acceleration, rotation);

                if (portalOut.Oriented == Orientation.Up)
                    spr.Velocity += 25 * new Vector2(0, -1);
            }

            spr.PortalUpdateDependents();
        }