コード例 #1
0
 public WorldState()
 {
     platformSide = GetInstance().GetOwnSide();
     if (GetInstance().IsInOpen(GetInstance().gameObject))
     {
         currentLocation = CurrentLocation.OPEN;
         currentAlcove   = null;
     }
     else
     {
         currentLocation = CurrentLocation.ALCOVE;
         currentAlcove   = GetInstance().GetCurrentAlcove();
     }
 }
コード例 #2
0
        private void RespondBouncy(Actor a, PlatformSide side)
        {
            switch (side)
            {
            case PlatformSide.Top: {
                if (a.ActualCoords.Y != Position.Top - a.Position.Height)
                {
                    a.ActualCoords.Y   = Position.Top - a.Position.Height;
                    a.ActualVelocity.Y = -a.ActualVelocity.Y * 0.9f < -Player.JUMP_VELO
                            ? -a.ActualVelocity.Y * 0.9f
                            : -Player.JUMP_VELO;
                    a.CurrentPlatformType = Type;
                }
            }
            break;

            case PlatformSide.Bottom: {
                if (a.ActualCoords.Y != Position.Bottom)
                {
                    a.ActualCoords.Y = Position.Bottom;
                }
                a.ActualVelocity.Y = -a.ActualVelocity.Y;
            }
            break;

            case PlatformSide.Right:
                if (a.ActualVelocity.X > 0)
                {
                    a.ActualVelocity.X = a.ActualVelocity.X * 2;
                }
                else
                {
                    a.ActualVelocity.X = -a.ActualVelocity.X * 2;
                }
                break;

            case PlatformSide.Left:
                if (a.ActualVelocity.X > 0)
                {
                    a.ActualVelocity.X = -a.ActualVelocity.X * 2;
                }
                else
                {
                    a.ActualVelocity.X = a.ActualVelocity.X * 2;
                }
                break;
            }
        }
コード例 #3
0
        private void RespondWin(Actor a, PlatformSide side)
        {
            //throw new System.NotImplementedException("Please implement stage progression!");
            if (!(a is Player))
            {
                return;
            }

            if (!a.Stage.ChoiceMade && Game.Manager.ChoiceMaker.Initialized)
            {
                Game.Manager.ChoiceMaker.Active = true;
            }
            else
            {
                a.Stage.LoadNextLevel();
            }
        }
コード例 #4
0
        public Boolean OnCollide(Actor a, PlatformSide side)
        {
            switch (Type)
            {
            case PlatformType.Default:
            case PlatformType.Icy:
                RespondNormal(a, side);
                break;

            case PlatformType.Bouncy:
                RespondBouncy(a, side);
                break;

            case PlatformType.Win:
                RespondWin(a, side);
                return(true);
            }

            return(false);
        }
コード例 #5
0
        Vector3 GetNextPlatformPos(Transform prevPlatform, Transform currPlatform)
        {
            Vector3      pos         = Vector3.zero;
            PlatformSide sideTiSpawn = GetSideToSpawn(prevPlatform, currPlatform);
            int          posY        = (int)Random.Range(prevPlatform.position.y + 2, prevPlatform.position.y + 4);

            switch (sideTiSpawn)
            {
            case PlatformSide.right:
                pos = new Vector3(Random.Range(prevPlatform.position.x, m_RightX), posY, 0);
                break;

            case PlatformSide.left:
                pos = new Vector3(Random.Range(m_LeftX, prevPlatform.position.x), posY, 0);
                break;

            case PlatformSide.either:
                pos = new Vector3(Random.Range(m_LeftX, m_RightX), posY, 0);
                break;
            }
            return(pos);
        }
コード例 #6
0
        /*
         * public bool OnCollide(Actor a)
         * {
         *  var ret = false;
         *  PlatformSide side = PlatformSide.Undefined;
         *
         *  //If my feet were above the top (y is lesser) of the platform earlier, then now I must be on top of it.
         *  //Also, if my velocity is down or zero, then that must be it. I cannot land on top of a platform if I am moving up, UNLESS the direction is up.
         *
         *  if (((Direction != Direction.Up) ? a.LastPosition.Bottom <= Position.Top : a.LastPosition.Bottom >= Position.Top)
         *      && ((Direction != Direction.Up) ? a.ActualVelocity.Y >= 0 : true)) //I land on a platform.
         *      side = PlatformSide.Top;
         *  //If my head was below (y is greater) the bottom of the platform earlier, then now I must have hit the bottom.
         *  //Also, if my velocity is up then that must be it. I cannot hit my head on the bottom of a platform if I am moving down or not moving vertically at all.
         *  else if (((Direction != Direction.Down) ? a.LastPosition.Top >= Position.Bottom : a.LastPosition.Top <= Position.Bottom)
         *      && ((Direction != Direction.Down) ? a.ActualVelocity.Y <= 0 : true)) //I hit my head on the underside of a platform.
         *      side = PlatformSide.Bottom;
         *
         *  //If my left was to the right (x is greater) of the platform earlier, then now I must have hit its right.
         *  else if (((Direction != Direction.Right) ? a.LastPosition.Left >= Position.Right : a.LastPosition.Left <= Position.Right)
         *      && ((Direction != Direction.Right) ? a.ActualVelocity.X <= 0 : true)) //Sideways collision from the right of this platform.
         *      side = PlatformSide.Right;
         *
         *  //If my right was to the left (x is lesser) of the platform earlier, then now I must have hit its left.
         *  //a.LastPosition.Right <= Position.Left
         *  else if (((Direction != Direction.Left) ? a.LastPosition.Right <= Position.Left : a.LastPosition.Right >= Position.Left)
         *      && ((Direction != Direction.Left) ? a.ActualVelocity.X >= 0 : true)) //Sideways collision from the left of this platform.
         *      side = PlatformSide.Left;
         *
         *  switch (Type)
         *  {
         *      case PlatformType.Default:
         *      case PlatformType.Icy:
         *          RespondNormal(a, side);
         *          break;
         *      case PlatformType.Bouncy:
         *          RespondBouncy(a, side);
         *          break;
         *      case PlatformType.Win:
         *          RespondWin(a, side);
         *          ret = true;
         *          break;
         *  }
         *  return ret;
         * }
         */

        private void RespondNormal(Actor a, PlatformSide side)
        {
            switch (side)
            {
            case PlatformSide.Top: {
                if (a.ActualVelocity.Y > 0)
                {
                    a.ActualVelocity.Y = 0;
                }
                a.ActualCoords.Y = Position.Top - a.Position.Height;

                a.CurrentPlatformType = Type;
                a.OnGround            = true;

                ConnectedObjects.Add(a);
            }
            break;

            case PlatformSide.Bottom: {
                if (a.ActualVelocity.Y < 0)
                {
                    a.ActualVelocity.Y = 0;
                }
                a.ActualCoords.Y = Position.Bottom;

                ConnectedObjects.Add(a);
            }
            break;

            case PlatformSide.Right: {
                if (a.ActualVelocity.X < 0)
                {
                    a.ActualVelocity.X = 0;
                }
                a.ActualCoords.X = Position.Right;

                if (Game.Manager.PlayerHasWallJump)
                {
                    (a as Player).OnLeftWall   = true;
                    (a as Player).WallCooldown = 100;
                }

                ConnectedObjects.Add(a);
            }
            break;

            case PlatformSide.Left: {
                if (a.ActualVelocity.X > 0)
                {
                    a.ActualVelocity.X = 0;
                }
                a.ActualCoords.X = Position.Left - a.Position.Width;
                if (Game.Manager.PlayerHasWallJump)
                {
                    (a as Player).OnRightWall  = true;
                    (a as Player).WallCooldown = 100;
                }

                ConnectedObjects.Add(a);
            }
            break;
            }
        }