Beispiel #1
0
        // Returns the strongest barrier at that location
        private ExplosionBarrier GetBarrierAtLocation(Point point)
        {
            ExplosionBarrier strongestBarrier = ExplosionBarrier.None;

            entityGrid.QueryUniqueIdsAt(point.X, point.Y, barrierQueryList);
            foreach (int uniqueId in barrierQueryList)
            {
                Entity there = EntityManager.TryGetEntityByUniqueId(uniqueId);
                if (there != null)
                {
                    ExplosionImpact explosionImpact = (ExplosionImpact)EntityManager.GetComponent(there, ComponentTypeIds.ExplosionImpact);
                    if (explosionImpact != null)
                    {
                        strongestBarrier = (ExplosionBarrier)Math.Max((int)explosionImpact.Barrier, (int)strongestBarrier);
                    }
                }
            }
            return(strongestBarrier);
        }
Beispiel #2
0
 protected override void OnProcessEntities(GameTime gameTime, IEnumerable <int> entityIdCollection)
 {
     // We could use the physics system to handle grabbing powerups, but it is fairly straightforward to just do it here with our grid.
     foreach (int liveId in entityIdCollection)
     {
         Placement placement = placementComponents.GetComponentFor(liveId);
         entityGrid.QueryUniqueIdsAt(placement.Position.ToInteger(), uniqueIdWorker);
         foreach (int uniqueIdOverlap in uniqueIdWorker)
         {
             Entity     possiblePlayerEntity = EntityManager.GetEntityByUniqueId(uniqueIdOverlap);
             PlayerInfo player = (PlayerInfo)EntityManager.GetComponent(possiblePlayerEntity, ComponentTypeIds.Player);
             if (player != null)
             {
                 // A player will pick this up!
                 PickUpPowerUp(possiblePlayerEntity.LiveId, player, powerUpComponents.GetComponentFor(liveId));
                 // Delete this powerup.
                 EntityManager.DelayFreeByLiveId(liveId, EntityFreeOptions.Deep);
                 break;
             }
         }
     }
 }
Beispiel #3
0
 protected override int OnHandleMessage(Entity target, uint message, ref MessageData data, object sender)
 {
     switch (message)
     {
     // This returns the unique id of the first entity at a particular spot that contains a particular component.
     case Messages.QueryComponentAtGrid:
         int uniqueIdFound = EntityManager.InvalidEntityUniqueId;
         entityGrid.QueryUniqueIdsAt(data.Int32, data.Int32Alt, uniqueIdWorker);
         foreach (int uniqueIdConsider in uniqueIdWorker)
         {
             if (EntityManager.GetComponent(EntityManager.GetEntityByUniqueId(uniqueIdConsider), data.Int32AltAlt) != null)
             {
                 uniqueIdFound = uniqueIdConsider;
                 break;
             }
         }
         data.SetIntResponse(uniqueIdFound);
         data.Handled = true;
         break;
     }
     return(0);
 }
Beispiel #4
0
        private void MaybeSendDeathBlock(GameState gameState)
        {
            // How many spots for death blocks?
            int count = (gameState.Bounds.Width - 2) * (gameState.Bounds.Height - 2);
            // How many seconds before they start appearing?
            float secondsToAppear = GameConstants.DeathBlocksArrivePeriod * count;

            Rectangle bounds          = gameState.Bounds;
            float     timeAppearing   = Math.Max(0, secondsToAppear - gameState.TimeRemaining);
            int       numberAppearing = (int)(timeAppearing / GameConstants.DeathBlocksArrivePeriod);

            Debug.Assert(numberAppearing <= count);

            // Show a warning?
            timeRunningOut = ((numberAppearing == 0) && (secondsToAppear < GameConstants.TimeRunningOutWarningTime));

            while (numberAppearing > gameState.DeathBlockCount)
            {
                // Send a block.
                Entity deathBlock = EntityManager.AllocateForGeneratedContent("DeathBlock", Universe.TopLevelGroupUniqueIdBase);
                // Figure out where! That's the hard part.
                Point     position  = deathBlockSpiralPoints[gameState.DeathBlockCount];
                Placement placement = (Placement)EntityManager.GetComponent(deathBlock, ComponentTypeIds.Placement);
                placement.Position = new Vector3(position.X, position.Y, 0);
                EntityManager.SendMessage(deathBlock, Messages.PlaySound, "Thud".CRC32Hash(), GameConstants.ThudVolume, null);

                // Send a kill messages to any entity here.
                entityGrid.QueryUniqueIdsAt(position, uniqueIdWorker);
                foreach (int uniqueIdHere in uniqueIdWorker)
                {
                    EntityManager.SendMessage(EntityManager.GetEntityByUniqueId(uniqueIdHere), Messages.DirectKill, null);
                }

                gameState.DeathBlockCount++;
            }
        }