Exemple #1
0
        public TerrainInfo GetTerrainInfo(int x, int y)
        {
            var result = new TerrainInfo
            {
                X = (x/10),
                Y = (y/10)
            };

            if ( result.X+1 >= X || result.Y+1 >= Y || result.X < 0 || result.Y < 0 )
            {
                result.IsValidForPig = false;
            }
            else
            {
                result.Height = _terrainArray[result.X, result.Y]/5 ;

                result.IsValidForPig = result.Height >= 0;
            }

            return result;
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            _mouseTexture = Content.Load<Texture2D>("mouse");

            Random rnd = new Random();
            //GraphicsDevice.Viewport.TitleSafeArea.

            _terrain.X = 65;//GraphicsDevice.Viewport.TitleSafeArea.Bottom / 5;
            _terrain.Y = 65;//GraphicsDevice.Viewport.TitleSafeArea.Bottom / 5;
            _terrain.Initialize();

            foreach (var pigEntity in _pigs)
            {
                var terrainInfo = new TerrainInfo { IsValidForPig = false };

                Vector2 pigPos = new Vector2();
                while (!terrainInfo.IsValidForPig)
                {
                    pigPos = new Vector2(rnd.Next(0, 645),
                       rnd.Next(0, 645));

                    terrainInfo = _terrain.GetTerrainInfo((int)pigPos.X, (int)pigPos.Y);
                }
                pigEntity.Position = pigPos;
                pigEntity.PigViewPort = GraphicsDevice.Viewport;
            }
        }