예제 #1
0
        public override void _Ready()
        {
            AddToGroup(GROUP);
            _moveStateMachine.AddState(MoveState.GROUNDED, MoveStateGrounded);
            _moveStateMachine.AddState(MoveState.AIRBORNE, MoveStateAirborne);
            _moveStateMachine.AddState(MoveState.DASH, MoveStateDash);
            _moveStateMachine.AddState(MoveState.SLIDE, MoveStateSlide);
            _moveStateMachine.AddState(MoveState.WALL, MoveStateWall);
            _moveStateMachine.AddLeaveState(MoveState.WALL, LeaveMoveStateWall);
            _moveStateMachine.AddLeaveState(MoveState.GROUNDED, LeaveMoveStateGrounded);
            _moveStateMachine.AddLeaveState(MoveState.AIRBORNE, LeaveMoveStateAirborne);
            _moveStateMachine.AddLeaveState(MoveState.DASH, LeaveMoveStateDash);
            _moveStateMachine.SetInitialState(MoveState.GROUNDED);
            _animatedSprite    = GetNode <AnimatedSprite>("AnimatedSprite");
            _velocityComponent = this.GetFirstNodeOfType <VelocityComponent>();
            _healthComponent   = this.GetFirstNodeOfType <HealthComponent>();
            _animationPlayer   = GetNode <AnimationPlayer>("AnimationPlayer");
            _flipSprite        = GetNode <Sprite>("FlipSprite");
            _flipTween         = GetNode <Tween>("FlipTween");
            _walkParticles     = GetNode <Particles2D>("WalkParticles");
            _dashParticles     = GetNode <Particles2D>("DashParticles");

            var weaponSocket = this.GetFirstNodeOfType <WeaponSocketComponent>();

            weaponSocket.EquipWeapon((GD.Load("res://scenes/GameObject/Combat/GrenadeLauncher.tscn") as PackedScene).Instance() as Weapon);
            weaponSocket = GetNode <WeaponSocketComponent>("WeaponSocketComponent2");
            weaponSocket.EquipWeapon((GD.Load("res://scenes/GameObject/Combat/PlayerWeapon.tscn") as PackedScene).Instance() as Weapon);

            _flipTween.Connect("tween_all_completed", this, nameof(OnFlipTweenCompleted));
            _healthComponent?.Connect(nameof(HealthComponent.HealthChanged), this, nameof(OnHealthChanged));
        }
예제 #2
0
        public override void _Ready()
        {
            _animatedSprite = GetNode<AnimatedSprite>("AnimatedSprite");
            _weaponPosition2d = GetNode<Position2D>("WeaponPosition2D");
            _secondaryWeapon = GetNode<Node2D>("SecondaryWeapon");
            _secondaryWeaponPosition2d = GetNode<Position2D>("SecondaryWeapon/SecondaryWeaponPosition2D");
            _cameraTargetPosition2d = GetNode<Position2D>("CameraTargetPosition2D");
            _healthComponent = GetNode<HealthComponent>("HealthComponent");

            _weaponRadius = _weaponPosition2d.Position.x;
            _weaponHeight = _weaponPosition2d.Position.y;

            AddToGroup(GROUP);

            PlayerInventory.Instance.Connect(nameof(PlayerInventory.EquipmentUpdated), this, nameof(OnEquipmentUpdated));
            _healthComponent.Connect(nameof(HealthComponent.HealthDepleted), this, nameof(OnHealthDepleted));
            _healthComponent.Connect(nameof(HealthComponent.HealthDecremented), this, nameof(OnHealthDecremented));

            UpdateEquipment();
            GameEventDispatcher.DispatchPlayerCreatedEvent(this);
        }