Ejemplo n.º 1
0
        private void SetupLevel(LevelComponent levelComponent)
        {
            levelComponent.HasLoaded.Value = false;

            defaultCollection.RemoveEntitiesContaining(typeof(GameBoardComponent),
                                                       typeof(FoodComponent), typeof(WallComponent),
                                                       typeof(EnemyComponent), typeof(ExitComponent));

            Observable.Interval(TimeSpan.FromSeconds(_gameConfiguration.IntroLength))
            .First()
            .Subscribe(x => levelComponent.HasLoaded.Value = true);

            defaultCollection.CreateEntity(new GameBoardBlueprint());

            for (var i = 0; i < levelComponent.FoodCount; i++)
            {
                defaultCollection.CreateEntity(new FoodBlueprint());
            }

            for (var i = 0; i < levelComponent.WallCount; i++)
            {
                defaultCollection.CreateEntity(new WallBlueprint());
            }

            for (var i = 0; i < levelComponent.EnemyCount; i++)
            {
                defaultCollection.CreateEntity(new EnemyBlueprint());
            }

            defaultCollection.CreateEntity(new ExitBlueprint());
        }
Ejemplo n.º 2
0
        protected override void ApplicationStarted()
        {
            defaultCollection = EntityDatabase.GetCollection();

            var levelBlueprint  = new LevelBlueprint();
            var levelEntity     = defaultCollection.CreateEntity(levelBlueprint);
            var player          = defaultCollection.CreateEntity(new PlayerBlueprint(_gameConfiguration.StartingFoodPoints));
            var playerView      = player.GetComponent <ViewComponent>();
            var playerComponent = player.GetComponent <PlayerComponent>();
            var levelComponent  = levelEntity.GetComponent <LevelComponent>();

            levelComponent.Level.DistinctUntilChanged()
            .Subscribe(x =>
            {
                var gameObject = playerView.View as GameObject;
                gameObject.transform.position = Vector3.zero;
                SetupLevel(levelComponent);
            });

            EventSystem.Receive <PlayerKilledEvent>()
            .Delay(TimeSpan.FromSeconds(_gameConfiguration.IntroLength))
            .Subscribe(x =>
            {
                levelBlueprint.UpdateLevel(levelComponent, 1);
                playerComponent.Food.Value = _gameConfiguration.StartingFoodPoints;
                SetupLevel(levelComponent);
            });
        }
Ejemplo n.º 3
0
        public IEntity PlayBackgroundMusic(string name)
        {
            var entity = defaultCollection.CreateEntity();

            entity.AddComponents(new MusicComponent(), new RawResourceComponent {
                Name = name
            });
            return(entity);
        }
        public override void EventTriggered(ShootBulletEvent eventData)
        {
            var bulletEntity = _defaultCollection.CreateEntity();

            bulletEntity.AddComponent <BulletComponent>();
            bulletEntity.AddComponent <ViewComponent>();
        }
Ejemplo n.º 5
0
        public static IEntity CreateEntity(this IEntityCollection entityCollection, IEnumerable <IBlueprint> blueprints)
        {
            var entity = entityCollection.CreateEntity();

            entity.ApplyBlueprints(blueprints);
            return(entity);
        }
Ejemplo n.º 6
0
        public static IEntity CreateEntity(this IEntityCollection entityCollection, params IBlueprint[] blueprints)
        {
            var entity = entityCollection.CreateEntity();

            entity.ApplyBlueprints(blueprints);
            return(entity);
        }
Ejemplo n.º 7
0
 protected virtual void SetupEntities()
 {
     for (var i = 0; i < EntityCount; i++)
     {
         var entity = _collection.CreateEntity();
         SetupEntity(entity);
     }
 }
Ejemplo n.º 8
0
        public void Process(IEntity entity)
        {
            var viewComponent = entity.GetComponent <ViewComponent>();
            var view          = viewComponent.View as GameObject;
            var blueprint     = new SelfDestructBlueprint(view.transform.position);

            _defaultCollection.CreateEntity(blueprint);
        }
 public void CreateEntitiesWithComponentsThenRemoveThemAll()
 {
     for (var i = 0; i < Iterations; i++)
     {
         var entity = _defaultEntityCollection.CreateEntity();
         entity.AddComponents(_availableComponents);
         entity.RemoveComponents(_availableComponents);
     }
 }
Ejemplo n.º 10
0
        protected override void ApplicationStarted()
        {
            _collection  = EntityDatabase.GetCollection();
            _groupSystem = new ExampleReactToGroupSystem();

            for (var i = 0; i < EntityCount; i++)
            {
                var entity = _collection.CreateEntity();
                entity.AddComponents(new SimpleReadComponent(), new SimpleWriteComponent());
            }

            RunSingleThread();
            RunMultiThreaded();
        }
Ejemplo n.º 11
0
        public override void OnEventReceived(NewEnemyWaveEvent @event)
        {
            var receiver = @event.GameComponent;

            receiver.CurrentWave.Value = @event.WaveNumber;

            collection.CreateEntity(new MeleeBlueprint
            {
                WaveNumber = @event.WaveNumber,
                Position   = new Vector2(20.0f, 24.0f),
                Speed      = 0.2f,
                Angle      = MathF.PI / 4.0f,
                Health     = 20.0f,
                Damage     = 12.0f
            });
        }
Ejemplo n.º 12
0
        public IEntity CreateUI <T>(T blueprint) where T : IBlueprint
        {
            IEntity entity = defaultConllection.CreateEntity(blueprint);

            return(entity);
        }