//bullets hit shield elements private bool BulletShieldElementHitTest(Bullet thisBullet, shieldElement thisShieldElement) { Rect recBullet = new Rect(Canvas.GetLeft(thisBullet), Canvas.GetTop(thisBullet), thisBullet.ActualWidth, thisBullet.ActualHeight); Rect recShieldElement = new Rect(Canvas.GetLeft(thisShieldElement), Canvas.GetTop(thisShieldElement), 10, 20); return recBullet.IntersectsWith(recShieldElement); }
//when a shield element gets hit it loses 1 of its 3 lives and gets redrawn private void reDrawShield(shieldElement thisShieldElement) { switch (thisShieldElement.intLives) { case (3): thisShieldElement.imgShield.Source = bitshielda; break; case (2): thisShieldElement.imgShield.Source = bitshieldb; break; case (1): thisShieldElement.imgShield.Source = bitshieldc; break; } }
//Bombs Hit shield elements private bool BombShieldElementHitTest(Bomb thisBomb, shieldElement thisShieldElement) { Rect recBomb = new Rect(Canvas.GetLeft(thisBomb), Canvas.GetTop(thisBomb), thisBomb.ActualWidth, thisBomb.ActualHeight); Rect recShieldElement = new Rect(Canvas.GetLeft(thisShieldElement), Canvas.GetTop(thisShieldElement), 10, 20); return recBomb.IntersectsWith(recShieldElement); }
//The draw shields method private void drawShields() { //there are 4 shield 0 to 3 for (int intShieldNo = 0; intShieldNo < 4; intShieldNo++) { //each shield has 4 rows 0 to 3 for (int row = 0; row < 4; row++) { //each row has 11 shield elements which are user controls for (int x = 0; x < 11; x++) { //provided the element is not in the cut out area at the bottom centre of the shield, //create the shield element if (!((row>1)&&(x>2)&&(x<8))) { shieldElement thisShieldElement = new shieldElement(); Shields.Add(thisShieldElement); cnvSpace.Children.Add(thisShieldElement); //135 offset, shields at 125px interval, each element 7px width. Canvas.SetLeft(thisShieldElement, 135+intShieldNo*125+x*7); //475 offset from top of screen 10 height Canvas.SetTop(thisShieldElement, 475+row*10); } } } } }