Пример #1
0
        public override void OnAdd(Scene scene)
        {
            base.OnAdd(scene);

            camera = scene.MainPlayer;

            gun = new Weapon("Pistol", this.body, camera.Transformation, scene);
        }
Пример #2
0
        public override void OnAdd(Scene scene)
        {
            base.OnAdd(scene);

            healthRechargeRate = 5;
            camera = (Camera)scene.FindEntity("MainCamera");
            weapons.Add(new Weapon("Machete", this.body, camera.Transformation, scene));
            weapons.Add(new Weapon("Pistol", this.body, camera.Transformation, scene));
            weapons.Add(new Weapon("SMG", this.body, camera.Transformation, scene));
            gun = weapons[weaponIndex];

            PlayerScreen.GetInst().AddJournalEntry("Get the key from the shack");
            PlayerScreen.GetInst().AddMarker(scene.FindEntity("Shack").Transformation);
        }
Пример #3
0
        void UpdateControls()
        {
            if (InputManager.Inst.IsKeyDownOnce(GameKey.ToggleCamera))
            {
                isControllable = !isControllable;
                isEnabled = isControllable;
            }
            if (InputManager.Inst.IsKeyDownOnce(GameKey.DropPlayerAtCamera))
            {
                isControllable = true;
                isEnabled = true;
                this.Transformation.SetPosition(camera.Transformation.GetPosition());
            }
            if (isControllable)
            {
                Vector3 velocity = Vector3.Zero;
                Vector3 rot = camera.Transformation.GetRotation();
                Matrix transform = Matrix.CreateRotationY(rot.Y);
                forwardVector = transform.Forward;
                strafeVector = transform.Right;
                if (InputManager.Inst.IsKeyDown(GameKey.MoveFoward))
                {
                    velocity += transform.Forward;
                }
                if (InputManager.Inst.IsKeyDown(GameKey.MoveBackward))
                {
                    velocity -= transform.Forward;
                }
                if (InputManager.Inst.IsKeyDown(GameKey.MoveLeft))
                {
                    velocity -= transform.Right;
                }
                if (InputManager.Inst.IsKeyDown(GameKey.MoveRight))
                {
                    velocity += transform.Right;
                }
                if (InputManager.Inst.IsKeyDownOnce(GameKey.Jump))
                {
                    body.Jump(6.5f);
                }
                if (InputManager.Inst.IsKeyDownOnce(GameKey.Crouch))
                {
                    SetupPosture(true);
                    this.team++;
                }
                if (InputManager.Inst.IsKeyUpOnce(GameKey.Crouch))
                {
                    SetupPosture(false);
                }

                float sprintCoeff = 0;
                if (InputManager.Inst.IsKeyDown(GameKey.Sprint) && velocity.Length() > 0.001f)
                {
                    energy -= Time.GameTime.ElapsedTime * sprintEnergyCost;
                    sprintCoeff = sprintSpeedBoost * MathHelper.Clamp(energy, 0, 1);
                }

                body.DesiredVelocity = velocity * (7.5f + sprintCoeff);

                if(gun != null)
                {
                    if (gunCycleTimeRemaining > 0.0f)
                    {
                        gunCycleTimeRemaining -= Time.GameTime.ElapsedTime;
                        if (gunCycleTimeRemaining <= 0.0f)
                        {
                            gun = weapons[weaponIndex];
                            gun.DrawFromHolster();
                        }
                    }

                    if (InputManager.Inst.IsKeyDownOnce(GameKey.Reload))
                        gun.Reload();
                    if (gun.IsManual())
                    {
                        if (InputManager.Inst.IsKeyDownOnce(GameKey.Fire))
                            gun.OnFire(camera.Transformation.GetPosition(), camera.Transformation.GetTransform().Forward);
                    }
                    else if (InputManager.Inst.IsKeyDown(GameKey.Fire))
                        gun.OnFire(camera.Transformation.GetPosition(), camera.Transformation.GetTransform().Forward);
                    if (!gun.HasDelayTime())
                    {
                        if (InputManager.Inst.IsKeyDown(GameKey.NextWeapon))
                        {
                            CycleWeapons(true);
                        }
                        if (InputManager.Inst.IsKeyDown(GameKey.PrevWeapon))
                        {
                            CycleWeapons(false);
                        }
                    }

                }
            }
        }