예제 #1
0
 /// <summary>
 /// Removes all components.
 /// </summary>
 /// <param name="context">The context.</param>
 public static void RemoveAllComponents(this IWorldContext context)
 {
     foreach (var c in context.Components)
     {
         context.RemoveComponent(c);
     }
 }
예제 #2
0
파일: Score.cs 프로젝트: giacomelli/Doog
        private Score(Point position, Snake snake, IWorldContext ctx)
            : base(position, ctx)
        {
            snake.FoodEaten += delegate
            {
                var effect = new RectangleComponent(snake.Head.Transform.Position, ctx)
                {
                    Pixel = '+'.DarkRed()
                };

                effect
                .Transform
                .MoveTo(Transform.Position, 1f, Easing.OutCubic)
                .Do(() =>
                {
                    ctx.RemoveComponent(effect);
                })
                .Once();

                this
                .To(points, points + 10, 1f, Easing.InOutQuint, v => points = (int)v)
                .Once();
            };

            Transform.CentralizePivot();
        }
예제 #3
0
 public override void InitializeRound(IWorldContext context)
 {
     m_context.Cycle = context.Cycle;
     m_roundBot      = context.GetBotsWithKindOfAbility <ISortingBotAbility> () [0];
     m_ability       = context.GetBotAbility <ISortingBotAbility> (m_roundBot);
     m_ability.Initialize(m_context);
 }
예제 #4
0
        /// <summary>
        /// Updates the environment (run a cycle).
        /// </summary>
        /// <param name="context">The world context.</param>
        public override void Update(IWorldContext context)
        {
            Play(m_crossBot, m_crossBotAbility, m_crossBotEnviromentContext);

            if (HasWinner())
            {
                MakeBotsRank(m_crossBot, m_noughtBot, false, context.Cycle);
                return;
            }

            if (IsDrawn())
            {
                MakeBotsRank(m_crossBot, m_noughtBot, true, context.Cycle);
                return;
            }

            Play(m_noughtBot, m_noughtBotAbility, m_noughtBotEnviromentContext);

            if (HasWinner())
            {
                MakeBotsRank(m_noughtBot, m_crossBot, false, context.Cycle);
                return;
            }

            if (IsDrawn())
            {
                MakeBotsRank(m_noughtBot, m_crossBot, true, context.Cycle);
                return;
            }
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RectangleComponent"/> class.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 /// <param name="context">The context.</param>
 public RectangleComponent(float x, float y, IWorldContext context)
     : base(context)
 {
     Transform = new Transform(x, y, context);
     Pixel     = new Pixel('#');
     Filled    = false;
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LineComponent"/> class.
 /// </summary>
 /// <param name="pointA">The point a.</param>
 /// <param name="pointB">The point b.</param>
 /// <param name="context">The context.</param>
 public LineComponent(Point pointA, Point pointB, IWorldContext context)
     : base(context)
 {
     Transform = new Transform(pointA.X, pointA.Y, context);
     PointB    = pointB;
     Pixel     = new Pixel('#');
 }
예제 #7
0
        /// <summary>
        /// Opens the scene.
        /// </summary>
        /// <typeparam name="TScene">The type of the scene.</typeparam>
        /// <param name="context">The context.</param>
        public static void OpenScene <TScene>(this IWorldContext context)
            where TScene : IScene
        {
            var scene = Activator.CreateInstance(typeof(TScene), context) as IScene;

            context.OpenScene(scene);
        }
예제 #8
0
        /// <summary>
        /// The method creates a new entity with the only component that's already attached to it.
        /// The component is TDisposableComponent. All entities that have that component are destroyed
        /// at an end of a frame with a special system.
        /// </summary>
        /// <param name="worldContext">A reference to IWorldContext implementation</param>
        /// <param name="name">A name of an entity (optional)</param>
        /// <returns>The method returns an identifier of created entity</returns>

        public static EntityId CreateDisposableEntity(this IWorldContext worldContext, string name = null)
        {
            IEntity entity = worldContext.GetEntityById(worldContext.CreateEntity(name));

            entity.AddComponent <TDisposableComponent>();

            return(entity.Id);
        }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Transform"/> class.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 /// <param name="context">The context.</param>
 public Transform(float x, float y, IWorldContext context)
     : base(context)
 {
     _scale = Point.Zero;
     _pivot = Point.Zero;
     _originalBoundingBox = new Rectangle(x, y, 0, 0);
     Position             = new Point(x, y);
 }
예제 #10
0
    public ImprovedSpawnSystem(IWorldContext worldContext, GameObject prefab, IGameObjectFactory factory)
    {
        mWorldContext = worldContext;

        mPrefab = prefab;

        mFactory = factory;
    }
예제 #11
0
        public void InitializeTest()
        {
            ctx = Substitute.For <IWorldContext>();
            ctx.LogSystem.Returns(Substitute.For <ILogSystem>());
            ctx.Time.Returns(Substitute.For <ITime>());

            owner = new Transform(ctx);
        }
예제 #12
0
        public void Init()
        {
            mWorldContext = Substitute.For <IWorldContext>();
            mWorldContext.GetEntitiesWithAll().ReturnsForAnyArgs(new List <EntityId> {
            });

            mSystemManager = new SystemManager(mWorldContext);
        }
예제 #13
0
파일: Wall.cs 프로젝트: giacomelli/Doog
        public static Wall Create(float x, float y, float scaleX, float scaleY, IWorldContext context)
        {
            var wall = new Wall((int)x, (int)y, context);

            wall.Transform.Scale = new Point(scaleX, scaleY);

            return(wall);
        }
예제 #14
0
        public PureReactiveSystemAdapter(IWorldContext worldContext, ReactiveSystemFilter systemFilter, ReactiveLambdaSystem lambdaSystem)
        {
            mWorldContext = worldContext ?? throw new System.ArgumentNullException("worldContext");

            mReactiveLambdaSystem = lambdaSystem ?? throw new System.ArgumentNullException("lambdaSystem");

            mReactiveSystemFilter = systemFilter ?? throw new System.ArgumentNullException("systemFilter");
        }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InGameLogSystem"/> class.
 /// </summary>
 /// <param name="bounds">The bounds.</param>
 /// <param name="context">The context.</param>
 public InGameLogSystem(Rectangle bounds, IWorldContext context)
     : base(context)
 {
     this._bounds = bounds;
     Context      = context;
     Enabled      = true;
     Tag          = "InGameLogSystem";
     context.AddComponent(this);
 }
예제 #16
0
        public SnakeTile(float x, float y, IWorldContext context, Action onCollisionFood, Action onCollisionTile, Action onCollisionWall)
            : base(x, y, context)
        {
            this.onCollisionFood = onCollisionFood;
            this.onCollisionTile = onCollisionTile;
            this.onCollisionWall = onCollisionWall;

            Pixel = BodyPixel;
        }
예제 #17
0
파일: Score.cs 프로젝트: giacomelli/Doog
        public static Score Create(Point position, Snake snake, IWorldContext ctx)
        {
            var textSize = snake.Context.FontSystem.GetFont().GetTextSize("000000");

            position -= textSize;
            position -= new Point(1, 0);

            return(new Score(position, snake, ctx));
        }
예제 #18
0
        /// <summary>
        /// Removes the components without tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tags">The tags.</param>
        public static void RemoveComponentsWithoutTag(this IWorldContext context, params string[] tags)
        {
            var toRemove = context.Components.GetWithoutTag(tags);

            foreach (var c in toRemove)
            {
                context.RemoveComponent(c);
            }
        }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CircleComponent"/> class.
 /// </summary>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 /// <param name="radius">The radius.</param>
 /// <param name="context">The context.</param>
 public CircleComponent(float x, float y, float radius, IWorldContext context)
     : base(context)
 {
     Transform = new Transform(x, y, context)
     {
         Scale = new Point(radius * 2)
     };
     Pixel  = new Pixel('#');
     Filled = true;
 }
예제 #20
0
        public void Respawn(IWorldContext worldContext)
        {
            var environment = worldContext.GetOption(WorldOption.Environment);

            _networkClient.Send(new MessageClientRespawn.Message(
                                    environment.Id,
                                    _client.Player.GameMode,
                                    LevelType
                                    ));
        }
예제 #21
0
        /// <summary>
        /// Opens the scene if specified key is down.
        /// </summary>
        /// <typeparam name="TScene">The type of the scene.</typeparam>
        /// <param name="context">The context.</param>
        /// <param name="ifKeyIsDown">If key is down.</param>
        /// <returns></returns>
        public static IWorldContext OpenScene <TScene>(this IWorldContext context, Keys ifKeyIsDown)
            where TScene : IScene
        {
            if (context.InputSystem.IsKeyDown(ifKeyIsDown))
            {
                context.OpenScene <TScene>();
            }

            return(context);
        }
예제 #22
0
파일: Controller.cs 프로젝트: r2d2m/TinyECS
    private void Awake()
    {
        mWorldContext = new WorldContextFactory().CreateNewWorldInstance();

        mSystemManager = new SystemManager(mWorldContext);

        WorldContextsManagerUtils.CreateWorldContextManager(mWorldContext, "WorldContextManager_System");
        SystemManagerObserverUtils.CreateSystemManagerObserver(mSystemManager, "SystemManagerObserver_System");

        mSystemManager.Init();
    }
예제 #23
0
파일: BaseView.cs 프로젝트: r2d2m/TinyECS
        /// <summary>
        /// The method prepares the view for initialization step
        /// </summary>
        /// <param name="worldContext">A reference to IWorldContext implementation</param>

        public void PreInit(IWorldContext worldContext)
        {
            WorldContext = worldContext;

            // create a new event which is an entity with attached component to inform system to register this view in the world's context
            IEntity registerViewRequestEntity = worldContext.GetEntityById(worldContext.CreateEntity());

            registerViewRequestEntity.AddComponent(new TOnViewWaitForInitEventComponent {
                mView = this
            });
        }
예제 #24
0
        public void Init()
        {
            mWorldContext = new WorldContextFactory().CreateNewWorldInstance();

            mSystemManager = new SystemManager(mWorldContext);

            mRegisterViewsSystem = new RegisterViewSystem(mWorldContext);

            mSystemManager.RegisterSystem(mRegisterViewsSystem);

            mSystemManager.Init();
        }
예제 #25
0
        /// <summary>
        /// The extension method returns a new allocated manager of world contexts
        /// </summary>
        /// <param name="worldContext"></param>
        /// <param name="name">A name of a game object that will have WorldContextsManager component</param>
        /// <returns>The extension method returns a new allocated manager of world contexts</returns>

        public static WorldContextsManager CreateWorldContextManager(this IWorldContext worldContext, string name = null)
        {
            GameObject worldContextsManagerGO = new GameObject(name);

            WorldContextsManager worldContextsManager = worldContextsManagerGO.AddComponent <WorldContextsManager>();

            worldContextsManager.WorldContext = worldContext;

            worldContextsManager.PrepareViews();

            return(worldContextsManager);
        }
예제 #26
0
        public void InitializeTest()
        {
            sinceSceneStart = 0;
            ctx             = Substitute.For <IWorldContext>();
            ctx.LogSystem.Returns(Substitute.For <ILogSystem>());
            var time = Substitute.For <ITime>();

            time.SinceSceneStart.Returns(c => sinceSceneStart);
            ctx.Time.Returns(time);

            owner = new Transform(ctx);
        }
예제 #27
0
파일: Portal.cs 프로젝트: giacomelli/Doog
        public Portal(Point position, IWorldContext ctx)
            : base(new Point((int)position.X, (int)position.Y), ctx)
        {
            Transform.Scale = DefaultScale;

            teleportEffect = new RectangleComponent(Transform.Position, 3, ctx)
            {
                Pixel   = '.'.Blue(),
                Enabled = false
            };
            teleportEffect.Transform.CentralizePivotX();
        }
예제 #28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Doog.ComponentBase"/> class.
        /// </summary>
        /// <param name="context">The world context.</param>
        /// <param name="addToContext">If set to <c>true</c> the component will be added to context.</param>
        protected ComponentBase(IWorldContext context, bool addToContext)
        {
            Context   = context;
            _enabled  = true;
            Tag       = GetType().Name;
            _children = new List <IComponent>();

            if (addToContext)
            {
                context.AddComponent(this);
            }
        }
예제 #29
0
        public void InitializeTest()
        {
            sinceSceneStart = 0;
            ctx             = Substitute.For <IWorldContext>();
            ctx.LogSystem.Returns(Substitute.For <ILogSystem>());
            var time = Substitute.For <ITime>();

            time.SinceSceneStart.Returns(c => sinceSceneStart);
            ctx.Time.Returns(time);

            owner = new RectangleComponent(5, 10, ctx);
            owner.Transform.Scale = new Point(20, 70);
        }
예제 #30
0
        /// <summary>
        /// Opens the scene with the specified name.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="name">The scene name.</param>
        /// <exception cref="ArgumentException">Could not find a scene with name '{0}'".With(name)</exception>
        public static void OpenScene(this IWorldContext context, string name)
        {
            var sceneType = Type.GetType(name) ?? context.GetType().Assembly.GetType(name);

            if (sceneType == null)
            {
                throw new ArgumentException($"Could not find a scene with name '{name}'");
            }

            var scene = Activator.CreateInstance(sceneType, context) as IScene;

            context.OpenScene(scene);
        }