Пример #1
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];
            }
        }
Пример #2
0
        public Entity(
            string tag, string group, string behavior,
            double health,
            int speed, int skill,
            TileLayer layer, Point position,
            Texture2D texture, Texture2D iconTexture, Texture2D healthbarTexture)
        {
            if (!init)
            {
                initializeBehaviors();
                init = true;
            }

            Tag   = tag;
            Group = group;

            Health = new StatBar(health);

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

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

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

            this.texture          = texture;
            this.iconTexture      = iconTexture;
            this.healthbarTexture = healthbarTexture;

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

            if (behaviors.ContainsKey(behavior))
            {
                Behavior += behaviors[behavior];
            }
        }
Пример #3
0
        public void Update(GameTime gameTime)
        {
            List<Point> frameRemove = new List<Point>();
            foreach (Point p in animations.Keys)
            {
                animations[p].Update(gameTime);
                if (animations[p].Finished)
                    frameRemove.Add(p);
            }

            foreach (Point p in frameRemove)
            {
                animations.Remove(p);
            }

            List<Entity> toRemove = new List<Entity>();
            foreach (Entity e in entities)
            {
                e.Update(gameTime, PlayerIndex.One);

                if (e.Health.IsEmpty)
                {
                    animations.Remove(e.Position);
                    FrameAnimation animation = new FrameAnimation(5, 32, 32, 0, 0, true);
                    animation.FramesPerSecond = 10;
                    animations.Add(e.Position, animation);
                    toRemove.Add(e);
                }
            }

            foreach (Entity e in toRemove)
            {
                string group = e.Group;
                entities.Remove(e);
                if (Group(group).Count() == 0)
                {
                    if (group != "Player")
                        groups.Remove(group);
                }
            }

            if (GroupFinished(CurrentGroup) && AnimationsFinished())
            {
                currentEntity = 0;
                foreach (Entity e in Group(CurrentGroup))
                {
                    e.EndTurn();
                    if (layer.IsCastleTile(e.Position))
                    {
                        e.Health.Heal(CastleHealAmount);
                        FrameAnimation animation = new FrameAnimation(5, 32, 32, 0, 0, true);
                        animation.FramesPerSecond = 12;
                        animations.Add(e.Position, animation);
                    }
                }
                currentGroup = ++currentGroup % groups.Count;
            }
            else
            {
                if (CurrentGroup == "Player")
                    return;

                List<Entity> cur = Group(CurrentGroup);
                if (currentEntity < cur.Count())
                {
                    cur[currentEntity].Act();
                    if (cur[currentEntity].Phase == Phase.Finished && !cur[currentEntity].Attacking && !cur[currentEntity].Moving)
                        currentEntity++;
                }
            }
        }
Пример #4
0
        public Entity(
            string tag, string group, string behavior,
            double health,
            int speed, int skill,
            TileLayer layer, Point position, 
            Texture2D texture, Texture2D iconTexture, Texture2D healthbarTexture)
        {
            if (!init)
            {
                initializeBehaviors();
                init = true;
            }

            Tag = tag;
            Group = group;

            Health = new StatBar(health);

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

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

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

            this.texture = texture;
            this.iconTexture = iconTexture;
            this.healthbarTexture = healthbarTexture;

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

            if (behaviors.ContainsKey(behavior))
                Behavior += behaviors[behavior];
        }
Пример #5
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];
        }
Пример #6
0
        public void Update(GameTime gameTime)
        {
            List <Point> frameRemove = new List <Point>();

            foreach (Point p in animations.Keys)
            {
                animations[p].Update(gameTime);
                if (animations[p].Finished)
                {
                    frameRemove.Add(p);
                }
            }

            foreach (Point p in frameRemove)
            {
                animations.Remove(p);
            }

            List <Entity> toRemove = new List <Entity>();

            foreach (Entity e in entities)
            {
                e.Update(gameTime, PlayerIndex.One);

                if (e.Health.IsEmpty)
                {
                    animations.Remove(e.Position);
                    FrameAnimation animation = new FrameAnimation(5, 32, 32, 0, 0, true);
                    animation.FramesPerSecond = 10;
                    animations.Add(e.Position, animation);
                    toRemove.Add(e);
                }
            }

            foreach (Entity e in toRemove)
            {
                string group = e.Group;
                entities.Remove(e);
                if (Group(group).Count() == 0)
                {
                    if (group != "Player")
                    {
                        groups.Remove(group);
                    }
                }
            }

            if (GroupFinished(CurrentGroup) && AnimationsFinished())
            {
                currentEntity = 0;
                foreach (Entity e in Group(CurrentGroup))
                {
                    e.EndTurn();
                    if (layer.IsCastleTile(e.Position))
                    {
                        e.Health.Heal(CastleHealAmount);
                        FrameAnimation animation = new FrameAnimation(5, 32, 32, 0, 0, true);
                        animation.FramesPerSecond = 12;
                        animations.Add(e.Position, animation);
                    }
                }
                currentGroup = ++currentGroup % groups.Count;
            }
            else
            {
                if (CurrentGroup == "Player")
                {
                    return;
                }

                List <Entity> cur = Group(CurrentGroup);
                if (currentEntity < cur.Count())
                {
                    cur[currentEntity].Act();
                    if (cur[currentEntity].Phase == Phase.Finished && !cur[currentEntity].Attacking && !cur[currentEntity].Moving)
                    {
                        currentEntity++;
                    }
                }
            }
        }