コード例 #1
0
ファイル: GameObject.cs プロジェクト: yyyejianbin9527/defense
        public virtual void Draw(float fDeltaTime)
        {
            if (m_bTransformDirty)
            {
                RebuildWorldTransform();
            }


            foreach (ModelMesh mesh in m_Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World      = m_ModelBones[mesh.ParentBone.Index] * m_WorldTransform;
                    effect.View       = GameState.Get().CameraMatrix;
                    effect.Projection = GraphicsManager.Get().Projection;
                    effect.EnableDefaultLighting();
                    effect.AmbientLightColor         = new Vector3(1.0f, 1.0f, 1.0f);
                    effect.DirectionalLight0.Enabled = false;
                    effect.DirectionalLight1.Enabled = false;
                    effect.DirectionalLight2.Enabled = false;
                    effect.PreferPerPixelLighting    = true;
                }
                mesh.Draw();
            }
        }
コード例 #2
0
        public void SetupGameplay()
        {
            ClearGameObjects();
            m_UIStack.Clear();
            m_UIGameplay = new UI.UIGameplay(m_Game.Content);
            m_UIStack.Push(m_UIGameplay);

            m_bPaused = false;
            m_Speed   = eGameSpeed.Normal;
            m_Camera.ResetCamera();
            GraphicsManager.Get().ResetProjection();
            m_SelectedTile = null;
            m_CurrentTile  = null;

            m_Timer.RemoveAll();

            Money         = Balance.StartingMoney;
            Life          = Balance.StartingLife;
            m_WaveNumber  = 0;
            m_bWaveActive = false;
            SpawnWorld();

            // Start the timer for the first wave
            m_Timer.AddTimer("StartWave", Balance.FirstWaveTime, StartWave, false);
            m_bCanPlayAlarm = true;
        }
コード例 #3
0
        public Ray CalculateMouseRay()
        {
            // create 2 positions in screenspace using the cursor position. 0 is as
            // close as possible to the camera, 1 is as far away as possible.
            Vector3 nearSource = new Vector3(m_MousePos.X, m_MousePos.Y, 0f);
            Vector3 farSource  = new Vector3(m_MousePos.X, m_MousePos.Y, 1f);

            // use Viewport.Unproject to tell what those two screen space positions
            // would be in world space. we'll need the projection matrix and view
            // matrix, which we have saved as member variables. We also need a world
            // matrix, which can just be identity.

            GraphicsDevice GraphicsDevice   = GraphicsManager.Get().GraphicsDevice;
            Matrix         projectionMatrix = GraphicsManager.Get().Projection;
            Matrix         viewMatrix       = GameState.Get().CameraMatrix;
            Vector3        nearPoint        = GraphicsDevice.Viewport.Unproject(nearSource,
                                                                                projectionMatrix, viewMatrix, Matrix.Identity);

            Vector3 farPoint = GraphicsDevice.Viewport.Unproject(farSource,
                                                                 projectionMatrix, viewMatrix, Matrix.Identity);

            // find the direction vector that goes from the nearPoint to the farPoint
            // and normalize it....
            Vector3 direction = farPoint - nearPoint;

            direction.Normalize();

            // and then create a new ray using nearPoint as the source.
            return(new Ray(nearPoint, direction));
        }
コード例 #4
0
        public void UpdateMouse(float fDeltaTime)
        {
            m_PrevMouse = m_CurrMouse;
            m_CurrMouse = Mouse.GetState();

            m_DeviceMousePos.X = m_CurrMouse.X;
            m_DeviceMousePos.Y = m_CurrMouse.Y;

            m_ActualMousePos = m_DeviceMousePos;
            m_MousePos       = m_ActualMousePos;

            ClampMouse();

            // Check for click
            if (JustPressed(m_PrevMouse.LeftButton, m_CurrMouse.LeftButton))
            {
                // If the UI doesn't handle it, send it to GameState
                if (GameState.Get().UICount == 0 ||
                    !GameState.Get().GetCurrentUI().MouseClick(m_MousePos))
                {
                    GameState.Get().MouseClick(m_MousePos);
                }
            }

            // Do camera pans and zoom
            if (GameState.Get().State == eGameState.Gameplay &&
                !GameState.Get().IsPaused)
            {
                if (m_MousePos.X < GlobalDefines.fCameraScroll)
                {
                    GameState.Get().Camera.AddToPan(Vector3.Left);
                }
                else if (m_MousePos.X > (GraphicsManager.Get().Width -
                                         GlobalDefines.fCameraScroll))
                {
                    GameState.Get().Camera.AddToPan(Vector3.Right);
                }

                if (m_MousePos.Y < GlobalDefines.fCameraScroll)
                {
                    GameState.Get().Camera.AddToPan(Vector3.Forward);
                }
                else if (m_MousePos.Y > (GraphicsManager.Get().Height -
                                         GlobalDefines.fCameraScroll))
                {
                    GameState.Get().Camera.AddToPan(Vector3.Backward);
                }

                int iWheelChange = m_CurrMouse.ScrollWheelValue - m_PrevMouse.ScrollWheelValue;
                if (iWheelChange != 0)
                {
                    // No delta time modifier because iWheelChange will vary based on FPS
                    float fZoomChange           = -1.0f * iWheelChange * GlobalDefines.fCameraZoomSpeed;
                    GraphicsManager.Get().Zoom += fZoomChange;
                }
            }
        }
コード例 #5
0
 public void RemoveGameObject(GameObject o, bool bRemoveFromList = true)
 {
     o.Enabled = false;
     o.Unload();
     GraphicsManager.Get().RemoveGameObject(o);
     if (bRemoveFromList)
     {
         m_GameObjects.Remove(o);
     }
 }
コード例 #6
0
ファイル: Pathfinder.cs プロジェクト: yyyejianbin9527/defense
        // Debug function that draws the path
        public void DrawPath(SpriteBatch batch)
        {
            PathNode CurrentNode = GlobalPath;

            while (CurrentNode != null && CurrentNode.tile != GlobalGoalTile)
            {
                // Draw a line from the current tile to the next one
                GraphicsManager.Get().DrawLine3D(batch, 2.0f, Color.White,
                                                 CurrentNode.tile.Position, CurrentNode.parent.tile.Position);

                CurrentNode = CurrentNode.parent;
            }
        }
コード例 #7
0
ファイル: Game1.cs プロジェクト: yyyejianbin9527/defense
 public Game1()
 {
     IsFixedTimeStep = false;
     GraphicsManager.Get().Start(this);
     if (DebugDefines.bShowWindowsMouseCursor)
     {
         IsMouseVisible = true;
     }
     else
     {
         IsMouseVisible = false;
     }
     Window.Title          = "__Defense";
     Content.RootDirectory = "Content";
 }
コード例 #8
0
 private void ClampMouse()
 {
     if (m_MousePos.X < 0)
     {
         m_MousePos.X = 0;
     }
     if (m_MousePos.Y < 0)
     {
         m_MousePos.Y = 0;
     }
     if (m_MousePos.X > GraphicsManager.Get().Width)
     {
         m_MousePos.X = GraphicsManager.Get().Width - GlobalDefines.iMouseCursorSize / 4;
     }
     if (m_MousePos.Y > GraphicsManager.Get().Height)
     {
         m_MousePos.Y = GraphicsManager.Get().Height - GlobalDefines.iMouseCursorSize / 4;
     }
 }
コード例 #9
0
 public void SpawnGameObject(GameObject o)
 {
     o.Load();
     m_GameObjects.AddLast(o);
     GraphicsManager.Get().AddGameObject(o);
 }
コード例 #10
0
ファイル: Game1.cs プロジェクト: yyyejianbin9527/defense
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     GraphicsManager.Get().LoadContent();
     SoundManager.Get().LoadContent(Content);
 }
コード例 #11
0
ファイル: Game1.cs プロジェクト: yyyejianbin9527/defense
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsManager.Get().Draw((float)gameTime.ElapsedGameTime.TotalSeconds);

            base.Draw(gameTime);
        }