Esempio n. 1
1
 static void moveSystem(Context context) {
     var entities = context.GetEntities(Matcher.AllOf(Matcher.Move, Matcher.Position));
     foreach(var entity in entities) {
         var move = entity.move;
         var pos = entity.position;
         entity.ReplacePosition(pos.x, pos.y + move.speed);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// override this in Scene subclasses and do your loading here. This is called from the contructor after the scene sets itself up but
        /// before begin is ever called.
        /// </summary>
        public virtual void Initialize()
        {
            Global.DebugRenderEnabled = false;
            //
            // start ECS (Game entities & components & systems)
            //
            EntityContext        = Entitas.Contexts.Default;
            Global.EntityContext = EntityContext;
            //
            // List of all entities, List of entities destroyed
            //
            GameEntities = new List <Entity>();
            Global.GameEntityToDestroy = new Dictionary <Entity, bool>();
            SceneEntities = new List <Entity>();
            Global.SceneEntityToDestroy = new Dictionary <Entity, bool>();
            //
            // start ECS (Scene UI & components)
            //
            SceneContext = Entitas.Contexts.Default;
            //SceneSystems = new Feature(null);

            Global.SceneContext = SceneContext;

            //znznznznznznznznznznznznznznznznznzn
            // Camera 2D setup
            //znznznznznznznznznznznznznznznznznzn

            Camera          = new Camera2D();
            Camera.target   = Global.WindowCenter;
            Camera.offset   = Global.WindowCenter;
            Camera.rotation = 0;
            Camera.zoom     = 1.0f;
            CameraEnabled   = false;
            CameraType2D    = Camera2DType.FollowPlayer;                                                //free camera no bounds
        }
Esempio n. 3
0
        static void groupExample(Context context) {
            context.GetGroup(Matcher.Position).GetEntities();

            // ----------------------------

            context.GetGroup(Matcher.Position).OnEntityAdded += (group, entity, index, component) => {
                // Do something
            };
        }
Esempio n. 4
0
 protected ReactiveSystem(Context context)
 {
     _collector = GetTrigger(context);
     _buffer = new List<Entity>();
 }
Esempio n. 5
0
 /// Specify the collector that will trigger the ReactiveSystem.
 protected abstract Collector GetTrigger(Context context);
Esempio n. 6
0
 public ContextStillHasRetainedEntitiesException(Context context)
     : base("'" + context + "' detected retained entities " +
     "although all entities got destroyed!",
     "Did you release all entities? Try calling context.ClearGroups() " +
     "and systems.ClearReactiveSystems() before calling " +
     "context.DestroyAllEntities() to avoid memory leaks.")
 {
 }
Esempio n. 7
0
 public ContextInfoException(Context context, ContextInfo contextInfo)
     : base("Invalid ContextInfo for '" + context + "'!\nExpected " +
          context.totalComponents + " componentName(s) but got " +
          contextInfo.componentNames.Length + ":",
          string.Join("\n", contextInfo.componentNames))
 {
 }
Esempio n. 8
0
 public ContextEntityIndexDoesNotExistException(Context context, string name)
     : base("Cannot get EntityIndex '" + name + "' from context '" +
          context + "'!", "No EntityIndex with this name has been added.")
 {
 }
Esempio n. 9
0
 public ContextEntityIndexDoesAlreadyExistException(Context context, string name)
     : base("Cannot add EntityIndex '" + name + "' to context '" + context + "'!",
          "An EntityIndex with this name has already been added.")
 {
 }
Esempio n. 10
0
        static void collectorExample(Context context) {
            var group = context.GetGroup(Matcher.Position);
            var collector = group.CreateCollector(GroupEvent.Added);

            // ----------------------------
            foreach(var e in collector.collectedEntities) {
                // do something
            }
            collector.ClearCollectedEntities();


            // ----------------------------
            collector.Deactivate();
        }
Esempio n. 11
0
 static void animatingComponent(Context context) {
     var e = context.animatingEntity;
     var isAnimating = context.isAnimating;
     context.isAnimating = true;
     context.isAnimating = false;
 }
Esempio n. 12
0
        #pragma warning disable
        static void userComponent(Context context, UserComponent component) {
            var e = context.userEntity;
            var name = context.user.name;
            var has = context.hasUser;

            context.SetUser("John", 42);
            context.ReplaceUser("Max", 24);
            context.RemoveUser();
        }