Exemplo n.º 1
0
        private void DetectEnemyDamage(Dictionary <int, IEntity> enemies, List <IEntity> linkProj, List <IEntity> items, List <IEntity> garbage)
        {
            if (!shouldCheck)
            {
                return;
            }

            List <int> deletionList = new List <int>();

            foreach (AbstractEntity proj in linkProj)
            {
                foreach (int enemy in enemies.Keys)
                {
                    IEntity currentEnemy;
                    enemies.TryGetValue(enemy, out currentEnemy);
                    if (proj != null && proj.GetBoundingRect().Intersects(currentEnemy.GetBoundingRect()))
                    {
                        ProjectileCollisionHandler.ProjectileEnemyHit(enemy, currentEnemy, (IProjectile)proj, deletionList, garbage, gameInstance);
                    }
                }
            }

            foreach (int enemyID in deletionList)
            {
                enemies.Remove(enemyID);
            }
        }
Exemplo n.º 2
0
        private void DetectDoorCollision(Dictionary <int, IEntity> enemies, List <IDoor> doors, List <IEntity> linkProj, List <IEntity> enemyProj)
        {
            Rectangle linkRect     = ((IEntity)link).GetBoundingRect();
            Boolean   alreadyMoved = false;

            foreach (IDoor door in doors)
            {
                Rectangle doorRect = door.GetBoundingRect();
                if (doorRect.Intersects(linkRect))
                {
                    if (door.DoorDestination != -1)
                    {
                        // Add more complex logic here.
                        gameInstance.dungeon.ChangeRoom(door);
                    }
                    else
                    {
                        side = blockCollision.SideOfCollision(doorRect, linkRect);
                        blockCollision.ReflectMovingEntity((IEntity)link, side);
                    }
                }


                //enemy vs blocks
                foreach (int enemy in enemies.Keys)
                {
                    // TODO: For some enemies, like the Spike and Final Boss, I don't want it to check for it's hit box
                    IEntity currentEnemy;
                    enemies.TryGetValue(enemy, out currentEnemy);
                    AbstractEntity cEnemy    = (AbstractEntity)currentEnemy;
                    Rectangle      enemyRect = cEnemy.GetBoundingRect();
                    alreadyMoved = false;

                    if (doorRect.Intersects(enemyRect))
                    {
                        side = blockCollision.SideOfCollision(doorRect, enemyRect);
                        if (!alreadyMoved) //This will prevent it from moving back twice
                        {
                            alreadyMoved = blockCollision.ReflectMovingEntity(currentEnemy, side);
                        }
                    }
                }

                //proj vs blocks
                foreach (AbstractEntity proj in linkProj)
                {
                    if (doorRect.Intersects(proj.GetBoundingRect()))
                    {
                        ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom);
                    }
                }

                foreach (AbstractEntity proj in enemyProj)
                {
                    if (doorRect.Intersects(proj.GetBoundingRect()))
                    {
                        ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void DetectBlockCollision(Dictionary <int, IEntity> enemies, List <IBlock> blocks, List <IEntity> linkProj, List <IEntity> enemyProj)
        {
            Rectangle linkRect     = ((IEntity)link).GetBoundingRect();
            Boolean   alreadyMoved = false;

            foreach (AbstractBlock block in blocks)
            {
                Rectangle blockRect = block.GetBoundingRect();

                //link vs blocks
                if (block.IsCollidable() && blockRect.Intersects(linkRect))
                {
                    side = blockCollision.SideOfCollision(blockRect, linkRect);

                    //Create a movable block class?? But how to only let it move one full space in one direction?
                    if (!alreadyMoved) //This will prevent it from moving back twice
                    {
                        /*This allows link to push blocks. Enemies can not push blocks*/
                        if (block.IsMovable() && ((block.PushSide() == side) || (block.PushSide2() == side)))
                        {
                            block.StartMoving(side);
                        }
                        alreadyMoved = blockCollision.ReflectMovingEntity((IEntity)link, side);
                    }
                }

                //enemy vs blocks
                foreach (int enemy in enemies.Keys)
                {
                    // TODO: For some enemies, like the Spike and Final Boss, I don't want it to check for it's hit box
                    IEntity currentEnemy;
                    enemies.TryGetValue(enemy, out currentEnemy);
                    IEntity   cEnemy    = currentEnemy;
                    Rectangle enemyRect = cEnemy.GetBoundingRect();
                    alreadyMoved = false;

                    if (((block.IsCollidable() && cEnemy.IsCollidable()) || block.IsTall()) && blockRect.Intersects(enemyRect))
                    {
                        side = blockCollision.SideOfCollision(blockRect, enemyRect);
                        if (!alreadyMoved) //This will prevent it from moving back twice
                        {
                            alreadyMoved = blockCollision.ReflectMovingEntity(currentEnemy, side);
                        }
                    }
                }

                //proj vs blocks
                foreach (AbstractEntity proj in linkProj)
                {
                    if (block.IsTall() && blockRect.Intersects(proj.GetBoundingRect()))
                    {
                        ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom);
                    }
                }

                foreach (AbstractEntity proj in enemyProj)
                {
                    if (block.IsTall() && blockRect.Intersects(proj.GetBoundingRect()))
                    {
                        ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom);
                    }
                }
            }
        }