All pastes #460915 Raw Edit

Miscellany

public text v1 · immutable
#460915 ·published 2007-04-27 11:24 UTC
rendered paste body
        public bool IsCollided(Rectangle aBox)
        {
            if ((aBox.X > this.boundingBox.X - this.boundingBox.Width) && (aBox.X < this.boundingBox.X + this.boundingBox.Width)  // Figure out if aBox is between the left and right of the box
                && (aBox.Y > this.boundingBox.Y - this.boundingBox.Height) && (aBox.Y < this.boundingBox.Y + this.boundingBox.Height)) // Figure out if aBox is between the top and bottom of the box
                return true;
            else
                return false;
        }


            // Check to see if a bullet has collided with enemy
            for (int i = 0; i < this.bullet.Length; i++)
            {
                for (int j = 0; j < this.enemy.Length; j++)
                {
                    if (this.enemy[j] != null)
                    {
                        if (this.enemy[j].collisionBox.IsCollided(this.bullet[i].collisionBox.Position))
                        //if (this.bullet[i].collisionBox.IsCollided(this.enemy[j].collisionBox.Position))
                        {
                            //this.enemy[j].EnemySprite.IsMoving = false;
                            //this.enemy[j].EnemySprite.IsVisible = false;
                            Debug.WriteLine("Hit: " + j + "!!!!");
                            Debug.WriteLine("Enemy: " + ( this.enemy[j].collisionBox.Position.Y + this.enemy[j].collisionBox.Position.Height));
                            Debug.WriteLine("Bullet: " + this.bullet[i].collisionBox.Position.Y);
                            this.Exit();
                        }
                    }
                }
            }