Пример #1
0
        public void ProcessRespawn(float delta, PlayerWeaponHelper weaponHelper)
        {
            if (_player.Health <= 0 && !_player.IsDead)
            {
                GetNode <CollisionShape>("Body_CollisionShape").Disabled = true;
                GetNode <CollisionShape>("Feet_CollisionShape").Disabled = true;
                weaponHelper.ChangingWeapon     = true;
                weaponHelper.ChangingWeaponName = "UNARMED";
                GetNode <ColorRect>("HUD/Death_Screen").Visible = true;
                GetNode <Panel>("HUD/Panel").Visible            = false;
                GetNode <Control>("HUD/Crosshair").Visible      = false;
                _deadTime      = RespawnTime;
                _player.IsDead = true;
                var grabbedObject = weaponHelper.GrabbedObject;
                if (grabbedObject != null)
                {
                    grabbedObject.Mode = RigidBody.ModeEnum.Rigid;
                    grabbedObject.ApplyImpulse(new Vector3(0, 0, 0),
                                               -_camera.GlobalTransform.basis.z.Normalized()
                                               * PlayerWeaponHelper.ObjectThrowForce / 2);
                    grabbedObject.CollisionLayer = 1;
                    grabbedObject.CollisionMask  = 1;
                    grabbedObject = null;
                }
            }

            if (!_player.IsDead)
            {
                return;
            }

            _deadTime -= delta;
            var deadTimePretty = $"{_deadTime:0.}";

            GetNode <Label>("HUD/Death_Screen/Label").Text = $"You died\n{deadTimePretty} seconds until respawn";
            if (_deadTime > 0)
            {
                return;
            }
            _player.GlobalTransform = new Transform(
                _player.GlobalTransform.basis,
                _globals.GetRespawnPosition());
            GetNode <CollisionShape>("Body_CollisionShape").Disabled = false;
            GetNode <CollisionShape>("Feet_CollisionShape").Disabled = false;
            GetNode <ColorRect>("HUD/Death_Screen").Visible          = false;
            GetNode <Panel>("HUD/Panel").Visible       = true;
            GetNode <Control>("HUD/Crosshair").Visible = true;
            foreach (var weapon in weaponHelper.Weapons)
            {
                weapon.Value?.Call("reset_weapon");
            }

            _player.Health = 100;
            weaponHelper.GrenadeAmounts = new Dictionary <string, int>
            {
                { "Grenade", 2 }, { "Sticky Grenade", 2 }
            };
            weaponHelper.CurrentGrenadeName = "Grenade";
            _player.IsDead = false;
        }
Пример #2
0
        public void ProcessHud(float delta, PlayerWeaponHelper weaponHelper)
        {
            var sb = new StringBuilder();

            sb.AppendLine($"HEALTH: {_player.Health}");
            if (weaponHelper.CurrentWeaponName != "UNARMED" &&
                weaponHelper.CurrentWeaponName != "KNIFE")
            {
                var currentWeapon = weaponHelper.CurrentWeapon;
                sb.Append($"AMMO: {currentWeapon.AmmoInWeapon}");
                sb.Append("/");
                sb.AppendLine(currentWeapon.SpareAmmo.ToString());
            }

            sb.Append($"{weaponHelper.CurrentGrenadeName}: ");
            sb.AppendLine(weaponHelper.CurrentGrenadeAmount.ToString());
            _uiStatusLabel.Text = sb.ToString();
        }