Exemple #1
0
        public static EntityInfo FromFile(string filename)
        {
            EntityInfo info = new EntityInfo();

            using (StreamReader sr = new StreamReader("Content/Entities/" + filename))
            {
                sr.ReadLine();
                info.behavior = sr.ReadLine();
                sr.ReadLine();
                info.health = double.Parse(sr.ReadLine());
                sr.ReadLine();
                info.speed = int.Parse(sr.ReadLine());
                sr.ReadLine();
                info.skill = int.Parse(sr.ReadLine());
                sr.ReadLine();
                info.texture = sr.ReadLine();
                sr.ReadLine();
                info.icon = sr.ReadLine();
                sr.ReadLine();
                info.healthbar = sr.ReadLine();

                info.items = new List<string>();
                sr.ReadLine();
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    info.items.Add(line);
                }

                sr.Close();
            }

            return info;
        }
Exemple #2
0
        public Entity(string tag, string group, TileLayer layer, Point position, EntityInfo info, ContentManager content)
        {
            if (!init)
            {
                initializeBehaviors();
                init = true;
            }

            Tag = tag;
            Group = group;

            Health = new StatBar(info.health);

            this.speed = info.speed;
            this.skill = info.skill;

            this.inventory = new Inventory(5, this);

            this.layer = layer;
            this.position = position;

            texture = content.Load<Texture2D>("Sprites/" + info.texture);
            iconTexture = content.Load<Texture2D>("UI/" + info.icon);
            healthbarTexture = content.Load<Texture2D>("UI/" + info.healthbar);

            animation = new FrameAnimation(2, 32, 32, 0, 0);
            animation.FramesPerSecond = 2;

            foreach (string item in info.items)
            {
                Item i = Item.FromFile(item, Group);
                inventory.Add(i);
                if (i is Weapon)
                    weapon = i as Weapon;
            }

            if (behaviors.ContainsKey(info.behavior))
                Behavior += behaviors[info.behavior];
        }