public override void Update(GameTime gameTime)
        {
            if (ElapsedTime == FireSpawnInterval)
            {
                foreach (int entityID in ActiveEntities)
                {
                    MonoGame.Extended.Entities.Entity placeholder    = Game1._world.GetEntity(entityID);
                    ECSComponents.StatusComponent     capturedStatus = placeholder.Get <ECSComponents.StatusComponent>(); // get the status component of the entity
                    if (capturedStatus.Type == Game1.EntityType.Lightning)                                                // if the entity is a Lightining Disaster
                    {
                        // call SpawnFire Here
                        ECSComponents.PositionComponent capturedPosition = placeholder.Get <ECSComponents.PositionComponent>();
                        int spawnX = (int)capturedPosition.XCoor;
                        int spawnY = (int)capturedPosition.YCoor;
                        SpawnFire(spawnX, spawnY);
                    }

                    else if (capturedStatus.Type == Game1.EntityType.Fire)      // this is where Propagate will be called
                    {
                        Propagate(entityID);
                    }
                }

                ElapsedTime = 0;
                return;
            }

            else
            {
                ElapsedTime++;
                return;
            }
        }
Exemplo n.º 2
0
        public async void SpawnFire(int initialX, int InitialY)
        {
            if (Game1.fireNum <= maxFires)
            {
                // PositionComponent
                ECSComponents.PositionComponent newPos = CalculateFireGridPos(initialX, InitialY);
                // SpriteComponent
                ECSComponents.SpriteComponent newSprite = new ECSComponents.SpriteComponent(Game1.SpriteDict["fire_1"], 1);
                // StatusComponent
                ECSComponents.StatusComponent newStatus = new ECSComponents.StatusComponent(false, Game1.EntityType.Fire);
                //hitboxComponet
                ECSComponents.CollisionBoxComponet newHitBox = new ECSComponents.CollisionBoxComponet(newSprite.Sprite, newPos);

                if (DetermineSpawnLegality(newPos))                   // if this position isn't already occupied by a fireSprite
                {
                    Entity newDisaster = Game1._world.CreateEntity(); // create the entity
                    int    newID       = newDisaster.Id;              // track the new entity's id

                    newDisaster = Game1._world.GetEntity(newID);      // spawn the new fire entity
                                                                      // attach components
                    newDisaster.Attach(newPos);
                    newDisaster.Attach(newSprite);
                    newDisaster.Attach(newStatus);
                    newDisaster.Attach(newHitBox);

                    Game1.fireNum++;

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                  () =>
                    {
                        Game1.myGamePage.CreateNewFire(newID);
                    });

                    return;
                }
                else
                {
                    return;     // fire already exists in this position so do not spawn it
                }
            }

            else
            {
                return;
            }
        }