Exemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        ///
        /// Kaushik: The update method is a little skimpy right now, primarily
        /// because we'll be adding in alot more of the specific code to
        /// handle things in here. What I like to do is to seperate the
        /// "Update" function into several child functions for the seperate
        /// game-states - there'll be a menu update function, a game update
        /// function, and so on. What's here is the basics I needed to get
        /// started.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            //Handle input and output
            inHandler.Update(gameTime);
            if (inHandler.isKeyDown(FlightSimLibrary.Action.Up))
            {
                playerShip.rotation = Quaternion.CreateFromAxisAngle(playerShip.rightVector, 0.1f) * playerShip.rotation;
            }
            else if (inHandler.isKeyDown(FlightSimLibrary.Action.Down))
            {
                playerShip.rotation = Quaternion.CreateFromAxisAngle(playerShip.rightVector, -0.1f) * playerShip.rotation;
            }
            if (inHandler.isKeyDown(FlightSimLibrary.Action.Left))
            {
                playerShip.rotation = Quaternion.CreateFromAxisAngle(playerShip.forwardVector, 0.1f) * playerShip.rotation;
            }
            else if (inHandler.isKeyDown(FlightSimLibrary.Action.Right))
            {
                playerShip.rotation = Quaternion.CreateFromAxisAngle(playerShip.forwardVector, -0.1f) * playerShip.rotation;
            }
            if (inHandler.isKeyDown(FlightSimLibrary.Action.Accelerate))
            {
                playerShip.Accelerate();
            }
            myPos  = Vector3.Transform(baseViewPos, Matrix.CreateFromQuaternion(playerShip.rotation));
            myPos += playerShip.getCoords();
            camUp  = Vector3.Transform(Vector3.UnitZ, Matrix.CreateFromQuaternion(playerShip.rotation));
            //lookPos = Vector3.Transform(lookPos, Matrix.CreateTranslation(-playerShip.getCoords()));
            View = Matrix.CreateLookAt(myPos, playerShip.getCoords(), camUp);

            //if (inHandler.isKeyDown(FlightSimLibrary.Action.Up))
            //    myPos -= 0.1f * Vector3.UnitX;
            //else if (inHandler.isKeyDown(FlightSimLibrary.Action.Down))
            //    myPos += 0.1f * Vector3.UnitX;
            //if (inHandler.isKeyDown(FlightSimLibrary.Action.Left))
            //    myPos -= 0.1f * Vector3.UnitY;
            //else if (inHandler.isKeyDown(FlightSimLibrary.Action.Right))
            //    myPos += 0.1f * Vector3.UnitY;
            //Set the view and projection matricies
            //View = Matrix.CreateLookAt(myPos, Vector3.Zero, Vector3.UnitZ);//Typically in game 3space, Y is up - this is more of that bethesda influence, as in their games Z is always up.
            Proj = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 2, graphics.PreferredBackBufferWidth / (float)graphics.PreferredBackBufferHeight, 0.1f, 10000.0f);
            //Perform update operations
            foreach (GameObject g in mainGameObjects)
            {
                g.Update(gameTime);
            }
            mainDrawCommands.Clear();//Clears the draw queue
            foreach (GameObject g in mainGameObjects)
            {
                mainDrawCommands.AddRange(g.GetDrawCommands());
            }

            base.Update(gameTime);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Controls the entity associated with this behavior.
        /// This method is invoked for each game loop.
        /// </summary>
        /// <param name="gameTime">Current game time.</param>
        public override void Update(GameTime gameTime)
        {
            Input.Update();

            Ship.Rotate(gameTime, Input.Rotate);
            Ship.Accelerate(gameTime, Input.Thrust);

            Ship.MainWeapon.IsActive    = Input.FireMainWeapon;
            Ship.SpecialWeapon.IsActive = Input.FireSpecialWeapon;
        }
Exemplo n.º 3
0
        private static void TestShip()
        {
            OilMotor motor = new OilMotor(550);
            Ship     ship  = new Ship(340, motor);

            Console.WriteLine("Ship:");
            ship.Start();
            ship.Accelerate(10);
            ship.Decelerate(5);
            Console.WriteLine(ship.ToString());

            ship.Stop();
        }
Exemplo n.º 4
0
    void Update()
    {
        if (inputType == PlayerInputType.Keyboard)
        {
            playerShip.Rotate(inputHandler.GetRotationInput());
        }
        else
        {
            playerShip.RotateTowards(inputHandler.GetMouseInWorldPosition());
        }
        if (inputHandler.IsForwardInputDown())
        {
            playerShip.Accelerate();
        }

        if (inputHandler.IsFireInputDown())
        {
            playerShip.Fire();
        }
    }
Exemplo n.º 5
0
 void KeyBoardControl(Ship s)
 {
     //W
     if (Input.GetKeyDown(KeyCode.W))
     {
         s.stopped  = false;
         framesHeld = 0;
         s.Accelerate();
     }
     if (Input.GetKey(KeyCode.W))
     {
         if (s.stopped == true && framesHeld <= framesBeforeLaunch)
         {
             framesHeld++;
         }
         else
         {
             framesHeld = 0;
             s.stopped  = false;
             s.Accelerate();
         }
     }
     //A
     if (Input.GetKeyDown(KeyCode.A))
     {
         s.TurnLeft();
     }
     if (Input.GetKey(KeyCode.A))
     {
         s.TurnLeft();
     }
     if (Input.GetKeyUp(KeyCode.A))
     {
         s.turningSpeed = 0;
     }
     //S
     if (Input.GetKeyDown(KeyCode.S))
     {
         s.stopped  = false;
         framesHeld = 0;
         s.Astern();
     }
     if (Input.GetKey(KeyCode.S))
     {
         if (s.stopped == true && framesHeld <= framesBeforeLaunch)
         {
             framesHeld++;
         }
         else
         {
             framesHeld = 0;
             s.stopped  = false;
             s.Astern();
         }
     }
     //D
     if (Input.GetKeyDown(KeyCode.D))
     {
         s.TurnRight();
     }
     if (Input.GetKey(KeyCode.D))
     {
         s.TurnRight();
     }
     if (Input.GetKeyUp(KeyCode.D))
     {
         s.turningSpeed = 0;
     }
     //1
     if (Input.GetKeyDown(KeyCode.Alpha1))
     {
         weaponNumber2 = 1;
     }
     //2
     if (Input.GetKeyDown(KeyCode.Alpha2))
     {
         weaponNumber2 = 2;
     }
 }