/// <summary>
        /// Checks the mouse's position set in the in-game world plane.
        /// </summary>
        /// <param name="mousePosition">Mouse's position on screen</param>
        /// <param name="camera">Camera object</param>
        /// <param name="device">Graphics device used in rendering</param>
        /// <returns></returns>
        public static Vector3 getMouseWorldPosition(Vector2 mousePosition,CameraAndLights camera,GraphicsDevice device)
        {
            Vector3 nearsource = new Vector3(mousePosition,0f);
            Vector3 farsource = new Vector3(mousePosition,CameraAndLights.nearClip);

            Vector3 nearPoint = device.Viewport.Unproject(nearsource,
                                                          camera.projectionMatrix,
                                                          camera.viewMatrix,
                                                          Matrix.Identity);

            Vector3 farPoint = device.Viewport.Unproject(farsource,
                                                         camera.projectionMatrix,
                                                         camera.viewMatrix,
                                                         Matrix.Identity);

            // Create a ray from the near clip plane to the far clip plane.
            Vector3 direction = farPoint - nearPoint;
            direction.Normalize();
            Ray pickRay = new Ray(nearPoint,direction);

            Plane floor = new Plane(new Vector3(0f,1f,0f),0f);

            float denominator = Vector3.Dot(floor.Normal,pickRay.Direction);
            float numerator = Vector3.Dot(floor.Normal,pickRay.Position) + floor.D;
            float dist = -(numerator / denominator);

            Vector3 mouseWorldPos = nearPoint + direction * dist;

            return mouseWorldPos * new Vector3(1f,0f,1f);
        }
        public override void Initialize()
        {
            camera = _gameState.camera;
            effects = _game.Services.GetService(typeof(Effect)) as Effect;
            graphics = _game.Graphics;

            DrawOrder = drawLayer;

            base.Initialize();
        }
 public InGame(SwordeningGame game)
     : base(game)
 {
     Hero = new Wizard(game,this,Vector3.Zero);
     camera = new CameraAndLights();
     _saveGame = new SaveGame(this);
     mapGrid = new MapGrid(_game,this);
     liveGrid = new LiveGrid(_game,ref mapGrid);
     monsters = new List<Creature>();
     camera.cameraPos = Vector3.Zero;
     gamemusic = _game.musics["gamemusic"];
     difficultycounter = 0;
     spawntime = 1.0f;
 }
        /// <summary>
        /// Separated from constructor for deserialization.
        /// </summary>
        /// <param name="game">the XNA game</param>
        /// <param name="gameState">InGame gamestate</param>
        /// <param name="textures">ground texture</param>
        public void Initialize(SwordeningGame game, InGame gameState)
        {
            _game = game;
            _graphics = game.Graphics;
            _gameState = gameState;
            camera = gameState.camera;
            effects = game.Services.GetService(typeof(Effect)) as Effect;
            _tileVertexBufferDict = new Dictionary<TileType,VertexBuffer>();
            _textures = new Dictionary<TileType,Texture2D>();

            SetUpTextures();
            SetUpVertices();
        }