public void AddMotionComponent()
 {
     if (this.Motion == null)
     {
         this.Motion = new MotionComponent(this);
     }
 }
Exemple #2
0
        // static method
        static public MotionComponent CreateFromConfig(Entity e, dynamic item)
        {
            float speedX = 0, speedY = 0;

            if (item.speed != null)
            {
                speedX = item.speed.x ?? 0;
                speedY = item.speed.y ?? 0;
            }

            MotionComponent motion = new MotionComponent(e);

            motion.Speed = new Vector(speedX, speedY);
            e.Motion     = motion;

            if (item.easing != null)
            {
                Vector     target = new Vector((float)item.easing.target.x, (float)item.easing.target.y);
                int        frames = item.easing.frames;
                EasingType type   = item.easing.type;
                motion.AddEaseMotion(target, frames, type);
            }

            return(motion);
        }
Exemple #3
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);
            }
        }