示例#1
0
        public void ChangeWeapon(RangeWeaponType rangeWeaponType, GameObject gameObject)
        {
            if (rangeWeaponType.Equals(currentWeapon))
            {
                return;
            }

            iRangeWeapon?.Destroy();

            switch (rangeWeaponType)
            {
            case RangeWeaponType.Pistol:
                iRangeWeapon = gameObject.AddComponent <PistolBullet>();
                aimManager.ChangeRange(1.8f);
                aimManager.ChangeAim(AimType.Line);
                break;

            case RangeWeaponType.Rifle:
                iRangeWeapon = gameObject.AddComponent <RifleBullet>();
                aimManager.ChangeRange(1.8f);
                aimManager.ChangeAim(AimType.Line);
                break;

            case RangeWeaponType.Shotgun:
                iRangeWeapon = gameObject.AddComponent <ShotgunBullet>();
                aimManager.ChangeRange(1f);
                aimManager.ChangeAim(AimType.Cone);
                break;

            case RangeWeaponType.Granade:
                aimManager.ChangeAim(AimType.CircleRange);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            currentWeapon = rangeWeaponType;
            iRangeWeapon?.Initialize(aimManager);
        }
示例#2
0
        private void SetupController()
        {
            UserInput = new UserInputController();

            UserInput.RegisterKeyPressAction(Keys.D, (Vector2 thumbStickPosition) =>
            {
                VelocityX += MovementSpeed * Globals.FixedUpdateMultiplier * Config.TIME_OFFSET;
            });

            UserInput.RegisterKeyPressAction(Keys.A, Buttons.LeftThumbstickLeft, (Vector2 thumbStickPosition) =>
            {
                VelocityX -= MovementSpeed * Globals.FixedUpdateMultiplier * Config.TIME_OFFSET;
            });

            UserInput.RegisterKeyPressAction(Keys.W, (Vector2 thumbStickPosition) =>
            {
                if (jumpCount < 2 && currentJump < MAX_JUMP)
                {
                    VelocityY   -= JUMP_FORCE;
                    currentJump += JUMP_FORCE;
                    VelocityY   -= JUMP_FORCE;
                    FallSpeed    = 0;
                    AudioEngine.Play("HeroJump", true);
                    //jumpCount++;
                }
            });

            UserInput.RegisterKeyReleaseAction(Keys.W, () =>
            {
                //if (jumpCount < 2)
                {
                    currentJump = 0;
                    jumpCount++;
                }
                if (IsOnGround)
                {
                    //jumpCount = 0;
                }
            });

            UserInput.LeftClickPressedAction = (mousePosition) =>
            {
                if (CurrentWeapon != null && !CurrentWeapon.IsEmpty() && !IsKicking)
                {
                    CurrentWeapon.TriggerPulled(Scene.Camera.ScreenToWorldSpace(mousePosition));
                }
            };

            UserInput.LeftClickUpAction = (mousePosition) =>
            {
                if (CurrentWeapon != null && !CurrentWeapon.IsEmpty() && !IsKicking)
                {
                    CurrentWeapon.TriggerReleased(Scene.Camera.ScreenToWorldSpace(mousePosition));
                }
            };


            UserInput.RightClickDownAction = (mousePosition) =>
            {
                if (CurrentFaceDirection == Direction.WEST)
                {
                    if (flying)
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickJetpackLeft");
                    }
                    else
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickLeft");
                    }
                }
                else
                {
                    if (flying)
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickJetpackRight");
                    }
                    else
                    {
                        GetComponent <AnimationStateMachine>().PlayAnimation("KickRight");
                    }
                }
            };


            /*UserInput.RegisterKeyPressAction(Keys.Down, Buttons.LeftThumbstickLeft, (Vector2 thumbStickPosition) =>
             * {
             *  VelocityY += MovementSpeed * Globals.FixedUpdateMultiplier * Config.TIME_OFFSET;
             * });*/

            UserInput.RegisterKeyPressAction(Keys.Space, (Vector2 thumbStickPosition) =>
            {
                if (Fuel > 0)
                {
                    //AudioEngine.Play("Jetpack");
                    VelocityY -= JETPACK_SPEED;
                    Fuel      -= JETPACK_SPEED;
                    flying     = true;
                    if (Fuel < 0)
                    {
                        Fuel = 0;
                    }
                }
                else
                {
                    flying = false;
                }
            });

            UserInput.RegisterKeyReleaseAction(Keys.Space, () =>
            {
                flying = false;
                //AudioEngine.Stop("Jetpack");
            });

            UserInput.RegisterMouseActions(
                () =>
            {
                NextWeapon();

                /*Timer.Repeat(300, (elapsedTime) =>
                 * {
                 *  Scene.Camera.Zoom += 0.002f * elapsedTime;
                 * });*/
            },
                () =>
            {
                PreviousWeapon();

                /*Timer.Repeat(300, (elapsedTime) =>
                 * {
                 *  Scene.Camera.Zoom -= 0.002f * elapsedTime;
                 * });*/
            }
                , 100);

            /*UserInput.RegisterKeyPressAction(Keys.Space, (Vector2 thumbStickPosition) =>
             * {
             *  if (CurrentWeapon != null && !CurrentWeapon.IsEmpty())
             *  {
             *      CurrentWeapon.TriggerPulled();
             *  }
             *
             * });
             *
             * UserInput.RegisterKeyReleaseAction(Keys.Space, () =>
             * {
             *  if (CurrentWeapon != null && !CurrentWeapon.IsEmpty())
             *  {
             *      CurrentWeapon.TriggerReleased();
             *  }
             *
             * });*/

            UserInput.RegisterKeyPressAction(Keys.D1, (Vector2 thumbStickPosition) =>
            {
                CurrentWeapon?.Destroy();
                CurrentWeapon = new Handgun(Scene, this);
            }, true);

            UserInput.RegisterKeyPressAction(Keys.D2, (Vector2 thumbStickPosition) =>
            {
                CurrentWeapon?.Destroy();
                CurrentWeapon = new Machinegun(Scene, this);
            }, true);

            UserInput.RegisterKeyPressAction(Keys.D3, (Vector2 thumbStickPosition) =>
            {
                CurrentWeapon?.Destroy();
                CurrentWeapon = new Shotgun(Scene, this);
            }, true);

            UserInput.MouseMovedAction = (prevMousePos, currentMousePos) => {
                Vector2 worldPos = Scene.Camera.ScreenToWorldSpace(currentMousePos);
                if (Transform.Position.X < worldPos.X)
                {
                    if (!IsKicking)
                    {
                        CurrentFaceDirection = Direction.EAST;
                    }
                }
                else
                {
                    if (!IsKicking)
                    {
                        CurrentFaceDirection = Direction.WEST;
                    }
                }
                CurrentWeapon?.SetDirection(CurrentFaceDirection);
                CurrentWeapon?.FollowMouse(worldPos);
            };

            /*UserInput.RegisterKeyPressAction(Keys.Escape, (Vector2 thumbstickPosition) =>
             * {
             *  Config.ExitAction.Invoke();
             * });*/
        }
示例#3
0
 static void DescribeWeaponFunctionality(IWeapon weapon)
 {
     weapon.Move();
     weapon.Destroy();
 }