Exemple #1
0
        public void ParseObjects(Core core)
        {
            foreach (var layer in Layers)
            {
                var objectLayer = layer as MapObjectLayer;

                if (objectLayer == null)
                    continue;

                foreach (var mapObject in objectLayer.Objects)
                {
                    if (mapObject.Type == "SquadStart")
                    {
                        var soldier = new Soldier(ref core.Squad);
                        soldier.Name = "Derp";
                        // HACK: For some reason, the tile object coordinates are offset by one tile on the Y-axis in the Tiled map file (https://github.com/bjorn/tiled/issues/91)
                        var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
                        var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
                        soldier.X = mapObjectGridPos.X;
                        soldier.Y = mapObjectGridPos.Y;

                        core.Squad.Add(soldier);
                    }
                    if (mapObject.Type == "MonsterSpawn" || mapObject.Type == "EnemySpawn")
                    {
                        var enemy = new MonsterSpawn("Monster", 14, 0, ref core.Swarm);
                        var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
                        var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
                        enemy.X = mapObjectGridPos.X;
                        enemy.Y = mapObjectGridPos.Y;
                    }
                    if (mapObject.Type == "AmbushMonsterSpawn" || mapObject.Type == "AmbushEnemySpawn")
                    {
                        var enemy = new MonsterSpawn("Monster", 2, 0, ref core.Swarm);
                        var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
                        var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
                        enemy.X = mapObjectGridPos.X;
                        enemy.Y = mapObjectGridPos.Y;
                    }
                    if (mapObject.Type == "DelayedMonsterSpawn" || mapObject.Type == "DelayedEnemySpawn")
                    {
                        var enemy = new MonsterSpawn("Monster", 200, 4, ref core.Swarm);
                        var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
                        var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
                        enemy.X = mapObjectGridPos.X;
                        enemy.Y = mapObjectGridPos.Y;
                    }
                    if (mapObject.Type == "BossSpawn")
                    {
                        var enemy = new MonsterSpawn("BUB", 12, 0, ref core.Swarm);
                        var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y - Grid.TileSize);
                        var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
                        enemy.X = mapObjectGridPos.X;
                        enemy.Y = mapObjectGridPos.Y;
                    }
                    if (mapObject.Type == "Door")
                    {
                        var door = new Door(true);
                        var mapObjectPos = new Vector2(mapObject.Bounds.X, mapObject.Bounds.Y);
                        var mapObjectGridPos = Grid.WorldToGrid(mapObjectPos);
                        door.X = mapObjectGridPos.X;
                        door.Y = mapObjectGridPos.Y;
                    }
                }
            }
        }
Exemple #2
0
        private GUI.Frame CreateUnitFrame(Soldier soldier)
        {
            var frame = new GUI.Frame(UIParent);
            frame.SetTexture("images/GUI/unit_background");
            frame.Color = Color.Black;
            frame.Width = 164;
            frame.Height = 42;

            var nameText = new GUI.Text(frame);
            nameText.SetFont("fonts/UnitName");
            nameText.Value = soldier.Name + " "/* + soldier.GetHashCode()*/;
            nameText.X = 4;
            nameText.Y = 1;
            frame["nameText"] = nameText;

            var healthBarBg = new GUI.Frame(frame);
            healthBarBg.SetTexture("images/GUI/health_background");
            healthBarBg.Width = 136;
            healthBarBg.Height = 13;
            healthBarBg.X = 3;
            healthBarBg.Y = 19;
            frame["healthBarBg"] = healthBarBg;

            var healthBar = new GUI.Frame(healthBarBg);
            healthBar.SetTexture("images/GUI/bar_solid");
            healthBar.Color = Color.Red;
            healthBar.Width = (int)((healthBarBg.Width - 2) * (soldier.GetComponent<Component.Stat>().HP / soldier.GetComponent<Component.Stat>().MaxHP));
            healthBar.Height = 11;
            healthBar.X = 1;
            healthBar.Y = 1;
            frame["healthBar"] = healthBar;

            var actionBarBg = new GUI.Frame(frame);
            actionBarBg.SetTexture("images/GUI/health_background");
            actionBarBg.Width = 136;
            actionBarBg.Height = 8;
            actionBarBg.X = 3;
            actionBarBg.Y = 31;
            frame["actionBarBg"] = actionBarBg;

            var actionBar = new GUI.Frame(actionBarBg);
            actionBar.SetTexture("images/GUI/bar_solid");
            actionBar.Color = Color.Orange;
            actionBar.Width = (int)((healthBarBg.Width - 2) * (soldier.GetComponent<Component.Stat>().HP / soldier.GetComponent<Component.Stat>().MaxHP));
            actionBar.Height = 6;
            actionBar.X = 1;
            actionBar.Y = 1;
            frame["actionBar"] = actionBar;

            for (int i = 1; i < 10; i++)
            {
                var line = new GUI.Frame(actionBar);
                line.Texture = Utility.GetSolidTexture();
                line.Color = Color.Black;
                line.Height = 6;
                line.Width = 1;
                line.X = (int)(i * ((float)actionBarBg.Width/10f)) - 1;
            }

            return frame;
        }
        // Get all soldiers who are close to each other in a chain
        public void GetNearChain(ref List<Soldier> group, List<Soldier> soldiers, Soldier soldier, float maxRange)
        {
            for (int index = 0; index < soldiers.Count; index++)
            {
                var nearSoldier = soldiers[index];

                if (!group.Contains(nearSoldier))
                {
                    float distance = Vector2.Distance(nearSoldier.Transform.World + nearSoldier.Transform.World.Origin,
                                                          soldier.Transform.World + soldier.Transform.World.Origin);
                    if (distance <= maxRange)
                    {
                        group.Add(nearSoldier);
                        GetNearChain(ref group, soldiers, nearSoldier, maxRange);
                    }
                }
            }
        }