Пример #1
0
        // constructor
        public Scene(string id)
        {
            // initialize properties
            this.Id            = id;
            this.NamedEntities = new Dictionary <string, Entity>();
            this.Entities      = new List <Entity>();

            // load config
            if (this.config == null)
            {
                this.config = Program.LoadJsonConfig(id + ".json");
            }

            // create entities defined in config file
            foreach (var item in this.config)
            {
                if (item.entity == null)
                {
                    continue;
                }

                Entity e = null;

                if (item.entity == "TextEntity")
                {
                    e = TextEntity.CreateFromConfig(item);
                }

                if (item.entity == "SpriteEntity")
                {
                    e = SpriteEntity.CreateFromConfig(item);
                }

                if (item.entity == "BoxEntity")
                {
                    e = BoxEntity.CreateFromConfig(item);
                }

                if (item.motion != null)
                {
                    e.Motion = MotionComponent.CreateFromConfig(e, item.motion);
                }

                this.AddEntity(e);
            }
        }
Пример #2
0
        // static methods
        static public BoxEntity CreateFromConfig(dynamic item)
        {
            string id        = item.id;
            float  width     = item.width ?? 100;
            float  height    = item.height ?? 100;
            float  thickness = item.thickness ?? 5;
            Color  color     = (item.color == null) ? Color.Gray : Color.FromName((string)item.color);

            // left/top fields will overwrite x/y if both exist
            float x    = item.x ?? 0;
            float y    = item.y ?? 0;
            float left = x - width / 2;
            float top  = y - height / 2;

            BoxEntity b = new BoxEntity(id, x, y, width, height, thickness, color);

            return(b);
        }