Esempio n. 1
0
        public void HandleInput(SGDE.Game game, InputComponent input)
        {
            switch (input.Type)
            {
                case InputType.Keyboard:
                    SGDE.Input.Keyboard keyboard = (SGDE.Input.Keyboard)input;
                    if (keyboard.IsKeyPressed(Keys.Left))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(5, 0));
                        }
                        else
                        {
                            this.Translate(-5, 0);
                        }
                    }
                    else if (keyboard.IsKeyPressed(Keys.Right))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(-5, 0));
                        }
                        else
                        {
                            this.Translate(5, 0);
                        }
                    }
                    if (keyboard.IsKeyPressed(Keys.Up))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(0, 5));
                        }
                        else
                        {
                            this.Translate(0, -5);
                        }
                    }
                    else if (keyboard.IsKeyPressed(Keys.Down))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(0, -5));
                        }
                        else
                        {
                            this.Translate(0, 5);
                        }
                    }

                    if (keyboard.IsKeyPressed(Keys.O))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            this.Scale(0.9f);
                        }
                        else
                        {
                            game.CameraControl.Scale(0.9f);
                        }
                    }
                    else if (keyboard.IsKeyPressed(Keys.I))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            this.Scale(1.1f);
                        }
                        else
                        {
                            game.CameraControl.Scale(1.1f);
                        }
                    }
                    if (keyboard.IsKeyPressed(Keys.R))
                    {
                        game.CameraControl.Rotate((float)(Math.PI / 32));
                    }
                    else if (keyboard.IsKeyPressed(Keys.L))
                    {
                        game.CameraControl.Rotate(-(float)(Math.PI / 32));
                    }

                    if (keyboard.IsKeyClicked(Keys.Escape))
                    {
                        game.Exit();
                    }
                    if (keyboard.IsKeyClicked(Keys.C))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    break;
                case InputType.GamePad:
                    SGDE.Input.GamePad gamePad = (SGDE.Input.GamePad)input;
                    Vector2 leftStick = gamePad.GetThumbstickPosition(GamePadComponent.LeftStick);
                    if (leftStick != Vector2.Zero)
                    {
                        this.Translate(leftStick.X * 5, -leftStick.Y * 5);
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.Back))
                    {
                        game.Exit();
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.A))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    break;
                case InputType.Mouse:
                    SGDE.Input.Mouse mouse = (SGDE.Input.Mouse)input;
                    Vector2 diff = mouse.PositionDiff;
                    this.Translate(diff.X, diff.Y);
                    break;
            }
        }
Esempio n. 2
0
        public void HandleInput(SGDE.Game game, InputComponent input)
        {
            SGDE.Input.Keyboard keyboard = (SGDE.Input.Keyboard)input;

            if (!staggered)
            {
                if (keyboard.IsKeyPressed(Keys.Left))
                {
                    this.Translate(-5, 0);
                    if (dir != PlayerDirection.Left)
                    {
                        if (!knockBack)
                            this.SpriteImage.SetAnimation("WalkLeft");
                        else
                            this.SpriteImage.SetAnimation("KnockBackLeft");
                        dir = PlayerDirection.Left;
                    }
                }
                else if (keyboard.IsKeyPressed(Keys.Right))
                {
                    this.Translate(5, 0);
                    if (dir != PlayerDirection.Right)
                    {
                        if (!knockBack)
                            this.SpriteImage.SetAnimation("WalkRight");
                        else
                            this.SpriteImage.SetAnimation("KnockBackRight");
                        dir = PlayerDirection.Right;
                    }
                }
                else
                {
                    this.SetVelocity(0, this.GetVelocity().Y);
                    switch (dir)
                    {
                        case PlayerDirection.Right:
                            if (!knockBack)
                                this.SpriteImage.SetAnimation("StandRight");
                            else
                                this.SpriteImage.SetAnimation("KnockBackRight");
                            dir = PlayerDirection.StandingRight;
                            break;
                        case PlayerDirection.Left:
                            if (!knockBack)
                                this.SpriteImage.SetAnimation("StandLeft");
                            else
                                this.SpriteImage.SetAnimation("KnockBackLeft");
                            dir = PlayerDirection.StandingLeft;
                            break;
                    }
                }

                if (keyboard.IsKeyPressed(Keys.Up))
                {
                    if (onGround && this.GetCollisionUnit().HasCollisions())
                    {
                        this.SetVelocity(this.GetVelocity().X, -10.0f);
                        onGround = false;
                    }
                }

                if (keyboard.IsKeyPressed(Keys.Z) && Game1.superJumpActive)
                {
                    if (onGround && this.GetCollisionUnit().HasCollisions())
                    {
                        this.SetVelocity(this.GetVelocity().X, -13.0f);
                        onGround = false;
                    }
                }
            }
            if (keyboard.IsKeyPressed(Keys.Escape))
                game.Exit();
        }
Esempio n. 3
0
        public void HandleInput(SGDE.Game game, InputComponent input)
        {
            switch (input.Type)
            {
                case InputType.Keyboard:
                    SGDE.Input.Keyboard keyboard = (SGDE.Input.Keyboard)input;

                    if (keyboard.IsKeyPressed(Keys.Left))
                    {
                        this.Translate(-5, 0);
                    }
                    if (keyboard.IsKeyPressed(Keys.Right))
                    {
                        this.Translate(5, 0);
                    }
                    if (keyboard.IsKeyPressed(Keys.Up))
                    {
                        this.Translate(0, -5);
                    }
                    if (keyboard.IsKeyPressed(Keys.Down))
                    {
                        this.Translate(0, 5);
                    }
                    if (keyboard.IsKeyClicked(Keys.Escape))
                    {
                        game.Exit();
                    }
                    if (keyboard.IsKeyClicked(Keys.C))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    if (keyboard.IsKeyPressed(Keys.A))
                    {
                        this.Rotate(-1.0f);
                    }
                    if (keyboard.IsKeyPressed(Keys.D))
                    {
                        this.Rotate(1.0f);
                    }
                    if (keyboard.IsKeyPressed(Keys.W))
                    {
                        this.Scale(new Vector2(0.01f, 0.01f));
                    }
                    if (keyboard.IsKeyPressed(Keys.X))
                    {
                        this.Scale(new Vector2(-0.01f, -0.01f));
                    }
                    if (keyboard.IsKeyClicked(Keys.Space))
                    {
                        this.ShootProjectile();
                    }

                    break;
                case InputType.GamePad:
                    SGDE.Input.GamePad gamePad = (SGDE.Input.GamePad)input;
                    Vector2 leftThumb = gamePad.GetThumbstickPosition(GamePadComponent.LeftStick);

                    if (leftThumb != Vector2.Zero)
                    {
                        this.Translate(leftThumb.X * 5, leftThumb.Y * -5);
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.Back))
                    {
                        game.Exit();
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.A))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    break;
            }
        }