private Vector3 GetRandomStartPosition(float scale)
        {
            var area = RandomEnum <AreaType> .Get();

            var rand = UnityEngine.Random.Range(0.0f, 1.0f);

            switch (area)
            {
            case AreaType.top:
            {
                return(new Vector3(m_level.Left + rand * m_level.Width, m_level.Top + scale, 0));
            }

            case AreaType.bottom:
            {
                return(new Vector3(m_level.Left + rand * m_level.Width, m_level.Bottom - scale, 0));
            }

            case AreaType.right:
            {
                return(new Vector3(m_level.Right + scale, m_level.Bottom + rand * m_level.Height, 0));
            }

            case AreaType.left:
            {
                return(new Vector3(m_level.Left - scale, m_level.Bottom + rand * m_level.Height, 0));
            }
            }

            throw Assert.CreateException();
        }
Beispiel #2
0
        private void SpawnUFO()
        {
            UFO ufo = m_ufoFactory.Create();

            var ufoType = RandomEnum <UFOType> .Get();

            var score   = m_ufoDataFactory.GetScore(ufoType);
            var ufoData = m_ufoDataFactory.GetData(ufoType);

            ufo.Score = score;
            ufo.transform.position = GetRandomStartPosition(ufo.Scale);
        }
        private void SpawnAsteroid()
        {
            var random_AsteroidType = RandomEnum <AsteroidType> .Get();

            var data = m_asteroidDataFactoryInterface.GetData(random_AsteroidType);

            if (data == null || random_AsteroidType == AsteroidType.none)
            {
                return;
            }

            Asteroid asteroid = m_asteroidFactory.Create();

            InitializeAsteroid(ref asteroid, data, random_AsteroidType);
            asteroid.transform.position = GetRandomStartPosition(asteroid.ScaleFactor);
        }
Beispiel #4
0
        /// <summary>
        /// Update
        /// </summary>
        /// <param name="time">Elapsed game time</param>
        public override void Update(GameTime time)
        {
            // Target range
            int range = Game.Random.Next(Monster.SightRange);

            // Direction to face to

            while (true)
            {
                CardinalPoint direction = RandomEnum.Get <CardinalPoint>();
                if (direction == Monster.Location.Direction)
                {
                    continue;
                }

                //int dir = Dice.GetD20(1);
                Point vector = Monster.Location.Coordinate;

/*
 *                              // Depending the current direction
 *                              switch (Monster.Location.Direction)
 *                              {
 *                                      case CardinalPoint.North:
 *                                      {
 *                                              if (dir < 10)
 *                                              {
 *                                                      direction = CardinalPoint.West;
 *                                                      vector.X--;
 *                                              }
 *                                              else
 *                                              {
 *                                                      direction = CardinalPoint.East;
 *                                                      vector.X++;
 *                                              }
 *                                      }
 *                                      break;
 *                                      case CardinalPoint.South:
 *                                      {
 *                                              if (dir < 10)
 *                                              {
 *                                                      direction = CardinalPoint.East;
 *                                                      vector.X++;
 *                                              }
 *                                              else
 *                                              {
 *                                                      direction = CardinalPoint.West;
 *                                                      vector.X--;
 *                                              }
 *
 *                                      }
 *                                      break;
 *                                      case CardinalPoint.West:
 *                                      {
 *                                              if (dir < 10)
 *                                              {
 *                                                      direction = CardinalPoint.North;
 *                                                      vector.Y--;
 *                                              }
 *                                              else
 *                                              {
 *                                                      direction = CardinalPoint.South;
 *                                                      vector.Y++;
 *                                              }
 *
 *                                      }
 *                                      break;
 *                                      case CardinalPoint.East:
 *                                      {
 *                                              if (dir < 10)
 *                                              {
 *                                                      direction = CardinalPoint.South;
 *                                                      vector.Y++;
 *                                              }
 *                                              else
 *                                              {
 *                                                      direction = CardinalPoint.North;
 *                                                      vector.Y--;
 *                                              }
 *
 *                                      }
 *                                      break;
 *                              }
 */
                // Depending the current direction
                switch (direction)
                {
                case CardinalPoint.North:
                {
                    vector.Y--;
                }
                break;

                case CardinalPoint.South:
                {
                    vector.Y++;
                }
                break;

                case CardinalPoint.West:
                {
                    vector.X--;
                }
                break;

                case CardinalPoint.East:
                {
                    vector.X++;
                }
                break;
                }


                // Check the block
                Square block = Monster.Maze.GetSquare(vector);
                if (block != null)
                {
                    // Automatic direction changing
                    //Monster.Location.Direction = direction;

                    //Monster.StateManager.PushState(new MoveState(Monster, range, direction));
                    return;
                }
            }
        }