コード例 #1
0
ファイル: Player.cs プロジェクト: Phischermen/GodotFPS
    public override void _Ready()
    {
        _CollisionStand  = GetNode <CollisionShape>("CollisionStand");
        _CollisionCrouch = GetNode <CollisionShape>("CollisionCrouch");
        CapsuleShape shape1 = (CapsuleShape)_CollisionStand.Shape;
        CapsuleShape shape2 = (CapsuleShape)_CollisionCrouch.Shape;

        StandHeight    = shape1.Height;
        CrouchHeight   = shape2.Height;
        OtherCollision = NX.FindAll <CollisionShape>(this, true);
        OtherCollision.Remove(_CollisionStand);
        OtherCollision.Remove(_CollisionCrouch);

        StandArea       = GetNode <Area>("StandArea");
        Head            = GetNode <Spatial>("Head");
        Neck            = GetNode <Spatial>("Head/Wrapper1/Neck");
        _Camera         = GetNode <Camera>("Head/Wrapper1/Neck/Wrapper2/Wrapper3/Camera");
        HighlightCamera = GetNode <Camera>("Head/Wrapper1/Neck/Wrapper2/Wrapper3/Camera/Viewport2/Camera");
        ArmWrapper      = GetNode <Spatial>("Head/Wrapper1/Neck/Wrapper2/Wrapper3/Camera/Viewport/Wrapper4");
        ClimbTimer      = GetNode <Timer>("ClimbTimer");
        ClimbTimer.Connect("timeout", this, "_OnClimbTimerTimeout");

        //_JumpArea = GetNode<PlayerFeet>("JumpArea");
        _SnapArea = GetNode <SnapArea>("SnapArea");
        GroundRay = GetNode <RayCast>("GroundRay");
        LedgeRays = new RayCast[GetNode <Node>(("Head/LedgeRays")).GetChildCount()];
        for (int i = 0; i < LedgeRays.Length; ++i)
        {
            LedgeRays[i] = GetNode <RayCast>("Head/LedgeRays/LedgeRay" + (i + 1));
        }
        ClimbLabel = GetNode <Label>("UI/Reticle/ClimbLabel");
        JumpLabel  = GetNode <Label>("UI/JumpLabel");

        ScanRay           = GetNode <RayCast>("Head/Wrapper1/Neck/ScanRay");
        PointerProjectRay = GetNode <RayCast>("Head/Wrapper1/Neck/PointerProjectRay");
        ScanPlayer        = ScanRay.GetNode <AudioStreamPlayer>("Player");
        ScanTimer         = GetNode <Timer>("ScanTimer");
        ScanTimer.Connect("timeout", this, "_OnScanTimerTimeout");

        //Check for vital actions in InputMap
        IX.CheckAndAddAction("move_forward", KeyList.W);
        IX.CheckAndAddAction("move_backward", KeyList.S);
        IX.CheckAndAddAction("move_left", KeyList.A);
        IX.CheckAndAddAction("move_right", KeyList.D);
        IX.CheckAndAddAction("move_up", KeyList.E);
        IX.CheckAndAddAction("move_down", KeyList.Q);
        IX.CheckAndAddAction("toggle_fly", KeyList.V);
        IX.CheckAndAddAction("interact", KeyList.E);
        IX.CheckAndAddAction("drop", KeyList.R);
        IX.CheckAndAddAction("release_mouse", KeyList.F1, false, false, true);
        IX.CheckAndAddAction("place_debug_camera", KeyList.F2, false, false, true);

        Input.Singleton.Connect("joy_connection_changed", this, "_OnJoyConnectionChanged");

        MaxSlopeSlip   = Mathf.Deg2Rad(MaxSlopeSlip);
        MaxSlopeNoWalk = Mathf.Deg2Rad(MaxSlopeNoWalk);

        //Set jumps left
        JumpsLeft = JumpCount;

        //Set animation
        HeadBobbing = _headBobbing;
        SwingTarget = Vector2.Zero;

        //Capture mouse
        Input.SetMouseMode(Input.MouseMode.Captured);

        StandArea.Monitoring = true;
    }