Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            screenWidth  = GraphicsDevice.Viewport.Width;
            screenHeight = GraphicsDevice.Viewport.Height;
            player       = new Player();
            gameObjects.Add(player);
            base.Initialize();
        }
Ejemplo n.º 2
0
        public void CheckForCollisions(MyGameObject o)
        {
            foreach (MyGameObject other in gameObjects)
            {
                if (o is Bullet && CheckForBulletCollisions(o, other))
                    break;
                else if( o is Enemy && CheckForEnemyCollisions(o, other))
                    break;

            }
        }
Ejemplo n.º 3
0
 public void CheckForCollisions(MyGameObject o)
 {
     foreach (MyGameObject other in gameObjects)
     {
         if (o is Bullet && CheckForBulletCollisions(o, other))
         {
             break;
         }
         else if (o is Enemy && CheckForEnemyCollisions(o, other))
         {
             break;
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Check if the bullet is out of the screen or if it hit an enemy
 /// </summary>
 /// <param name="bullet"></param>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool CheckForBulletCollisions(MyGameObject bullet, MyGameObject other)
 {
     // remove bullet if it is out of screen
     if (bullet.Position.Y + bullet.Texture.Height <= 0)
     {
         bullet.IsNonExisting = true;
         return true;
     }
         // remove bullet if it hits an enemy
     if (other is Enemy && bullet.BoundingBox.Intersects(other.BoundingBox))
         {
             bullet.IsNonExisting = true;
             ((Enemy)other).Decend();
             return true;
         }
     return false;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Check if the player can eat an enemy
 /// </summary>
 /// <param name="player"></param>
 /// <param name="enemy"></param>
 /// <returns></returns>
 public bool CheckForEnemyCollisions(MyGameObject enemy, MyGameObject player)
 {
     // check if enemy is out of the screen
     if (enemy.Position.X + enemy.Texture.Width * 3 < 0 || enemy.Position.X >= screenWidth * 2)
     {
         enemy.IsNonExisting = true;
         return(true);
     }
     // check if enemy hits the player
     if (player is Player && player.BoundingBox.Intersects(enemy.BoundingBox))
     {
         increaseScore(((Enemy)enemy).Type);
         enemy.IsNonExisting = true;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Check if the bullet is out of the screen or if it hit an enemy
 /// </summary>
 /// <param name="bullet"></param>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool CheckForBulletCollisions(MyGameObject bullet, MyGameObject other)
 {
     // remove bullet if it is out of screen
     if (bullet.Position.Y + bullet.Texture.Height <= 0)
     {
         bullet.IsNonExisting = true;
         return(true);
     }
     // remove bullet if it hits an enemy
     if (other is Enemy && bullet.BoundingBox.Intersects(other.BoundingBox))
     {
         bullet.IsNonExisting = true;
         ((Enemy)other).Decend();
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Check if the player can eat an enemy
 /// </summary>
 /// <param name="player"></param>
 /// <param name="enemy"></param>
 /// <returns></returns>
 public bool CheckForEnemyCollisions(MyGameObject enemy, MyGameObject player)
 {
     // check if enemy is out of the screen
     if (enemy.Position.X + enemy.Texture.Width*3 < 0  || enemy.Position.X >=screenWidth*2)
     {
         enemy.IsNonExisting = true;
         return true;
     }
     // check if enemy hits the player
     if (player is Player && player.BoundingBox.Intersects(enemy.BoundingBox))
     {
         increaseScore(((Enemy)enemy).Type);
         enemy.IsNonExisting = true;
         return true;
     }
     return false;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            screenWidth = GraphicsDevice.Viewport.Width;
            screenHeight = GraphicsDevice.Viewport.Height;
            player = new Player();
            gameObjects.Add(player);
            base.Initialize();
        }