예제 #1
0
        public Spikes(EntityInfo entityInfo) : base(entityInfo)
        {
            // Starting HP
            HP = 1000;

            // Get data
            ZInterpreter data = new ZInterpreter(entityInfo.Data);

            if (data.HasKey("direction"))
            {
                Direction = data.GetString("direction");
            }

            if (data.HasKey("damage"))
            {
                Damage = data.GetInt("damage");
            }

            // Build entity
            Entity = new Entity(entity => {
                entity.Name         = "Enemy";
                entity.LayerName    = "Main";
                entity.SortingLayer = 6;
                entity.Position     = (entityInfo.Position * 16);
                entity.Origin       = new Vector2(0f, 0f);

                entity.AddComponent(new Collider()).Run <Collider>(c => { c.TriggerType = Collider.TriggerTypes.NonSolid; c.ColliderType = Collider.ColliderTypes.Box; });

                entity.Data.Add("damage", Damage.ToString());

                entity.AddComponent(new Sprite()).Run <Sprite>(sprite => {
                    Sprite = sprite;
                    sprite.LoadTexture("Entities/Enemies/Spikes");
                });
            });
        }
예제 #2
0
        public WallCrab(EntityInfo entityInfo) : base(entityInfo)
        {
            // Starting HP
            HP = 5;

            // Get data
            ZInterpreter data = new ZInterpreter(entityInfo.Data);

            if (data.HasKey("direction"))
            {
                Direction = data.GetString("direction");
            }

            Planted = (data.HasKey("planted")) ? data.GetString("planted") : "top";

            if (data.HasKey("speed"))
            {
                Speed = data.GetFloat("speed");
            }

            RotateSpeed = RotateSpeed * Speed * 12;

            if (data.HasKey("damage"))
            {
                Damage = data.GetInt("damage");
            }

            // Collider
            TriggerCollider = new Entity(entity => {
                entity.Name         = "Enemy";
                entity.LayerName    = "Main";
                entity.SortingLayer = 100;
                entity.Data.Add("damage", Damage.ToString());

                entity.AddComponent(new Collider()).Run <Collider>(c => { c.ColliderType = Collider.ColliderTypes.Box; c.TriggerType = Collider.TriggerTypes.NonSolid; });

                entity.AddComponent(new Sprite()).Run <Sprite>(sprite => {
                    sprite.BuildRectangle(new Point(10, 10), Color.White);
                    sprite.Visible = false;
                });

                StaticCoroutines.CoroutineHelper.Always(() => {
                    if (Planted == "top")
                    {
                        entity.Position = Entity.Position + new Vector2(0, -8);
                    }
                    else if (Planted == "left")
                    {
                        entity.Position = Entity.Position + new Vector2(-8, 0);
                    }
                    else if (Planted == "bottom")
                    {
                        entity.Position = Entity.Position + new Vector2(0, 8);
                    }
                    else if (Planted == "right")
                    {
                        entity.Position = Entity.Position + new Vector2(8, 0);
                    }
                });
            });

            // Build entity
            Entity = new Entity(entity => {
                entity.LayerName    = "Main";
                entity.SortingLayer = 6;
                entity.Position     = (entityInfo.Position * 16);
                entity.Origin       = new Vector2(0.5f, 1f);

                entity.AddComponent(new Collider()).Run <Collider>(c => { c.ColliderType = Collider.ColliderTypes.Box; c.TriggerType = Collider.TriggerTypes.NonSolid; });

                if (Planted == "top")
                {
                    entity.Position += new Vector2(12, 16);
                }
                else if (Planted == "right")
                {
                    entity.Position += new Vector2(0, 16);
                    entity.Rotation += (float)Math.PI / 2;
                }

                entity.AddComponent(new Sprite()).Run <Sprite>(sprite => {
                    Sprite = sprite;

                    sprite.LoadTexture("Entities/Enemies/WallCrab");
                    sprite.AddAnimation(new Animation("walking", 0.2f, "24,16".ToPoint(), "0,0 1,0 2,0 3,0 4,0 5,0".ToPointList()));
                    sprite.RunAnimation("walking");
                });

                entity.AddComponent(new Collider()).Run <Collider>(pc => { Collider = pc; });
            });
        }