Example #1
0
    public override void _PhysicsProcess(float delta)
    {
        TimeSinceTranquilised += delta;
        foreach (DiseasedData dd in _diseasedBy)
        {
            dd.TimeSinceDiseased += delta;
            if (dd.TimeSinceDiseased >= _diseasedInterval)
            {
                this.TakeDamage(this.Transform, dd.Inflictor.GetType().ToString().ToLower(), dd.Inflictor.InflictLength, dd.Attacker, dd.Inflictor.Damage);
            }
        }

        TimeSinceConcussed += delta;
        if (Concussed)
        {
            // if crosshair within percentage of final destination, set new coords
            if (Math.Abs(_concussionCrosshairDestination.x - Crosshair.Position.x) < 10 &&
                Math.Abs(_concussionCrosshairDestination.y - Crosshair.Position.y) < 10)
            {
                _concussionCrosshairDestination = GetConcussionCrosshairDestination(true);
            }

            // move crosshair towards coords (change this later to an arc that changes constantly)
            Vector2 targ = (Crosshair.Position - _concussionCrosshairDestination).Normalized();

            Vector2 motion = targ * 50 * delta;

            Crosshair.Position -= motion;
        }

        if (Input.GetMouseMode() == Input.MouseMode.Captured)
        {
            // process inputs -- should this be in normal process instead of physics process?
            foreach (Impulse imp in _playerController.Impulses)
            {
                switch (imp)
                {
                case Impulse.Attack:
                    this.Shoot();
                    break;

                case Impulse.Slot1:
                    ActiveWeapon = this.Class.Weapon1;
                    break;

                case Impulse.Slot2:
                    ActiveWeapon = this.Class.Weapon2;
                    break;

                case Impulse.Slot3:
                    ActiveWeapon = this.Class.Weapon3;
                    break;

                case Impulse.Slot4:
                    ActiveWeapon = this.Class.Weapon4;
                    break;

                case Impulse.Detpipe:
                    this.Detpipe();
                    break;

                case Impulse.Gren1:
                    if (this.Class.HandGrenadeManager.PrimedGrenade1 != null)
                    {
                        // throw it
                        this.Class.HandGrenadeManager.ThrowGren(camera.GetGlobalTransform(), this, this.Class.Gren1, 1);
                    }
                    else if (this._currentGren1 > 0)
                    {
                        // prime new gren1
                        this.Class.HandGrenadeManager.PrimeGren(this, this.Class.Gren1, 1);

                        _currentGren1 -= 1;
                    }
                    break;

                case Impulse.Gren2:
                    if (this.Class.HandGrenadeManager.PrimedGrenade2 != null)
                    {
                        // throw it
                        this.Class.HandGrenadeManager.ThrowGren(camera.GetGlobalTransform(), this, this.Class.Gren2, 2);
                    }
                    else if (this._currentGren2 > 0)
                    {
                        // prime new gren2
                        this.Class.HandGrenadeManager.PrimeGren(this, this.Class.Gren2, 2);

                        _currentGren2 -= 1;
                    }
                    break;
                }
            }
            _playerController.Impulses.Clear();

            _playerController.Transform = this.Transform;

            /*throw new NotImplementedException();
             * // if controlling client, send your transform
             * if ()
             * {
             *
             * }
             * // if other player, check for transform updates
             * else
             * {
             *  if (_playerController.Transform != new Transform())
             *  {
             *      // TODO should probably check how far they are from each other and rubber band instead of straight apply
             *      this.Transform = _playerController.Transform;
             *      _playerController.Transform = new Transform();
             *  }
             * }*/

            if (ActiveWeapon != null)
            {
                ActiveWeapon.PhysicsProcess(delta);
            }

            QueueJump();
            if (touchingGround || climbLadder)
            {
                GroundMove(delta);
            }
            else
            {
                AirMove(delta);
            }

            playerVelocity = this.MoveAndSlide(playerVelocity, up);
            touchingGround = IsOnFloor();
            float speed = playerVelocity.Length();
            //GD.Print("Speed: " + speed.ToString());
        }
    }