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;
            }
        }
Exemplo n.º 3
0
        public bool CheckEntityStatus()
        {
            bool entity_destroyed = false;

            /// Iterate through all entities w/ Status Component
            foreach (var entityId in ActiveEntities)
            {
                var entity = GetEntity(entityId);
                var status = entity.Get <StatusComponent>();

                /// Check if Entity is destroyed
                if (status.IsReadyForCleanup)
                {
                    if (status.Type == Game1.EntityType.Fire)       // if the entity being destroyed is fired, it's grid position must be freed up
                    {
                        // to do this we must get the entity's indicies in the fire grid, then we set that position in the array == 0
                        ECSComponents.PositionComponent capturedPos = entity.Get <ECSComponents.PositionComponent>();
                        int fireSpriteWidth  = Game1.SpriteDict["fire_1"].texture.Width;
                        int fireSpriteHeight = Game1.SpriteDict["fire_1"].texture.Height;

                        int fireGridXIndex = ((int)capturedPos.XCoor - ((int)capturedPos.XCoor % fireSpriteWidth)) / fireSpriteWidth;
                        int fireGridYIndex = ((int)capturedPos.YCoor - ((int)capturedPos.YCoor % fireSpriteHeight)) / fireSpriteHeight;

                        fireGridXIndex -= 1;
                        fireGridYIndex -= 1;

                        Game1.fireGrid[fireGridXIndex, fireGridYIndex] = 0;
                        Game1.fireNum--;
                    }
                    if (status.Type == Game1.EntityType.Lightning)
                    {
                        Game1.cloudNum--;
                    }

                    DestroyEntity(entity);
                    Game1._world.DestroyEntity(entity);   // Removes entity from the world
                    entity_destroyed = true;
                }
            }

            return(entity_destroyed);
        }
        public override void Draw(GameTime gameTime)    // overridden draw function that will render all entities with a sprite component every Darw() call
        {
            Game1.spriteBatch.Begin();
            foreach (var entityID in ActiveEntities)
            {
                // Get the entity that the entityID references
                Entity entity = Game1._world.GetEntity(entityID);

                //      **Get Position**
                // Pull the PositionComponent from the entity
                ECSComponents.PositionComponent entityPositionComponent = entity.Get <ECSComponents.PositionComponent>();
                // Get the coordinates of the entity from the entity's PositionComponent
                var entityX = entityPositionComponent.XCoor;
                var entityY = entityPositionComponent.YCoor;
                var angle   = entityPositionComponent.Angle;

                //      **Get Sprite**
                // Pull the SpriteComponent from the entity
                ECSComponents.SpriteComponent entitySpriteComponent = entity.Get <ECSComponents.SpriteComponent>();
                // Get the Texture2D of the entity from the entity's SpriteComponent
                SpriteClass sprite = entitySpriteComponent.Sprite;
                Microsoft.Xna.Framework.Graphics.Texture2D texture = sprite.texture;
                float scale = entitySpriteComponent.Scale;

                // draw the entity
                Vector2 spritePosition = new Vector2(entityX, entityY);
                Game1.spriteBatch.Draw(texture,
                                       spritePosition,
                                       null,
                                       Color.White,
                                       angle,
                                       new Vector2(texture.Width / 2, texture.Height / 2),
                                       new Vector2(scale, scale),
                                       Microsoft.Xna.Framework.Graphics.SpriteEffects.None,
                                       0f);
            }
            Game1.spriteBatch.End();
        }