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);
        }
        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);
        }
Esempio n. 3
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);
        }