コード例 #1
0
        public void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Enter))
            {
                _game.GameManager.ParticleManager.EmitPlayerDestroyedParticles(Position());
            }

            if (InputManager.KeyPressed(Keys.Z))
            {
                if (_game.Camera.Zoom == 1f)
                {
                    _game.Camera.ZoomTo(5f, 0.5, Position());
                }
                else
                {
                    _game.Camera.ZoomTo(1f, 0.5, Position());
                }
            }

            if (_invincibleTimer.TotalMilliseconds > 0)
            {
                _invincibleTimer -= gameTime.ElapsedGameTime;
            }
            else
            {
                Invincible = false;
            }

            CurrentAnimator.Update(gameTime.ElapsedGameTime.Milliseconds);

            _hitboxSprite.Position = _hitbox.GetCenter();

#if ANDROID
            UpdatePositionFromTouch(gameTime);
            //UpdateAnimationFromTouch();
#else
            UpdatePositionFromKeyboard(gameTime);
            //UpdateAnimationFromKeyboard();
#endif

            CheckOutOfBounds();
            UpdateShoot(gameTime);
        }
コード例 #2
0
        public override void Update(float deltaTime)
        {
            stats.OnUpdate(deltaTime);
            Vector2 scale = currentAnimator.Scale;

            if (IsPressed(Keys.Enter))
            {
                SwitchEntity();
            }
            if (IsPressed(Keys.Space))
            {
                currentAnimator.Play(GetNextAnimation());
            }
            if (IsPressed(Keys.P))
            {
                ChangeAnimationSpeed(DeltaSpeed);
            }
            if (IsPressed(Keys.O))
            {
                ChangeAnimationSpeed(-DeltaSpeed);
            }
            if (IsPressed(Keys.R))
            {
                currentAnimator.Speed = -currentAnimator.Speed;
            }
            if (IsPressed(Keys.X))
            {
                currentAnimator.Play(currentAnimator.Name);
            }
            if (IsPressed(Keys.T))
            {
                currentAnimator.Transition(GetNextAnimation(), 1000.0f);
            }
            if (IsPressed(Keys.C))
            {
                PushCharacterMap();
            }
            if (IsPressed(Keys.V))
            {
                currentAnimator.SpriteProvider.PopCharMap();
            }
            if (IsPressed(Keys.J))
            {
                currentAnimator.Color = currentAnimator.Color == Color.White ? Color.Red : Color.White;
            }

            if (IsPressed(Keys.W))
            {
                currentAnimator.Position += new Vector2(0, -10);
            }
            if (IsPressed(Keys.S))
            {
                currentAnimator.Position += new Vector2(0, 10);
            }
            if (IsPressed(Keys.A))
            {
                currentAnimator.Position += new Vector2(-10, 0);
            }
            if (IsPressed(Keys.D))
            {
                currentAnimator.Position += new Vector2(10, 0);
            }
            if (IsPressed(Keys.Q))
            {
                currentAnimator.Rotation -= 15 * (float)Math.PI / 180;
            }
            if (IsPressed(Keys.E))
            {
                currentAnimator.Rotation += 15 * (float)Math.PI / 180;
            }
            if (IsPressed(Keys.N))
            {
                currentAnimator.Scale -= new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (IsPressed(Keys.M))
            {
                currentAnimator.Scale += new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (IsPressed(Keys.F))
            {
                currentAnimator.Scale *= new Vector2(-1, 1);
            }
            if (IsPressed(Keys.G))
            {
                currentAnimator.Scale *= new Vector2(1, -1);
            }

            oldState = Keyboard.GetState();

            currentAnimator.Update(deltaTime);

            string entity = currentAnimator.Entity.Name;

            status   = string.Format("{0} : {1}", entity, currentAnimator.Name);
            metadata = "Variables:\n" + GetVarValues() + "\nTags:\n" + GetTagValues();
        }
コード例 #3
0
ファイル: ExampleGame.cs プロジェクト: warmuuh/SpriterDotNet
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            float deltaTime = gameTime.ElapsedGameTime.Ticks / (float)TimeSpan.TicksPerMillisecond;

            stats.OnUpdate(deltaTime);
            Vector2 scale = animator.Scale;

            if (WasPressed(Keys.Enter))
            {
                SwitchEntity();
            }
            if (WasPressed(Keys.Space))
            {
                animator.Play(animator.GetNextAnimation());
            }
            if (WasPressed(Keys.O))
            {
                animator.ChangeAnimationSpeed(-0.2f, 5.0f);
            }
            if (WasPressed(Keys.P))
            {
                animator.ChangeAnimationSpeed(0.2f, 5.0f);
            }
            if (WasPressed(Keys.R))
            {
                animator.Speed = -animator.Speed;
            }
            if (WasPressed(Keys.X))
            {
                animator.Play(animator.Name);
            }
            if (WasPressed(Keys.T))
            {
                animator.Transition(animator.GetNextAnimation(), 1000.0f);
            }
            if (WasPressed(Keys.C))
            {
                animator.PushNextCharacterMap();
            }
            if (WasPressed(Keys.V))
            {
                animator.PopCharacterMap();
            }
            if (WasPressed(Keys.J))
            {
                animator.Color = animator.Color == Color.White ? Color.Red : Color.White;
            }

            if (WasPressed(Keys.W))
            {
                animator.Position += new Vector2(0, -10);
            }
            if (WasPressed(Keys.S))
            {
                animator.Position += new Vector2(0, 10);
            }
            if (WasPressed(Keys.A))
            {
                animator.Position += new Vector2(-10, 0);
            }
            if (WasPressed(Keys.D))
            {
                animator.Position += new Vector2(10, 0);
            }
            if (WasPressed(Keys.Q))
            {
                animator.Rotation -= 15 * (float)Math.PI / 180;
            }
            if (WasPressed(Keys.E))
            {
                animator.Rotation += 15 * (float)Math.PI / 180;
            }
            if (WasPressed(Keys.N))
            {
                animator.Scale -= new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (WasPressed(Keys.M))
            {
                animator.Scale += new Vector2(Math.Sign(scale.X) * 0.2f, Math.Sign(scale.Y) * 0.2f);
            }
            if (WasPressed(Keys.F))
            {
                animator.Scale *= new Vector2(-1, 1);
            }
            if (WasPressed(Keys.G))
            {
                animator.Scale *= new Vector2(1, -1);
            }

            if (WasPressed(Keys.OemTilde))
            {
                (animator as MonoGameDebugAnimator).DrawSpriteOutlines = !(animator as MonoGameDebugAnimator).DrawSpriteOutlines;
            }
            if (WasPressed(Keys.OemMinus))
            {
                graphics.SynchronizeWithVerticalRetrace = !graphics.SynchronizeWithVerticalRetrace;
                graphics.ApplyChanges();
            }

            oldState = Keyboard.GetState();

            animator.Update(deltaTime);

            elapsedTime += deltaTime;
            if (elapsedTime >= 100)
            {
                elapsedTime -= 100;
                string entity = animator.Entity.Name;
                animatorInfo = string.Format("{0} : {1}", entity, animator.Name);
                metadata     = string.Format("Variables:\n{0}\nTags:\n", animator.GetVarValues(), animator.GetTagValues());
            }
        }
コード例 #4
0
        public void Update(GameTime gameTime)
        {
            if (_destroyed)
            {
                if (_game.GameManager.TransitioningToEndGame())
                {
                    _game.GameManager.ParticleManager.EmitPlayerDestroyedParticles(Position());
                    Dispose();
                }

                return;
            }

            if (_game.GameManager.CantMove())
            {
                return;
            }

            if (_ready)
            {
                var keyboardState = Keyboard.GetState();

                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    _game.GameManager.ParticleManager.EmitPlayerDestroyedParticles(Position());
                }

                if (InputManager.KeyPressed(Keys.Z))
                {
                    if (_game.Camera.Zoom == 1f)
                    {
                        _game.Camera.ZoomTo(5f, 0.5, Position());
                    }
                    else
                    {
                        _game.Camera.ZoomTo(1f, 0.5, Position());
                    }
                }

                if (!_hitTimer.Equals(TimeSpan.Zero))
                {
                    if (_hitTimer.TotalMilliseconds <= 0)
                    {
                        if (_game.SpriteBatchManager.Background != null)
                        {
                            var gradientBackground = (GradientBackground)_game.SpriteBatchManager.Background;
                            gradientBackground.ChangeGradientColors(_savedBackgroundBrightColor,
                                                                    _savedBackgroundDarkColor);

                            _backgroundColorChanged = false;
                        }
                    }
                    else
                    {
                        _hitTimer -= gameTime.ElapsedGameTime;
                    }
                }

#if ANDROID
                UpdatePositionFromTouch(gameTime);
                //UpdateAnimationFromTouch();
#else
                UpdatePositionFromKeyboard(gameTime);
                //UpdateAnimationFromKeyboard();
#endif

                UpdateShoot(gameTime);
                CheckOutOfBounds();
            }

            _hitboxSprite.Position = _hitbox.GetCenter();
            CurrentAnimator.Update(gameTime.ElapsedGameTime.Milliseconds);
        }