Esempio n. 1
0
        private async void LoadEnemy(string enemyDataName)
        {
            var data = Autoload.Get <Data>();

            if (!data.enemyData.ContainsKey(enemyDataName))
            {
                GD.PushError($"Enemy data for {enemyDataName} not found");
                return;
            }

            enemyName = enemyDataName;
            Stat      = data.enemyData[enemyDataName];
            moveSpeed = data.GetLerpedSpeedStat(Stat.MoveSpeed, MIN_SPEED, MAX_SPEED);

            battleTexture = new AtlasTexture
            {
                Atlas = GD.Load <Texture>(string.Format(BattleSpritePath,
                                                        enemyDataName.ToLower()))
            };

            if (sprite == null || stateMachine == null)
            {
                await ToSignal(this, "ready");
            }


            sprite.Texture =
                GD.Load <Texture>(string.Format(OverworldSpritePath,
                                                enemyDataName.ToLower()));

            stateMachine.behaviour =
                GD.Load <AI_Behaviour>(string.Format(AIResourcePath,
                                                     Stat.AiType.ToLower()));
            EmitSignal(nameof(StatsLoaded));
        }
Esempio n. 2
0
        private void SpawnEnemy(EnemySpawn enemySpawn)
        {
            if (enemySpawn.enemies.Length == 0)
            {
                GD.PushWarning(
                    $"{enemySpawn} enemy spawn has no enemy names attached.");
                return;
            }

            if (enemySpawn.enemyNumber <= 0)
            {
                GD.PushWarning(
                    $"{enemySpawn} enemy spawn's enemyNumber not greater than 0");
                return;
            }

            for (var i = 0; i < enemySpawn.enemyNumber; i++)
            {
                var enemy     = (BaseEnemy)_baseEnemyScene.Instance();
                var safe      = false;
                var enemyName = enemySpawn.enemies.RandomElement();
                if (string.IsNullOrWhiteSpace(enemyName))
                {
                    GD.PushError(
                        $"{enemySpawn.Name} enemy spawn has a null enemy attached");
                    return;
                }

                var data = Autoload.Get <Data>();
                if (!data.enemyData.ContainsKey(enemyName))
                {
                    GD.PushError(
                        $"{enemySpawn} enemy spawn has a {enemyName} enemy with no data attached.");
                    return;
                }

                enemy.OnDependency = (ref BaseEnemy.EnemyDependencies dependency) =>
                {
                    dependency.EnemyName      = enemyName;
                    dependency.PlayerInstance = _player;
                };

                while (!safe)
                {
                    enemy.Position = enemySpawn.GetRandomGlobalPosition();
                    _map.CallDeferred("add_child", enemy);
                    safe = enemy.IsInAllowedTile();

                    if (!safe)
                    {
                        enemy.QueueFree();
                    }
                }

                enemy.Connect(nameof(BaseEnemy.Died), this, nameof(OnEnemy_Death),
                              new Array {
                    enemySpawn
                });
            }
        }
Esempio n. 3
0
        private void UpdateCharacters()
        {
            var saveData = SaveManager.SaveData;

            foreach (var keyValuePair in Autoload.Get <Data>().characterData)
            {
                var characterName   = keyValuePair.Key;
                var characterRecord = keyValuePair.Value;

                if (characterRecord.guildLevel > saveData.GuildLevel)
                {
                    continue;
                }

                var character = (Character)CharacterResource.Instance();
                _characters.AddChild(character);
                character.characterName = characterName;
                if (!character.UpdateCharacter())
                {
                    character.QueueFree();
                    continue;
                }

                character.characterButton.Connect("pressed", this,
                                                  nameof(OnCharacter_Pressed), new Array {
                    character
                });
            }
        }
    public override void _Ready()
    {
        asteroidPool      = GetNode("AsteroidPool") as Node;
        commandStartPoint = GetNode("CommandStartPoint") as Position2D;
        deathSound        = GetNode("DeathSound") as AudioStreamPlayer;
        bgm                 = GetNode("BGM") as AudioStreamPlayer;
        gameplayHUD         = GetNode("GameplayHUD") as GameplayHUDObject;
        gameOverHUD         = GetNode("GameOverHUD") as GameOverHUD;
        ship                = GetNode("Ship") as ShipObject;
        commandExecutePoint = GetNode("CommandExecutePoint") as CommandExecutePoint;

        messageTimer  = GetNode("GameplayHUD/MessageTimer") as Timer;
        blackHolePool = GetNode("BlackHolePool") as Node;
        spawnTimer    = GetNode("SpawnTimer") as Timer;

        this.globals = (Autoload)GetNode("/root/Autoload");

        this.globals.Randomize();
        ship.Connect("Hit", this, "GameOver");
        gameOverHUD.Connect("BackToMainMenu", this, "GotoMainmenu");
        gameOverHUD.Connect("RestartGame", this, "RestartGameplay");
        commandExecutePoint.Connect("CallRight", this, "ForceShipTurnRight");
        commandExecutePoint.Connect("CallLeft", this, "ForceShipTurnLeft");
        commandExecutePoint.Connect("CallShoot", this, "ForceShipShootLaser");

        SetProcess(true);
        NewGame();
        StartNextLevel();
    }
Esempio n. 5
0
    public override void _Ready()
    {
        this.globals = (Autoload)GetNode("/root/Autoload");

        AddToGroup("commands");
        SetProcess(true);
    }
Esempio n. 6
0
        public void OnItem_MouseEntered(string itemName)
        {
            if (string.IsNullOrWhiteSpace(itemName))
            {
                GD.PushError("Item name must not be empty");
                return;
            }

            var data = Autoload.Get <Data>();

            if (!data.itemData.ContainsKey(itemName))
            {
                GD.PushError($"Item name {itemName} not found");
                return;
            }

            var itemRecord = data.itemData[itemName];
            var itemType   = itemRecord.type;

            _itemNameLabel.Text = itemName;
            _background.Texture = GetItemTypeBackground(itemType);
            switch (itemType)
            {
            case "item":
                _damageMargin.Visible      = false;
                _healthGainedLabel.Visible = false;
                break;

            case "weapon":
                _damageMargin.Visible       = true;
                _healthGainedMargin.Visible = false;
                _quickDamageLabel.Text      = $"{itemRecord.quickDamage}";
                _heavyDamageLabel.Text      = $"{itemRecord.heavyDamage}";
                _counterDamageLabel.Text    = $"{itemRecord.counterDamage}";
                break;

            case "usable":
                _damageMargin.Visible       = false;
                _healthGainedMargin.Visible = true;
                _healthGainedLabel.Text     = $"{itemRecord.healthGained}";
                break;

            case "armor":
                _damageMargin.Visible       = false;
                _healthGainedMargin.Visible = true;
                _healthGainedLabel.Text     = $"{itemRecord.healthAdded}";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            _tween.InterpolateProperty(this, "rect_position", RectPosition,
                                       new Vector2(RectPosition.x, BOTTOM_POS_Y),
                                       ANIMATION_DURATION, Tween.TransitionType.Cubic, Tween.EaseType.Out);
            _tween.Start();
            popupToBeVisible = true;
        }
Esempio n. 7
0
        public void DropItems(string enemyName, Player playerInstance)
        {
            _playerInstance = playerInstance;
            var enemyRecord  = Autoload.Get <Data>().enemyData[enemyName];
            var coinsDropped = (int)GD.RandRange(
                enemyRecord.CoinDropAmount * MIN_COIN_DROP, enemyRecord
                .CoinDropAmount * MAX_COIN_DROP + 1);

            if (coinsDropped <= 0 && enemyRecord.CoinDropAmount > 0)
            {
                coinsDropped = 1;
            }

            _coinAmountLabel.Text  = $"{coinsDropped}";
            _playerInstance.Coins += coinsDropped;

            foreach (Node child in _itemsDroppedGrid.GetChildren())
            {
                child.QueueFree();
            }

            var items = new Dictionary <string, float>();

            if (!string.IsNullOrWhiteSpace(enemyRecord.ItemDrop1))
            {
                items.Add(enemyRecord.ItemDrop1, enemyRecord.ItemDrop1Chance);
            }

            if (!string.IsNullOrWhiteSpace(enemyRecord.ItemDrop2))
            {
                items.Add(enemyRecord.ItemDrop2, enemyRecord.ItemDrop2Chance);
            }

            if (!string.IsNullOrWhiteSpace(enemyRecord.ItemDrop3))
            {
                items.Add(enemyRecord.ItemDrop3, enemyRecord.ItemDrop3Chance);
            }

            for (var i = 0; i < enemyRecord.MaxItemDropped; i++)
            {
                var chance = Utility.Random.NextDouble();
                foreach (var item in items)
                {
                    if (chance < item.Value)
                    {
                        var itemDropped = ItemDroppedResource.Instance();
                        itemDropped.GetNode <TextureRect>("Item").Texture =
                            Utility.GetInventoryItemResource(item.Key);
                        _itemsDroppedGrid.AddChild(itemDropped);
                        playerInstance.Inventory.Add(item.Key);
                    }
                }
            }

            playerInstance.hudMargin.Visible = false;
            margin.Visible = true;
            _autoCloseTimer.Start();
        }
Esempio n. 8
0
    public override void _Ready()
    {
        sprite    = GetNode("Sprite") as Sprite;
        collision = GetNode("CollisionShape2D") as CollisionShape2D;

        this.globals = (Autoload)GetNode("/root/Autoload");

        AddToGroup("reefs");
    }
Esempio n. 9
0
    public override void _Ready()
    {
        this.globals = (Autoload)GetNode("/root/Autoload");

        labelTest      = GetNode("Label1") as Label;
        labelTest.Text = "Hello" + this.globals.score;
        GD.Print("GetChildCount: " + GetChildCount());
        SetPhysicsProcess(true);         //TUU use PhysicsProcess() insteads of FixProcess
    }
    public override void _Ready()
    {
        hitByCommandSound = GetNode("HitByCommandSound") as AudioStreamPlayer;

        this.globals = (Autoload)GetNode("/root/Autoload");

        hitByCommandSound.Stop();

        AddToGroup("commands");
        SetProcess(true);
    }
Esempio n. 11
0
        private async void OnSelect_Pressed()
        {
            AudioSystem.StopAllMusic();

            SaveManager.SaveData.CharacterName = selectedCharacterName;
            var transitionParams =
                new Transitions.TransitionParams(
                    Transitions.TransitionType.ShrinkingCircle, 0.2f);
            await Autoload.Get <Transitions>()
            .ChangeSceneDoubleTransition(WORLD_SCENE_PATH, transitionParams);
        }
Esempio n. 12
0
 private async void OnDoorDetection_BodyEntered(KinematicBody2D body)
 {
     if (body.IsInGroup("player"))
     {
         AudioSystem.PlaySFX(AudioSystem.SFXCollection.GuildHallEnter);
         await Autoload.Get <Transitions>().ChangeSceneDoubleTransition
             (WorldScenePath,
             new Transitions.TransitionParams(
                 Transitions.TransitionType.ShrinkingCircle, 0.3f));
     }
 }
Esempio n. 13
0
        private async void GoToMainMenu()
        {
            goingToMainMenu = true;
            var transitionParams =
                new Transitions.TransitionParams(
                    Transitions.TransitionType.ShrinkingCircle, 0.15f);
            await Autoload.Get <Transitions>()
            .ChangeSceneDoubleTransition(MainMenuScenePath, transitionParams);

            Autoload.Get <PaletteSwap>().Enabled = true;
        }
Esempio n. 14
0
    public override void _Ready()
    {
        this.globals = (Autoload)GetNode("/root/Autoload");

        explosionSpriteEffect = GetNode("ExplosionSpriteEffect") as AnimatedSprite;
        sprite         = GetNode("Sprite") as Sprite;
        collision      = GetNode("Collision") as CollisionShape2D;
        explosionSound = GetNode("ExplosionSound") as AudioStreamPlayer;

        AddToGroup("asteroids");
        explosionSpriteEffect.Visible = false;
    }
Esempio n. 15
0
        private async void GoToCharacterSelector()
        {
            AudioSystem.StopAllMusic();

            _changingScene = true;
            var transitionParams =
                new Transitions.TransitionParams(
                    Transitions.TransitionType.ShrinkingCircle, 0.2f);
            var transitions = Autoload.Get <Transitions>();
            await transitions.ChangeSceneDoubleTransition(CharacterSelectionScenePath,
                                                          transitionParams);
        }
Esempio n. 16
0
    public override void _Ready()
    {
        this.globals = (Autoload)GetNode("/root/Autoload");

        bgm = GetNode("BGM") as AudioStreamPlayer;
        hud = GetNode("HUD") as MenuHUD;

        hud.Connect("StartGame", this, "NewGame");

        SetProcess(false);
        bgm.Play();
    }
Esempio n. 17
0
File: Main.cs Progetto: v2sky/d2bs
        private bool GetAutoload()
        {
            bool autoload = false;

            if (Autoload.InvokeRequired)
            {
                Autoload.Invoke((MethodInvoker) delegate { autoload = Autoload.Checked; });
            }
            else
            {
                autoload = Autoload.Checked;
            }
            return(autoload);
        }
Esempio n. 18
0
        private async void OnDoorDetection_BodyEntered(KinematicBody2D body)
        {
            if (body.IsInGroup("player"))
            {
                var offset = new Vector2(0, 5);
                SaveManager.SaveData.WorldPosition = _player.Position + offset;

                AudioSystem.PlaySFX(AudioSystem.SFXCollection.GuildHallEnter);
                var transitionParams =
                    new Transitions.TransitionParams(
                        Transitions.TransitionType.ShrinkingCircle, 0.3f);

                await Autoload.Get <Transitions>()
                .ChangeSceneDoubleTransition(GuildHallScenePath, transitionParams);
            }
        }
Esempio n. 19
0
        public void TakeDamage(int damage, string damageType)
        {
            GD.Print($"{CharacterInstance.Name} TAKE DAMAGE: {damage} type {damageType}");
            EmitSignal(nameof(DamageTaken), damage, damageType);

            if (CharacterInstance.statusEffects.ContainsKey("Frozen") &&
                damageType == "Fire")
            {
                CharacterInstance.statusEffects.Remove("Frozen");
            }

            CharacterInstance.Health -= damage;

            if (CharacterInstance.Health <= 0)
            {
                CharacterInstance.Health = 0;
            }

            hitCombo = 0;

            switch (CharacterInstance)
            {
            case Player _:
                AudioSystem.PlaySFX(AudioSystem.SFXCollection.BattleHurtPlayer);
                break;

            case BaseEnemy enemy:
            {
                var enemyRecord =
                    Autoload.Get <Data>().enemyData[enemy.enemyName];


                if (AudioSystem.SFXCollection.TryGetValue(
                        $"BattleHurt{enemyRecord.Race}", out var sfx))
                {
                    AudioSystem.PlaySFX(sfx);
                }
                else
                {
                    GD.PrintErr($"No SFX found for {enemyRecord.Race} race");
                }

                break;
            }
            }
        }
Esempio n. 20
0
        private void OnEquip_Pressed()
        {
            AudioSystem.PlaySFX(AudioSystem.SFXCollection.InventoryItemEquipped);
            var data = Autoload.Get <Data>().itemData;

            if (!data.ContainsKey(selectedItem))
            {
                return;
            }

            var itemRecord       = data[selectedItem];
            var selectedItemType = itemRecord.type;

            switch (selectedItemType)
            {
            case "weapon":
                playerInstance.EquippedWeapon = selectedItem;
                EmitSignal(nameof(EquippedWeaponChanged));
                _equipButton.Visible = false;
                break;

            case "armor":
                if (!string.IsNullOrWhiteSpace(playerInstance.EquippedArmor))
                {
                    var oldArmorData = data[playerInstance.EquippedArmor];
                    playerInstance.Health -= oldArmorData.healthAdded;
                }

                playerInstance.EquippedArmor = selectedItem;
                playerInstance.maxHealth     =
                    SaveData.DefaultHealth + itemRecord.healthAdded;
                playerInstance.Health += itemRecord.healthAdded;
                EmitSignal(nameof(EquippedArmorChanged));
                _equipButton.Visible = false;
                break;

            default:
                GD.PushError(
                    "The equip button was pressed for a non-equippable item.");
                break;
            }
        }
Esempio n. 21
0
        private async void OnUse_Pressed()
        {
            AudioSystem.PlaySFX(AudioSystem.SFXCollection.InventoryItemUsed);
            var data = Autoload.Get <Data>().itemData;

            if (!data.ContainsKey(selectedItem))
            {
                return;
            }

            var itemRecord       = data[selectedItem];
            var selectedItemType = itemRecord.type;

            if (selectedItemType == "usable")
            {
                if (playerInstance.Health >= playerInstance.maxHealth)
                {
                    _confirmUsePopup.Visible = true;
                    var yesPressed =
                        (bool)(await ToSignal(this, nameof(YesOrNoPressed)))[0];
                    _confirmUsePopup.Visible = false;
                    if (!yesPressed)
                    {
                        return;
                    }
                }
                else
                {
                    playerInstance.Health = Mathf.Min(
                        playerInstance.Health + itemRecord.healthGained,
                        playerInstance.maxHealth);
                }

                playerInstance.Inventory.Remove(selectedItem);
                EmitSignal(nameof(ItemUsed), selectedItem);
                Visible = false;
            }
            else
            {
                GD.PushError("The use button was pressed for a non-usable item");
            }
        }
Esempio n. 22
0
        private async void GoToCharacterSelector()
        {
            if (!_introSFXPlayed)
            {
                _introSFXPlayer.Stop();
                _introSFXPlayer.QueueFree();

                PlayTitleScreenMusic();
            }

            AudioSystem.PlaySFX(AudioSystem.SFXCollection.TitleScreenKeyPressed);

            _changingScene = true;
            var transitionParams =
                new Transitions.TransitionParams(
                    Transitions.TransitionType.ShrinkingCircle, 0.2f);
            var transitions = Autoload.Get <Transitions>();
            await transitions.ChangeSceneDoubleTransition(CharacterSelectionScenePath,
                                                          transitionParams);
        }
Esempio n. 23
0
        private async void GameOver()
        {
            _player.isDead = true;

            var saveData = SaveManager.SaveData;

            saveData.WorldPosition  = SaveData.DefaultWorldPosition;
            saveData.Coins          = SaveData.DefaultCoins;
            saveData.Inventory      = SaveData.DefaultInventory;
            saveData.EquippedWeapon = SaveData.DefaultWeapon;
            saveData.EquippedArmor  = SaveData.DefaultArmor;
            saveData.MaxHealth      = SaveData.DefaultHealth;
            saveData.Health         = SaveData.DefaultHealth;
            _player.Health          = SaveData.DefaultHealth;

            AudioSystem.StopAllMusic();
            await Autoload.Get <Transitions>().ChangeSceneDoubleTransition(
                GameOverScenePath,
                new Transitions.TransitionParams(
                    Transitions.TransitionType.ShrinkingCircle, 0.2f));
        }
Esempio n. 24
0
    public override void _Ready()
    {
        ship = GetNode("PlayerShip") as ShipObject;
        Position2D temp = GetNode("PlayerShipPoints/2") as Position2D;

        commandStartPoint     = GetNode("CommandPanel/CommandStartPoint") as Position2D;
        commandExecutionPoint = GetNode("CommandPanel/CommandExecutionPoint") as CommandExecutionPointObject;
        reefSpawnTimer        = GetNode("ReefSpawnTimer") as Timer;
        reefPool             = GetNode("ReefPool") as Node;
        remainingNMileLabel  = GetNode("CommandPanel/RemainingNMileLabel") as Label;
        messageLabel         = GetNode("MessageLabel") as Label;
        messageTimer         = GetNode("MessageTimer") as Godot.Timer;
        weaterStatusLabel    = GetNode("CommandPanel/WeaterStatusLabel") as Label;
        gameOverSound        = GetNode("GameOverSound") as AudioStreamPlayer;
        missionCompleteSound = GetNode("MissionCompleteSound") as AudioStreamPlayer;
        bgm = GetNode("BGM") as AudioStreamPlayer;

        this.globals = (Autoload)GetNode("/root/Autoload");

        this.globals.Randomize();
        ship.SetStartPosition(temp.Position, Int32.Parse(temp.Name));
        velocity = commandVelocity[weatherFactor];
        reefSpawnTimer.Start();
        distanceFromGoal            *= 60; //multiply with 60 because frame-per-sec principle
        this.globals.missionComplete = false;
        difficult     = 0;
        weatherFactor = 0;
        messageLabel.Hide();
        messageTimer.Stop();
        SetWeatherStatusLabel();
        gameOverSound.Stop();
        missionCompleteSound.Stop();
        bgm.Stop();
        bgm.Play();

        commandExecutionPoint.Connect("CallRight", this, "ForceShipTurnRight");
        commandExecutionPoint.Connect("CallLeft", this, "ForceShipTurnLeft");
        ship.Connect("Hit", this, "DoGameOver");
    }
Esempio n. 25
0
        public void OnItem_Pressed(InventoryItem item, Player player)
        {
            var itemName = item.itemName;

            selectedItem   = itemName;
            playerInstance = player;
            Visible        = true;

            AudioSystem.PlaySFX(AudioSystem.SFXCollection.PauseMenuItemPressed);

            EmitSignal(nameof(DetailedItemInfoMenuAppeared));
            _nameLabel.Text = itemName;

            _itemIcon.Texture =
                GD.Load <Texture>(string.Format(InventorySprite,
                                                itemName.ToLower().Replace(" ", "_")));


            var data = Autoload.Get <Data>();

            if (!data.itemData.ContainsKey(itemName))
            {
                return;
            }

            var itemRecord = data.itemData[itemName];
            var itemType   = itemRecord.type;

            switch (itemType)
            {
            case "item":
                _damageValues.Visible     = false;
                _equipButton.Visible      = false;
                _useButton.Visible        = false;
                _healthGainedHBox.Visible = false;
                break;

            case "weapon":
                _damageValues.Visible     = true;
                _equipButton.Visible      = playerInstance.EquippedWeapon != itemName;
                _useButton.Visible        = false;
                _healthGainedHBox.Visible = false;
                _quickDamageLabel.Text    = $"{itemRecord.quickDamage}";
                _heavyDamageLabel.Text    = $"{itemRecord.heavyDamage}";
                _counterDamageLabel.Text  = $"{itemRecord.counterDamage}";
                _quickTypeIcon.Texture    =
                    GetDamageTypeIcon(itemRecord.quickDamageType);
                _heavyTypeIcon.Texture =
                    GetDamageTypeIcon(itemRecord.heavyDamageType);
                _counterTypeIcon.Texture =
                    GetDamageTypeIcon(itemRecord.counterDamageType);

                _quickStatusIcon.Texture =
                    GetDamageTypeStatusIcon(itemRecord.quickStatusEffect);
                _quickStatusEffectChanceLabel.Text =
                    itemRecord.quickStatusEffect == "none"
                            ? string.Empty
                            : $"{itemRecord.quickEffectChance}";

                _heavyStatusIcon.Texture =
                    GetDamageTypeStatusIcon(itemRecord.heavyStatusEffect);
                _heavyStatusEffectChanceLabel.Text =
                    itemRecord.heavyStatusEffect == "none"
                            ? string.Empty
                            : $"{itemRecord.heavyEffectChance}";

                _counterStatusIcon.Texture =
                    GetDamageTypeStatusIcon(itemRecord.counterStatusEffect);
                _counterStatusEffectChanceLabel.Text =
                    itemRecord.counterStatusEffect == "none"
                            ? string.Empty
                            : $"{itemRecord.counterEffectChance}";
                break;

            case "usable":
                _damageValues.Visible        = false;
                _equipButton.Visible         = false;
                _useButton.Visible           = true;
                _healthGainedHBox.Visible    = true;
                _healthGainedValueLabel.Text = $"{itemRecord.healthGained}";
                break;

            case "armor":
                _damageValues.Visible        = false;
                _equipButton.Visible         = playerInstance.EquippedArmor != itemName;
                _useButton.Visible           = false;
                _healthGainedHBox.Visible    = true;
                _healthGainedValueLabel.Text = $"{itemRecord.healthAdded}";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 26
0
 public override void _Ready()
 {
     Autoload.Get <PaletteSwap>().Enabled = false;
 }