示例#1
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        Main m = GetNode <Main>("/root/main");

        _input = new FPSInput();

        _hudState            = new HUDPlayerState();
        _hudState.health     = 80;
        _hudState.ammoLoaded = 999;
        _hudState.weaponName = "Stakegun";

        // find Godot scene nodes
        _body       = GetNode <KinematicWrapper>("actor_base");
        _body.actor = this;
        _body.HideModels();

        _head = GetNode <Spatial>("actor_base/head");

        _laserDot = GetNode <LaserDot>("laser_dot");
        _laserDot.CustomInit(_head, uint.MaxValue, 1000);

        _thrownSword = m.factory.SpawnThrownSword(false);
        m.AddOrphanNode(_thrownSword);

        // init components
        _fpsCtrl = new FPSController(_body, _head);


        // Inventory
        _inventory = new ActorInventory();
        _inventory.Init(_head, 1);

        // Add weapons
        _inventory.AddWeapon(AttackFactory.CreatePlayerShotgun(_head, _body));
        _inventory.AddWeapon(AttackFactory.CreateStakegun(_head, _body));

        m.cam.AttachToTarget(_head);
    }
示例#2
0
 public void SetHudState(HUDPlayerState state)
 {
     playerStatus.Text = $"Health {state.health}\n{state.weaponName}\nAmmo {state.ammoLoaded}";
 }
示例#3
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //_main = GetNode<Main>("/root/main");
        _main = Main.i;

        _input = new FPSInput();

        _hudState            = new HUDPlayerState();
        _hudState.health     = 80;
        _hudState.ammoLoaded = 999;
        _hudState.weaponName = "Stakegun";

        // find Godot scene nodes
        _body       = GetNode <KinematicWrapper>("actor_base");
        _body.actor = this;
        _body.HideModels();

        _head        = GetNode <Spatial>("actor_base/head");
        _meleeVolume = _head.GetNode <MeleeHitVolume>("melee_hit_volume");

        ///////////////////////////////////////
        // view models

        // grab hands placeholder and attach it to the head node
        _handsPlaceholder = GetNode <ViewModel>("hands_placeholder");
        Transform t = _handsPlaceholder.GlobalTransform;

        RemoveChild(_handsPlaceholder);
        _head.AddChild(_handsPlaceholder);
        _handsPlaceholder.GlobalTransform = t;
        _handsPlaceholder.SetEnabled(false);

        // same for placeholder gun
        _gunPlaceholder = GetNode <ViewModel>("view_placeholder_gun");
        ZqfGodotUtils.SwapSpatialParent(_gunPlaceholder, _head);
        _gunPlaceholder.SetEnabled(true);
        _viewModel = _gunPlaceholder;

        _laserDot = GetNode <LaserDot>("laser_dot");
        _laserDot.CustomInit(_head, uint.MaxValue, 1000);

        _thrownSword = _main.factory.SpawnThrownSword(false);
        _main.AddOrphanNode(_thrownSword);

        // init components
        _fpsCtrl = new FPSController(_body, _head);


        // Inventory
        _inventory = new ActorInventory();
        _inventory.Init(_head, 1);

        // Add weapons
        SwordThrowProjectile prj = _main.factory.SpawnThrownSword();

        _inventory.AddWeapon(AttackFactory.CreatePlayerMelee(_meleeVolume, prj, _laserDot));
        _inventory.AddWeapon(AttackFactory.CreatePlayerShotgun(_head, _body));
        _inventory.AddWeapon(AttackFactory.CreateStakegun(_head, _body));
        _inventory.AddWeapon(AttackFactory.CreateLauncher(_head, _body));
        _inventory.AddWeapon(new InvWeapGodhand(_head, _laserDot));
        _inventory.SelectWeaponByIndex(1);

        _main.cam.AttachToTarget(_head, Vector3.Zero, GameCamera.ParentType.Player);

        if (_entId == 0)
        {
            // no id previous set, request one
            _entId = _main.game.ReserveActorId(1);
            _main.game.RegisterActor(this);
        }

        _main.Broadcast(GlobalEventType.PlayerSpawned, this);
    }