コード例 #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            var           dt    = gameTime.ElapsedGameTime.TotalSeconds;
            KeyboardState state = Keyboard.GetState();

            // TODO: Add your update logic here
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                plane.MoveRight(300 * dt);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                plane.MoveLeft(300 * dt);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                plane.MoveUp(300 * dt);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                plane.MoveDown(300 * dt);
            }

            if (state.IsKeyDown(Keys.Space) && !keyboardState.IsKeyDown(Keys.Space))
            {
                plane.Fire();
            }
            plane.LaunchBullet();

            keyboardState = state;
            base.Update(gameTime);
        }
コード例 #2
0
ファイル: HUD.cs プロジェクト: tioazis/unity-pesawat
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKey(KeyCode.UpArrow))
     {
         pesawat.MoveUp();
     }
     if (Input.GetKey(KeyCode.DownArrow))
     {
         pesawat.MoveDown();
     }
     if (Input.GetKey(KeyCode.LeftArrow))
     {
         pesawat.MoveLeft();
     }
     if (Input.GetKey(KeyCode.RightArrow))
     {
         pesawat.MoveRight();
     }
     if (Input.GetKey(KeyCode.Space))
     {
         pesawat.Attack();
     }
 }
コード例 #3
0
 // Update is called once per frame
 void Update()
 {
     if (PencetAtas)
     {
         pesawat.MoveUp();
     }
     if (PencetBawah)
     {
         pesawat.MoveDown();
     }
     if (PencetKanan)
     {
         pesawat.MoveRight();
     }
     if (PencetKiri)
     {
         pesawat.MoveLeft();
     }
     if (PencetTembak)
     {
         pesawat.Attack();
     }
 }