public List <CollectableEntityType> Collect(ICollidableEntity collidableEntity)
        {
            List <CollectableEntityType> collectedEntityTypes = new List <CollectableEntityType>();
            Rectangle collidableBounds = collidableEntity.CollisionBounds;

            Point[] collidablePixels          = collidableEntity.CollisionPixels;
            Matrix  collidableTransformMatrix = collidableEntity.CollisionTransformMatrix;

            Point[] collidableTransformedPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(collidablePixels, collidableTransformMatrix);
            foreach (ICollectableEntity collectableEntity in collectableEntities)
            {
                if (collectableEntity.CollectionBounds.Intersects(collidableBounds))
                {
                    Boolean[,] collectableBooleans = collectableEntity.CollectionBooleans;
                    foreach (Point collectionPixel in collidableTransformedPixels)
                    {
                        Vector2 collectablePixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel(
                            new Vector2((float)collectionPixel.X, (float)collectionPixel.Y),
                            collectableEntity.CollectionTransformMatrix);
                        Point collectablePoint = new Point((int)collectablePixelVector.X, (int)collectablePixelVector.Y);
                        if (collectablePoint.X >= 0 && collectablePoint.Y >= 0 &&
                            collectablePoint.X < collectableBooleans.GetLength(0) &&
                            collectablePoint.Y < collectableBooleans.GetLength(1))
                        {
                            collectedEntityTypes.Add(collectableEntity.CollectionEntityType);
                            collectableEntity.Collected();
                            break;
                        }
                    }
                }
            }
            return(collectedEntityTypes);
        }
        public Boolean CheckForCollisionsWith(ICollidableEntity collidableEntity)
        {
            Rectangle collidableEntityCollisionBounds = collidableEntity.CollisionBounds;

            Point[] collidableEntityCollisionPixels          = collidableEntity.CollisionPixels;
            Matrix  collidableEntityCollisionTransformMatrix = collidableEntity.CollisionTransformMatrix;

            Point[] collisionPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(collidableEntityCollisionPixels, collidableEntityCollisionTransformMatrix);
            foreach (ICollidableEntity _collidableEntity in collidableEntities)
            {
                if (_collidableEntity.CollisionBounds.Intersects(collidableEntityCollisionBounds) && collidableEntity != _collidableEntity)
                {
                    Boolean[,] collisionBooleans = _collidableEntity.CollisionBooleans;
                    foreach (Point collisionPixel in collisionPixels)
                    {
                        Vector2 _collisionPixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel(new Vector2((float)collisionPixel.X, (float)collisionPixel.Y), _collidableEntity.CollisionTransformMatrix);
                        Point   _collisionPixel       = new Point((int)_collisionPixelVector.X, (int)_collisionPixelVector.Y);
                        if (_collisionPixel.X >= 0 && _collisionPixel.Y >= 0 && _collisionPixel.X < collisionBooleans.GetLength(0) && _collisionPixel.Y < collisionBooleans.GetLength(1))
                        {
                            if (collisionBooleans[_collisionPixel.X, _collisionPixel.Y])
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
Пример #3
0
 public void AttackWithProjectileVariableDamage(Rectangle attackerBounds, Matrix attackerTransformMatrix, Tuple <Point, float>[] attackerPointValueTuples, float damage)
 {
     IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerBounds,
                                                                                                                        this.AttackableEntities.ToArray());
     foreach (Tuple <Point, float> attackerPointValueTuple in attackerPointValueTuples)
     {
         Point attackerPointOnScreen = CollisionHelper.ConvertTexturePixelToScreenPixel(attackerPointValueTuple.Item1, attackerTransformMatrix);
         float attackerValue         = damage * attackerPointValueTuple.Item2;
         foreach (IAttackableEntity attackableEntity in attackableEntitiesWithinAttackersBounds)
         {
             Point attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackerPointOnScreen,
                                                                                                                          attackableEntity.AttackTransformMatrix);
             if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0)
             {
                 if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) &&
                     attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1))
                 {
                     if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X, attackersPixelInAttackableEntitysTextureCoordinates.Y])
                     {
                         attackableEntity.AttackWithDamage(DamageType.Projectile, attackerValue);
                     }
                 }
             }
         }
     }
 }
Пример #4
0
        public AttackResults AttackWithMelee(IAttackerEntity attackerEntity, float damage)
        {
            Rectangle attackerBounds = attackerEntity.AttackerBounds;

            Point[] attackerPixels          = attackerEntity.AttackerPixels;
            Matrix  attackerTransformMatrix = attackerEntity.AttackerTransformMatrix;

            Point[] attackerTransformedPixels = CollisionHelper.ConvertTexturePixelsToScreenPixels(attackerPixels, attackerTransformMatrix);
            foreach (IAttackableEntity attackableEntity in attackableEntities)
            {
                if (attackableEntity.AttackBounds.Intersects(attackerBounds))
                {
                    Boolean[,] attackableBooleans = attackableEntity.AttackBooleans;
                    foreach (Point attackerPixel in attackerTransformedPixels)
                    {
                        Vector2 attackablePixelVector = CollisionHelper.ConvertScreenPixelToTexturePixel(
                            new Vector2((float)attackerPixel.X, (float)attackerPixel.Y),
                            attackableEntity.AttackTransformMatrix);
                        Point attackablePoint = new Point((int)attackablePixelVector.X, (int)attackablePixelVector.Y);
                        if (attackablePoint.X >= 0 && attackablePoint.Y >= 0 &&
                            attackablePoint.X < attackableBooleans.GetLength(0) &&
                            attackablePoint.Y < attackableBooleans.GetLength(1))
                        {
                            if (attackableBooleans[attackablePoint.X, attackablePoint.Y])
                            {
                                if (attackableEntity.AttackWithDamage(DamageType.Melee, damage))
                                {
                                    return(AttackResults.Kill);
                                }
                                else
                                {
                                    return(AttackResults.Damage);
                                }
                            }
                        }
                    }
                }
            }

            return(AttackResults.None);
        }
Пример #5
0
        public MultiAttackResults AttackWithProjectile(IAttackerEntity attackerEntity, float damage)
        {
            IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray());
            float[]             damageValuesArray  = new float[attackableEntitiesWithinAttackersBounds.Length];
            MultiAttackResults  multiAttackResults = new MultiAttackResults();

            foreach (Point attackersPixel in attackerEntity.AttackerPixels)
            {
                Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix);
                for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++)
                {
                    IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index];
                    Point             attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates,
                                                                                                                                             attackableEntity.AttackTransformMatrix);
                    if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0)
                    {
                        if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) &&
                            attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1))
                        {
                            if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X, attackersPixelInAttackableEntitysTextureCoordinates.Y])
                            {
                                damageValuesArray[index] += damage;
                            }
                        }
                    }
                }
            }
            for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++)
            {
                if (damageValuesArray[index] > 0.0f)
                {
                    if (attackableEntitiesWithinAttackersBounds[index].AttackWithDamage(DamageType.Projectile, damageValuesArray[index]))
                    {
                        multiAttackResults.Kills++;
                    }
                    else
                    {
                        multiAttackResults.Damages++;
                    }
                }
            }
            return(multiAttackResults);
        }
Пример #6
0
 public AttackResults AttackWithProjectileSingleTarget(IAttackerEntity attackerEntity, float damage)
 {
     IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray());
     foreach (Point attackersPixel in attackerEntity.AttackerPixels)
     {
         Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix);
         for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++)
         {
             IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index];
             Point             attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates, attackableEntity.AttackTransformMatrix);
             if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0)
             {
                 if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) &&
                     attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1))
                 {
                     if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X, attackersPixelInAttackableEntitysTextureCoordinates.Y])
                     {
                         if (attackableEntity.AttackWithDamage(DamageType.Projectile, damage))
                         {
                             return(AttackResults.Kill);
                         }
                         else
                         {
                             return(AttackResults.Damage);
                         }
                     }
                 }
             }
         }
     }
     return(AttackResults.None);
 }