示例#1
0
        public void Update(GameTime gameTime, InputManager inputManager)
        {
            if (axis == 1)
            {
                if (inputManager.KeyPressed(Keys.Right, Keys.D))
                {
                    itemNumber++;
                }
                else if (inputManager.KeyPressed(Keys.Left, Keys.A))
                {
                    itemNumber--;
                }
            }
            else
            {
                if (inputManager.KeyPressed(Keys.Down, Keys.S))
                {
                    itemNumber++;
                }
                else if (inputManager.KeyPressed(Keys.Up, Keys.W))
                {
                    itemNumber--;
                }
            }

            if (inputManager.KeyPressed(Keys.Enter, Keys.Space))
            {
                if (linkType[itemNumber] == "Screen")
                {
                    Type newClass = Type.GetType("Hack_Attack." + linkID[itemNumber]);
                    ScreenManager.Instance.AddScreen((GameScreen)Activator.CreateInstance(newClass), inputManager);
                }
            }

            if (itemNumber < 0)
            {
                itemNumber = 0;
            }
            else if (itemNumber > menuItems.Count - 1)
            {
                itemNumber = menuItems.Count - 1;
            }

            for (int i = 0; i < animation.Count; i++)
            {
                for (int j = 0; j < animation[i].Count; j++)
                {
                    if (itemNumber == i)
                    {
                        animation[i][j].IsActive = true;
                    }
                    else
                    {
                        animation[i][j].IsActive = false;
                    }

                    animation[i][j].Update(gameTime);
                }
            }
        }
示例#2
0
        public override void Update(GameTime gameTime, InputManager input, Collision col, Layer layer)
        {
            base.Update(gameTime, input, col, layer);
            moveAnimation.DrawColor = Color.White;
            moveAnimation.IsActive  = true;

            //BULLETS
            if (input.KeyPressed(Keys.Space))
            {
                Bullet bullet = new Bullet();
                bullet.position.Y = position.Y;
                if (moveAnimation.CurrentFrame.Y == 0)
                {
                    bullet.direction  = true;
                    bullet.position.X = position.X + 32;
                }
                else
                {
                    bullet.direction  = false;
                    bullet.position.X = position.X - 10;
                }

                bullets.Add(bullet);
            }

            if (input.KeyDown(Keys.LeftShift))
            {
                time = false;
            }
            else
            {
                time = true;
            }

            if (time)
            {
                for (int i = 0; i < bullets.Count; i++)
                {
                    float x = bullets[i].position.X;
                    if (bullets[i].direction)
                    {
                        x += bulletSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        x -= bulletSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    bullets[i].position = new Vector2(x, bullets[i].position.Y);
                }
            }


            if (input.KeyDown(Keys.Right, Keys.D))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
                velocity.X = moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else if (input.KeyDown(Keys.Left, Keys.A))
            {
                moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
                velocity.X = -moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else
            {
                moveAnimation.IsActive = false;
                velocity.X             = 0;
            }

            if (input.KeyDown(Keys.Up, Keys.W) && !activateGravity)
            {
                activateGravity = true;
                velocity.Y      = -jumpSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (activateGravity)
            {
                velocity.Y += gravity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }
            else
            {
                velocity.Y = 0;
            }

            position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;

            moveAnimation.Position = position;
            ssAnimation.Update(gameTime, ref moveAnimation);

            Camera.Instance.SetFocalPoint(new Vector2(Position.X, ScreenManager.Instance.Dimensions.Y / 2));
        }