Ejemplo n.º 1
0
    public override void _Ready()
    {
        // Get nodes
        _joystick     = GetParent().GetNode("CanvasLayer/Joystick").GetChild <JoystickButton>(0);
        _playerSprite = GetNode <Sprite>("PlayerSprite");
        _inventory    = GetParent().GetNode <Inventory>("CanvasLayer/Inventory");
        _debugOverlay = GetParent().GetNode <DebugOverlay>("CanvasLayer/DebugOverlay");
        _audioPlayer  = GetNode <AudioStreamPlayer>("AudioPlayer");
        _itemTooltip  = (ItemTooltip)GD.Load <PackedScene>("res://ItemTooltip.tscn").Instance();
        GetParent().GetNode("CanvasLayer").AddChild(_itemTooltip);
        _gathering      = GetParent <Gathering>();
        _footstepPlayer = GetNode <AudioStreamPlayer>("FootstepPlayer");
        _miscPlayer     = GetNode <AudioStreamPlayer>("MiscPlayer");

        // Load assets
        _runForwards        = GD.Load <Texture>("res://textures/Player_run_forwards.png");
        _runBackwards       = GD.Load <Texture>("res://textures/Player_run_backwards.png");
        _runRight           = GD.Load <Texture>("res://textures/Player_run_right.png");
        _runForwardsNormal  = GD.Load <Texture>("res://textures/normal/Player_run_forwards_n.png");
        _runBackwardsNormal = GD.Load <Texture>("res://textures/normal/Player_run_backwards_n.png");
        _runRightNormal     = GD.Load <Texture>("res://textures/normal/Player_run_right_n.png");
        _forestSong         = GD.Load <AudioStreamOGGVorbis>("res://audio/music/enchanted_forest_longer.ogg");

        // Load footstep sounds into an array
        for (int i = 0; i < _footstepSounds.Length; i++)
        {
            string terrainType = string.Empty;
            int    indexOffset = 0;
            if (i < 4)
            {
                terrainType = "dirt";
            }
            else if (i >= 4 && i < 8)
            {
                terrainType = "grass";
                indexOffset = 4;
            }
            else if (i >= 8)
            {
                terrainType = "stone";
                indexOffset = 8;
            }

            _footstepSounds[i] = GD.Load <AudioStream>("res://audio/sfx/footstep/" + terrainType + "_" + (i - indexOffset + 1).ToString() + ".wav");
        }

        // Load magic pop sounds
        for (int i = 0; i < _magicPopSounds.Length; i++)
        {
            _magicPopSounds[i] = GD.Load <AudioStream>("res://audio/sfx/magic/magic_pop_open_0" + (i + 1).ToString() + ".wav");
        }

        // Other setup
        Timer spriteAnimTimer = GetNode <Timer>("SpriteAnimateTimer");

        spriteAnimTimer.WaitTime = 1f / _SpriteFPS;
        spriteAnimTimer.Connect("timeout", this, nameof(AnimateSprite));

        _invItems.AddRange(new Item.ItemStack[] { new Item.ItemStack(Items.BRIMSTONE, 1), new Item.ItemStack(Items.FLY_AGARIC, 3), new Item.ItemStack(Items.ELDERBERRIES, 5), new Item.ItemStack(Items.AQUA_FORTIS, 1), new Item.ItemStack(Items.HOLLY_BERRIES, 3), new Item.ItemStack(Items.AQUA_VITAE, 1) });
        GetParent().GetNode <Inventory>("CanvasLayer/Inventory").UpdateSlots(_invItems);

        _debugOverlay.TrackProperty(nameof(_inventory.Scale), _inventory, "Inventory Scale");
        _debugOverlay.TrackFunc(nameof(FloorPositionString), this, "Player Position");

        _inventory.Connect("ItemSlotSelected", this, nameof(InventorySlotSelected));

        _audioPlayer.Stream   = _forestSong;
        _audioPlayer.VolumeDb = -25f;
        _audioPlayer.Play();
    }