Example #1
0
 /// <summary>
 /// Specialcase that creates an Entity that spawns creeps from a CreepSpawner.
 /// This loads necessary data from XNA content pipeline.
 /// </summary>
 /// <param name="Model"><see cref="SharedContent.CreepSpawner"/></param>
 /// <param name="Content">XNA content pipeline</param>
 public Entity(SharedContent.CreepSpawner Model, ContentManager Content)
     :
     this(Content.Load <SharedContent.EntityModel>("EntityPrototypes/CreepSpawner"), Content)
 {
     SharedContent.EntityModel prototype = Content.Load <SharedContent.EntityModel>(Model.CreepPrototypeAsset);
     Physics.Position = Model.Position;
     Behaviour        = new Behaviours.CreepSpawner(Model.Start, Model.End);
     if (Model.RenderableAsset != null && Model.RenderableAsset != "")
     {
         Renderable = new Sprite(Content.Load <Texture2D>(Model.RenderableAsset));
     }
 }
Example #2
0
        /// <summary>
        /// Loads a generic Entity from data coming from XNA content pipeline. This instanciates the classes named
        /// in the model using reflection.
        /// </summary>
        /// <param name="Model">The name of Model to load.</param>
        /// <param name="Content">Content pipeline to use.</param>
        public Entity(SharedContent.EntityModel Model, ContentManager Content) : this()
        {
            // Hairy hacks to allow dynamic creation of classes from data files.
            Physics          = new Physics(Model.Speed);
            Physics.Position = Model.Position;
            CombatStats      = Content.Load <SharedContent.CombatStats>(Model.CombatStatsAsset).clone();
            Abilities        = new List <IAbility>();
            Assembly me = Assembly.GetExecutingAssembly();

            foreach (SharedContent.Ability ability in Model.Abilities)
            {
                Object abilityHandle = me.CreateInstance("progarkspill.GameObjects.Abilities." +
                                                         ability.AbilityTypeName);
                IAbility control = (IAbility)abilityHandle;
                control.Stats = Content.Load <SharedContent.AbilityStats>(ability.AbilityStatsAsset).clone();;
                Abilities.Add(control);
                if (ability.EntityModelAsset != null && ability.EntityModelAsset != "")
                {
                    control.ProjectilePrototype = new Entity(Content.Load <SharedContent.EntityModel>(ability.EntityModelAsset), Content);
                }
            }
            Collidable = (ICollidable)me.CreateInstance("progarkspill.GameObjects.Collidables." +
                                                        Model.CollidableType);
            if (Model.CollisionHandlerType != null && Model.CollisionHandlerType != "")
            {
                CollisionHandler = (ICollisionHandler)me.CreateInstance("progarkspill.GameObjects.CollisionHandlers." +
                                                                        Model.CollisionHandlerType);
            }
            if (Model.RenderableAsset != null && Model.RenderableAsset != "")
            {
                Renderable = new Sprite(Content.Load <Texture2D>(Model.RenderableAsset));
            }
            Status = (IStatus)me.CreateInstance("progarkspill.GameObjects.Statuses." +
                                                Model.StatusType);
            Behaviour = (IBehaviour)me.CreateInstance("progarkspill.GameObjects.Behaviours." +
                                                      Model.BehaviourType);
            Stats.Level = Model.Level;
        }