/// <summary>
 /// Use default input, bypass plugin input
 /// </summary>
 public static void useDefaultInput()
 {
     if (!isIAPInitComplete())
     {
         return;
     }
     OuyaUnityPlugin.useDefaultInput();
     OuyaInput.ClearAxes();
     OuyaInput.ClearButtons();
     OuyaInput.ClearButtonStates();
     OuyaInput.ClearButtonStates();
     OuyaInput.UpdateInputFrame();
     s_useDefaultInput = true;
 }
Exemple #2
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)
        {
            //Log.Info(TAG, string.Format("BUTTON_O is {0}", OuyaInput.GetButton(OuyaController.BUTTON_O)));

            if (OuyaInput.GetButtonUp(0, OuyaController.BUTTON_A))
            {
                Exit();
            }

            // TODO: Add your update logic here
            m_focusManager.UpdateFocus();

            foreach (ButtonSprite button in m_buttons)
            {
                // button is active if the selected button is true
                button.m_isActive = (button == m_focusManager.SelectedButton);
            }

            if (OuyaInput.GetButtonUp(OuyaController.BUTTON_MENU))
            {
                m_debugText = "Pause button detected.";
                m_focusManager.SelectedButton = BtnPause;
            }

            if (OuyaInput.GetButtonUp(OuyaController.BUTTON_O))
            {
                if (m_focusManager.SelectedButton == BtnRequestProducts)
                {
                    s_productIndex = 0;
                    s_products.Clear();
                    m_debugText = "Requesting products...";
                    Activity1.RequestProducts();
                }
                else if (m_focusManager.SelectedButton == BtnRequestPurchase)
                {
                    if (s_productIndex < s_products.Count)
                    {
                        Purchasable purchasable = new Purchasable(s_products [s_productIndex].Identifier);
                        m_debugText = "Requesting purchase...";
                        Activity1.RequestPurchase(purchasable);
                    }
                    else
                    {
                        m_debugText = "Be sure to request products to select a purchase...";
                    }
                }
                else if (m_focusManager.SelectedButton == BtnRequestReceipts)
                {
                    m_debugText = "Requesting receipts...";
                    Activity1.RequestReceipts();
                }
                else if (m_focusManager.SelectedButton == BtnRequestGamerInfo)
                {
                    m_debugText = "Requesting GamerInfo...";
                    Activity1.RequestGamerInfo();
                }
                else if (m_focusManager.SelectedButton == BtnExit)
                {
                    m_debugText = "Exiting...";
                    Activity1.Quit();
                }
                else if (m_focusManager.SelectedButton == BtnPause)
                {
                    m_debugText = "Pause button detected...";
                    m_focusManager.SelectedButton = BtnPause;
                }
            }

            if (m_focusManager.SelectedButton == BtnRequestProducts ||
                m_focusManager.SelectedButton == BtnRequestPurchase)
            {
                if (OuyaInput.GetButtonUp(OuyaController.BUTTON_DPAD_UP))
                {
                    if (s_productIndex > 0)
                    {
                        --s_productIndex;
                    }
                }
                if (OuyaInput.GetButtonUp(OuyaController.BUTTON_DPAD_DOWN))
                {
                    if ((s_productIndex + 1) < s_products.Count)
                    {
                        ++s_productIndex;
                    }
                }
            }

            base.Update(gameTime);

            OuyaInput.ClearButtonStates();
        }
        /// <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)
        {
            #region Frames per second

            if (_mTimer < DateTime.Now)
            {
                _mFramesPerSecond = _mFrames;
                _mFrames          = 0;
                _mTimer           = DateTime.Now + TimeSpan.FromSeconds(1);
            }
            else
            {
                ++_mFrames;
            }

            #endregion

            #region Render to Light Render Texture
            GraphicsDevice.SetRenderTarget(_mLightRenderTarget);

            _sGraphics.GraphicsDevice.Clear(Color.White);

            _mSpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
                                SamplerState.LinearClamp, DepthStencilState.Default,
                                RasterizerState.CullNone);

            foreach (Projectile projectile in _sProjectiles)
            {
                projectile.DrawLight(_mSpriteBatch);
            }

            foreach (Player player in _mPlayers)
            {
                player.DrawLight(_mSpriteBatch);
            }

            _mSpriteBatch.End();
            #endregion

            #region Render to Render Texture
            GraphicsDevice.SetRenderTarget(_mRenderTarget);

            _sGraphics.GraphicsDevice.Clear(Color.Green);

            _mSpriteBatch.Begin();
            foreach (Projectile projectile in _sProjectiles)
            {
                projectile.Draw(_mSpriteBatch, _mFont, gameTime);
            }
            foreach (Player player in _mPlayers)
            {
                player.Draw(_mSpriteBatch, _mFont, gameTime);
            }
            _mSpriteBatch.End();
            #endregion

            GraphicsDevice.SetRenderTarget(null);

            // draw through effect
            _mSpriteBatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, _mLightingEffect, Matrix.Identity);
            _mSpriteBatch.Draw(_mRenderTarget, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            _mSpriteBatch.End();

            //draw light source
            _mSpriteBatch.Begin();
            _mSpriteBatch.Draw(_mLightRenderTarget, Vector2.Zero, new Rectangle(0, 0, 200, 400), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            _mSpriteBatch.Draw(_mRenderTarget, new Vector2(200, 0), new Rectangle(200, 0, 200, 400), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            _mSpriteBatch.End();

            // set sampler
            GraphicsDevice.Textures[1] = _mLightRenderTarget;
            _mLightingEffect.Parameters["LightSampler"].SetValue(_mLightRenderTarget);

            _mSpriteBatch.Begin();
            _mSpriteBatch.DrawString(_mFont,
                                     string.Format("Hello from MonoGame: Projectiles={0} FPS={1:F2}", _sProjectiles.Count, _mFramesPerSecond),
                                     new Vector2(Window.ClientBounds.Width / 2 - 200, Window.ClientBounds.Height / 2 - 40), Color.White);
            _mSpriteBatch.End();

            OuyaInput.ClearButtonStates();

            base.Draw(gameTime);

            while (_sProjectiles.Count > 0 &&
                   _sProjectiles[0]._mLifeTime < 0)
            {
                _sProjectiles.RemoveAt(0);
            }
        }