public static void AddItemToInventory(Item itemToGive, int stack) { Item selectedItem = playerInventory[selectedInventorySlot]; bool itemPlaced = false; //First, we check if a stack of the item exists for (int i = 0; i < 5; i++) { if (!itemPlaced) { if (playerInventory[i].type == itemToGive.type) { playerInventory[i].stack += stack; itemPlaced = true; } } } //Second, we check if there's an empty slot for (int i = 0; i < 5; i++) { if (!itemPlaced) { if (playerInventory[i].type == (int)Item.ItemTypes.Air) { playerInventory[i] = itemToGive; itemPlaced = true; } } } //Lastly, if the item can't be picked up, throw out whatever you're holding if (!itemPlaced) { if (selectedItem.type != (int)Item.ItemTypes.Air) { PackedScene itemScene = GD.Load <PackedScene>("res://Scenes/Environment/Items/" + selectedItem.name + ".tscn"); Node2D droppedItem = itemScene.Instance() as Node2D; droppedItem.Set("initializeTimer", 30); droppedItem.Set("itemType", selectedItem.type); droppedItem.Set("amount", selectedItem.stack); mapYSort.AddChild(droppedItem); droppedItem.GlobalPosition = Player.player.GlobalPosition; } playerInventory[selectedInventorySlot] = itemToGive; } gameData.EmitSignal(nameof(UpdateInventorySlotDrawings)); }
public static void SpawnDeathClouds(Vector2 pos) { AnimatedSprite clouds = PackedScenes.scenesDict["DeathClouds"].Instance() as AnimatedSprite; mapYSort.AddChild(clouds); clouds.GlobalPosition = pos; clouds.Play("default"); }
/// <summary> /// Adds enemies as children to the room, and adds them to the enemies list. /// </summary> private void AddEnemies() { var possibleEnemyPositions = NodeService.GetChildrenOfType <Position2D>(GetNode("PossibleEnemyPositions")); var enemyPositions = ListService.SelectNRandom(possibleEnemyPositions, 3); foreach (var enemyPosition in enemyPositions) { var skeleton = ActorFactory.CreateSkeleton(); _enemies.AddChild(skeleton); skeleton.Position = enemyPosition.Position; } }
private void CreateTrees() { YSort ySort = GetNode <YSort>("YSort"); for (int i = 0; i < 10; i++) { SpruceTree spruceTree = (SpruceTree)SpruceTreeScene.Instance(); spruceTree.Name = "SpruceTree" + i.ToString(); spruceTree.Position = GetRandomPosition(); ySort.AddChild(spruceTree); } }
private void UpdateGuildFromLevel() { foreach (Vector2 tile in _extendedTileMap.GetUsedCells()) { _extendedTileMap.SetCellv(tile, (int)Tiles.Empty); } foreach (Node chest in GetTree().GetNodesInGroup("Chest")) { chest.QueueFree(); } var saveData = SaveManager.SaveData; for (var i = 0; i < saveData.GuildLevel; i++) { if (i >= saveData.ChestContent.Count) { saveData.ChestContent.Add(Enumerable.Range(0, 8) .Select(e => string.Empty).ToList()); } var position = _firstChestPosition + new Vector2(CHEST_GAP_X * i, CHEST_GAP_Y * i); var chestInstance = (Chest)ChestResource.Instance(); chestInstance.Position = position; chestInstance.chestID = i; _objectsYSort.AddChild(chestInstance); var x = i; _extendedTileMap.SetCell(x, BLACK_TILES_POS_Y, (int)Tiles.Black); for (var y = TOP_POS_Y; y < BOTTOM_POS_Y + 1; y++) { x = y % 2 == 0 ? i + 1 : i; var tile = Tiles.Wall; if (y >= PLANK_START_POS_Y) { tile = y % 2 == 0 ? Tiles.PlankEven : Tiles.PlankOdd; } _extendedTileMap.SetCell(x, y, (int)tile); } var rightBorderPosition = _rightBorder.Position; rightBorderPosition.x = 38 + CHEST_GAP_X * (saveData.GuildLevel - 1); _rightBorder.Position = rightBorderPosition; _player.camera.LimitRight = 32 + CHEST_GAP_X * (saveData.GuildLevel - 1); } }
public void CreateMobs() { YSort ySort = GetNode <YSort>("YSort"); for (int i = 0; i < 20; i++) { Mob mob = (Mob)MobScene.Instance(); mob.Name = "Mob" + i.ToString(); mob.Position = GetRandomPosition(); ySort.AddChild(mob); GetNode("YSort/Mob" + i.ToString() + "/UI/SelectionArea").Connect("LeftClick", this, nameof(LeftClickOnMob)); GetNode("YSort/Mob" + i.ToString() + "/UI/SelectionArea").Connect("RightClick", this, nameof(RightCLickOnMob)); Mobs.Add(mob); } }
public void SpawnEntity(Entity entity) { _ySort.AddChild(entity); }