コード例 #1
0
 /// <summary>
 ///     Creates a new instance of Enemy with a texture, CollidableObject and type
 /// </summary>
 /// <param name="aliveTexture2D">Texture for enemy when alive</param>
 /// <param name="deadTexture2D">Texture for enemy when dead</param>
 /// <param name="spawnPosition">The spawn position of the object</param>
 public Enemy(Texture2D texture, Vector2 spawnPosition)
 {
     InWorldPosition = spawnPosition;
     // Create a new CollidableObject with alive texture and spawn
     CollidableObject = new CollidableObject(texture, spawnPosition);
     //EnemyManager.AddEnemy(out this);
 }
コード例 #2
0
        public static bool CheckCollisionToAnyEnemy(CollidableObject collidableObject)
        {
            foreach (EnemyManager enemy in Enemies)
            {
                if (enemy.CollidableObject.IsColliding(collidableObject))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
 /// <summary>
 ///     Detects a pixel level collision between two CollidableObjects.
 /// </summary>
 /// <param name="collidable">The CollidableObject to check a collision against</param>
 /// <returns>True if colliding, false if not.</returns>
 public bool IsColliding(CollidableObject collidable)
 {
     // If rectangle of objects intersects
     if (BoundingRectangle.Intersects(collidable.BoundingRectangle))
     {
         // And any of the pixels of objects intersect
         if (IntersectPixels(Transform, Texture.Width, Texture.Height, TextureData, collidable.Transform, collidable.Texture.Width, collidable.Texture.Height, collidable.TextureData))
         {
             // Then return true
             return(true);
         }
     }
     // Else return false
     return(false);
 }
コード例 #4
0
 /// <summary>
 /// Constructs a new Player with a texture, position
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="position"></param>
 public Player(Texture2D texture, Vector2 position)
 {
     inWorldPosition = position;
     // Create a new CollidableObject
     collidableObject = new CollidableObject(texture, position);
 }