void TestBulletCollision() { int rowNum = 0; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; rowNum = i; int collisionIndex = TheInvaders.CollisionTest(TheBullet.GetBounds()); if ((collisionIndex >= 0) && ActiveBullet) { TheInvaders.Invaders[collisionIndex].BeenHit = true; TheScore.AddScore(CalcScoreFromRow(rowNum)); PlaySoundInThread("0.wav", 1); ActiveBullet = false; TheBullet.Reset(); } if (SaucerStart && ActiveBullet && CurrentSaucer.GetBounds().IntersectsWith(TheBullet.GetBounds())) { CurrentSaucer.BeenHit = true; if (CurrentSaucer.ScoreCalculated == false) { TheScore.AddScore(CurrentSaucer.CalculateScore()); CurrentSaucer.ScoreCalculated = true; PlaySoundInThread("3.wav", 1); } } } }
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; for (int i = 0; i < kNumberOfShields; i++) { Shields[i].Draw(g); } // g.FillRectangle(Brushes.Black, 0, 0, ClientRectangle.Width, ClientRectangle.Height); TheMan.Draw(g); TheScore.Draw(g); TheHighScore.Draw(g); displayLives.Draw(g); if (ActiveBullet) { TheBullet.Draw(g); } if (SaucerStart) { CurrentSaucer.Draw(g); } for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.Draw(g); } }
private void SetAllDirections(bool bDirection) { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.DirectionRight = bDirection; } }
void ResetAllBombCounters() { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.ResetBombCounters(); } }
private void MoveInvadersInPlace() { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.MoveInPlace(); } }
void InitializeInvaderRows(int level) { InvaderRows[0] = new InvaderRow(speeds[3], speeds[2], "invader1.gif", "invader1c.gif", 2 + level); InvaderRows[1] = new InvaderRow(speeds[3], speeds[2], "invader2.gif", "invader2c.gif", 3 + level); InvaderRows[2] = new InvaderRow(speeds[3], speeds[2], "invader2.gif", "invader2c.gif", 4 + level); InvaderRows[3] = new InvaderRow(speeds[3], speeds[2], "invader3.gif", "invader3c.gif", 5 + level); InvaderRows[4] = new InvaderRow(speeds[3], speeds[2], "invader3.gif", "invader3c.gif", 6 + level); }
void TestBombCollision() { if (TheMan.Died) { NumberOfMen--; if (NumberOfMen == 0) { TheHighScore.Write(TheScore.Count); TheScore.GameOver = true; GameGoing = false; } else { TheMan.Reset(); ResetAllBombCounters(); } } if (TheMan.BeenHit == true) { return; } for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; for (int j = 0; j < TheInvaders.Invaders.Length; j++) { for (int k = 0; k < kNumberOfShields; k++) { bool bulletHole = false; if (Shields[k].TestCollision(TheInvaders.Invaders[j].GetBombBounds(), true, out bulletHole)) { TheInvaders.Invaders[j].ResetBombPosition(); Invalidate(Shields[k].GetBounds()); } if (Shields[k].TestCollision(TheBullet.GetBounds(), false, out bulletHole)) { ActiveBullet = false; Invalidate(Shields[k].GetBounds()); TheBullet.Reset(); } } if (TheInvaders.Invaders[j].IsBombColliding(TheMan.GetBounds())) { TheMan.BeenHit = true; PlaySoundInThread("2.wav", 1); } } } }
private int TotalNumberOfInvaders() { int sum = 0; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; sum += TheInvaders.NumberOfLiveInvaders(); } return(sum); }
void TestForLanding() { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; if (TheInvaders.AlienHasLanded(ClientRectangle.Bottom)) { TheMan.BeenHit = true; PlaySoundInThread("2.wav", 1); TheScore.GameOver = true; TheHighScore.Write(TheScore.Count); GameGoing = false; } } }
private int CalculateLargestLastPosition() { int max = 0; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; int nLastPos = TheInvaders.GetLastInvader().Position.X; if (nLastPos > max) { max = nLastPos; } } return(max); }
private void MoveInvaders() { bool bMoveDown = false; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.Move(); } // if (InvaderSoundCounter % 5) PlaySoundInThread("4.wav", 3); if ((CalculateLargestLastPosition()) > ClientRectangle.Width - InvaderRows[4][0].GetWidth()) { TheInvaders.DirectionRight = false; SetAllDirections(false); } if ((CalculateSmallestFirstPosition()) < InvaderRows[4][0].Width / 3) { TheInvaders.DirectionRight = true; SetAllDirections(true); for (int i = 0; i < kNumberOfRows; i++) { bMoveDown = true; } } if (bMoveDown) { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.MoveDown(); } } }
private int CalculateSmallestFirstPosition() { int min = 50000; try { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; int nFirstPos = TheInvaders.GetFirstInvader().Position.X; if (nFirstPos < min) { min = nFirstPos; } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } return(min); }
void TestBombCollision() { if (TheMan.Died) { NumberOfMen --; _livesIndicator.DecrementLives(); // also show on lives indicator Invalidate(); if (NumberOfMen == 0) { TheHighScore.Write(TheScore.Count); TheScore.GameOver = true; GameGoing = false; } else { TheMan.Reset(); ResetAllBombCounters(); } } if (TheMan.BeenHit == true) return; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; for (int j = 0; j < TheInvaders.Invaders.Length; j++) { for (int k = 0; k < kNumberOfShields; k++) { bool bulletHole = false; if (Shields[k].TestCollision(TheInvaders.Invaders[j].GetBombBounds(), true, out bulletHole)) { TheInvaders.Invaders[j].ResetBombPosition(); Invalidate(Shields[k].GetBounds()); } if (Shields[k].TestCollision(TheBullet.GetBounds(), false, out bulletHole)) { ActiveBullet = false; Invalidate(Shields[k].GetBounds()); TheBullet.Reset(); } } if (TheInvaders.Invaders[j].IsBombColliding(TheMan.GetBounds()) ) { TheMan.BeenHit = true; PlaySoundInThread("2.wav", 1); } } } }
private void MoveInvaders() { bool bMoveDown = false; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.Move(); } // if (InvaderSoundCounter % 5) PlaySoundInThread("4.wav", 3); if ((CalculateLargestLastPosition()) > ClientRectangle.Width - InvaderRows[4][0].GetWidth()) { TheInvaders.DirectionRight = false; SetAllDirections(false); } if ((CalculateSmallestFirstPosition()) < InvaderRows[4][0].Width/3) { TheInvaders.DirectionRight = true; SetAllDirections(true); for (int i = 0; i < kNumberOfRows; i++) { bMoveDown = true; } } if (bMoveDown) { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.MoveDown(); } } }
void InitializeInvaderRows(int level) { InvaderRows[0] = new InvaderRow("invader1.gif", "invader1c.gif", 2 + level); InvaderRows[1] = new InvaderRow("invader2.gif", "invader2c.gif", 3 + level); InvaderRows[2] = new InvaderRow("invader2.gif", "invader2c.gif", 4 + level); InvaderRows[3] = new InvaderRow("invader3.gif", "invader3c.gif", 5 + level); InvaderRows[4] = new InvaderRow("invader3.gif", "invader3c.gif", 6 + level); }
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; for (int i = 0; i < kNumberOfShields; i++) { Shields[i].Draw(g); } // g.FillRectangle(Brushes.Black, 0, 0, ClientRectangle.Width, ClientRectangle.Height); TheMan.Draw(g); TheScore.Draw(g); TheHighScore.Draw(g); _livesIndicator.Draw(g); if (ActiveBullet) { TheBullet.Draw(g); } if (SaucerStart) { CurrentSaucer.Draw(g); } for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; TheInvaders.Draw(g); } }
private int CalculateSmallestFirstPosition() { int min = 50000; try { for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; int nFirstPos = TheInvaders.GetFirstInvader().Position.X; if (nFirstPos < min) min = nFirstPos; } } catch(Exception ex) { MessageBox.Show(ex.Message.ToString()); } return min; }
private int TotalNumberOfInvaders() { int sum = 0; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; sum += TheInvaders.NumberOfLiveInvaders(); } return sum; }
private void StartGame() { player = new Player(); UIObjects.PlayerList.Add(Player); invRow = new InvaderRow(Playground); }
private int CalculateLargestLastPosition() { int max = 0; for (int i = 0; i < kNumberOfRows; i++) { TheInvaders = InvaderRows[i]; int nLastPos = TheInvaders.GetLastInvader().Position.X; if (nLastPos > max) max = nLastPos; } return max; }