/************************************************************************************ * missile_timer_Tick: timer for animating missile movements and bomber movements ************************************************************************************/ private void missile_timer_Tick(object sender, EventArgs e) { Graphics g = Graphics.FromImage(myCanvas); if (newgame)//game has ended { wait_counter++; if (wait_counter < missile_timer.Interval*2) {//dislpay text Draw_Funct(); Draw_level_text(g,sender,e); } else {//renew variables time_to_next_level = 0; newBase.reset_missiles();//restock missiles //beginning of new level so set all checks below to false newgame = false; end_of_level = false; wait_for_level_over = false; wait_counter = 0; } } int explode_count = explosion_list.Count; List<PointF> enemy_location = new List<PointF>(); List<PointF> enemy_bomb_targets = new List<PointF>(); int rand_location = 0; int rand_missile_bomber = 0; //enemy bomber for (int i = 0; i < bomber_list.Count; i++) { if (bomber_list[i].get_location(1).X > DrawingPanel.Width+40)//bomber has left screen { bomber_list.RemoveAt(i); } else//bomber still in screen { int rand_bomb_location = rand1.Next(0, 6); rand_missile_bomber = rand1.Next(0, 200); //move & draw bomb bomber_list[i].move(2); bomber_list[i].Draw(g); enemy_bomb_targets = generate_enemy_list(); if (rand_missile_bomber == 0)//low chance that bomber will fire(0/200) { enemy_missile_list.Add(new Line10C(Color.Red, 2, bomber_list[i].get_location(1), enemy_bomb_targets[rand_bomb_location])); } for (int a = 0; a < explosion_list.Count; a++)//check if bomber in explosion { if (explosion_list[a].IsPointFInside(bomber_list[i].get_location(0)) || explosion_list[a].IsPointFInside(bomber_list[i].get_location(1)) || explosion_list[a].IsPointFInside(bomber_list[i].get_location(2))) {//add explosion and remove bomber explosion_list.Add(new Ellipse10C(Color.Red, bomber_list[i].get_location(1), 0, 0, 60)); bomber_list.RemoveAt(i); break; } } } } //enemy missiles for (int i = 0; i < enemy_missile_list.Count; i++) { //missile not at final pos & did not encounter an explosion if (!enemy_missile_list[i].atfinalpos() && !enemy_missile_list[i].get_removal()) { //draw & move missiles enemy_missile_list[i].Move_pslope(1); enemy_missile_list[i].Draw(g); //draw missile tip g.FillEllipse(new SolidBrush(Color.White), enemy_missile_list[i].get_currentPoint().X - 1, enemy_missile_list[i].get_currentPoint().Y - 1, 2, 2); //cluster bomb... so remove original missile and add 3 missiles in place if (enemy_missile_list[i].is_cluster() && enemy_missile_list[i].get_currentPoint().Y < DrawingPanel.Height / 2 + 100 && enemy_missile_list[i].get_currentPoint().Y > 200) { enemy_location = generate_enemy_list();//generate enemy list //get random targets for (int m = 0; m < 3; m++) { rand_location = rand1.Next(0, 9); enemy_missile_list.Add(new Line10C(Color.Red, 2, enemy_missile_list[i].get_currentPoint(), enemy_location[rand_location])); } enemy_missile_list.RemoveAt(i); } } //enemy missile encountered explosion else if (enemy_missile_list[i].get_removal()) { enemy_missile_list.RemoveAt(i); } else//enemy at final position city/base { bool hit_city = false;//speed up runtime by not running both city and base loops for (int a = 0; a < six_cities.get_cities().Length; a++) { //did it hit a city if (enemy_missile_list[i].get_final_point().X == six_cities.get_cities()[a].X + 20 && enemy_missile_list[i].get_final_point().Y == six_cities.get_cities()[a].Y + 10) { //disable city six_cities.city_disable[a] = true; hit_city = true; } } if (hit_city != true)//if it didnt hit city, then it hit base { for (int b = 0; b < 3; b++) { if (enemy_missile_list[i].get_final_point() == newBase.get_base_point(b)) { newBase.base_disable[b] = true;//base is disabled } } } //generate explosion current_explosion = new Ellipse10C(Color.Red, enemy_missile_list[i].get_final_point(), 0, 0, 60); explosion_list.Add(current_explosion); enemy_missile_list.RemoveAt(i); explode_player.Play(); } } //your missiles for (int i = 0; i < missile_list.Count; i++) { if (!missile_list[i].atfinalpos())//missile not at final pos { //missile from middle base moves faster if (missile_list[i].get_fire_point() == newBase.get_base_point(1)) { missile_list[i].Move_pslope(15); } //else if (missile_list[i].is_enemy()) missile_list[i].Move_pslope(1); else missile_list[i].Move_pslope(8); //draw missile and missile tip missile_list[i].Draw(g); g.FillEllipse(new SolidBrush(Color.White), missile_list[i].get_currentPoint().X - 1, missile_list[i].get_currentPoint().Y - 1, 2, 2); } else//missile at final pos then make explosion { current_explosion = new Ellipse10C(Color.Red, missile_list[i].get_final_point(), 0, 0, 60); explosion_list.Add(current_explosion); missile_list.RemoveAt(i); explosion_timer.Start(); explode_player.Play(); } } extra_explosion();//draw the chain explosions for when missiles encounter explosions DrawingPanel.Invalidate(); //if no more missiles and it's the end of the level so initiate check to transfer to next level if (enemy_missile_list.Count == 0 && bomber_list.Count == 0 && end_of_level==true) { wait_for_level_over = true; } }
/************************************************************************************ * missile_timer_Tick: timer for animating missile movements and bomber movements ************************************************************************************/ private void missile_timer_Tick(object sender, EventArgs e) { Graphics g = Graphics.FromImage(myCanvas); if (newgame)//game has ended { wait_counter++; if (wait_counter < missile_timer.Interval * 2) {//dislpay text Draw_Funct(); Draw_level_text(g, sender, e); } else { //renew variables time_to_next_level = 0; newBase.reset_missiles(); //restock missiles //beginning of new level so set all checks below to false newgame = false; end_of_level = false; wait_for_level_over = false; wait_counter = 0; } } int explode_count = explosion_list.Count; List <PointF> enemy_location = new List <PointF>(); List <PointF> enemy_bomb_targets = new List <PointF>(); int rand_location = 0; int rand_missile_bomber = 0; //enemy bomber for (int i = 0; i < bomber_list.Count; i++) { if (bomber_list[i].get_location(1).X > DrawingPanel.Width + 40)//bomber has left screen { bomber_list.RemoveAt(i); } else//bomber still in screen { int rand_bomb_location = rand1.Next(0, 6); rand_missile_bomber = rand1.Next(0, 200); //move & draw bomb bomber_list[i].move(2); bomber_list[i].Draw(g); enemy_bomb_targets = generate_enemy_list(); if (rand_missile_bomber == 0)//low chance that bomber will fire(0/200) { enemy_missile_list.Add(new Line10C(Color.Red, 2, bomber_list[i].get_location(1), enemy_bomb_targets[rand_bomb_location])); } for (int a = 0; a < explosion_list.Count; a++)//check if bomber in explosion { if (explosion_list[a].IsPointFInside(bomber_list[i].get_location(0)) || explosion_list[a].IsPointFInside(bomber_list[i].get_location(1)) || explosion_list[a].IsPointFInside(bomber_list[i].get_location(2))) {//add explosion and remove bomber explosion_list.Add(new Ellipse10C(Color.Red, bomber_list[i].get_location(1), 0, 0, 60)); bomber_list.RemoveAt(i); break; } } } } //enemy missiles for (int i = 0; i < enemy_missile_list.Count; i++) { //missile not at final pos & did not encounter an explosion if (!enemy_missile_list[i].atfinalpos() && !enemy_missile_list[i].get_removal()) { //draw & move missiles enemy_missile_list[i].Move_pslope(1); enemy_missile_list[i].Draw(g); //draw missile tip g.FillEllipse(new SolidBrush(Color.White), enemy_missile_list[i].get_currentPoint().X - 1, enemy_missile_list[i].get_currentPoint().Y - 1, 2, 2); //cluster bomb... so remove original missile and add 3 missiles in place if (enemy_missile_list[i].is_cluster() && enemy_missile_list[i].get_currentPoint().Y < DrawingPanel.Height / 2 + 100 && enemy_missile_list[i].get_currentPoint().Y > 200) { enemy_location = generate_enemy_list();//generate enemy list //get random targets for (int m = 0; m < 3; m++) { rand_location = rand1.Next(0, 9); enemy_missile_list.Add(new Line10C(Color.Red, 2, enemy_missile_list[i].get_currentPoint(), enemy_location[rand_location])); } enemy_missile_list.RemoveAt(i); } } //enemy missile encountered explosion else if (enemy_missile_list[i].get_removal()) { enemy_missile_list.RemoveAt(i); } else//enemy at final position city/base { bool hit_city = false;//speed up runtime by not running both city and base loops for (int a = 0; a < six_cities.get_cities().Length; a++) { //did it hit a city if (enemy_missile_list[i].get_final_point().X == six_cities.get_cities()[a].X + 20 && enemy_missile_list[i].get_final_point().Y == six_cities.get_cities()[a].Y + 10) { //disable city six_cities.city_disable[a] = true; hit_city = true; } } if (hit_city != true)//if it didnt hit city, then it hit base { for (int b = 0; b < 3; b++) { if (enemy_missile_list[i].get_final_point() == newBase.get_base_point(b)) { newBase.base_disable[b] = true;//base is disabled } } } //generate explosion current_explosion = new Ellipse10C(Color.Red, enemy_missile_list[i].get_final_point(), 0, 0, 60); explosion_list.Add(current_explosion); enemy_missile_list.RemoveAt(i); explode_player.Play(); } } //your missiles for (int i = 0; i < missile_list.Count; i++) { if (!missile_list[i].atfinalpos())//missile not at final pos { //missile from middle base moves faster if (missile_list[i].get_fire_point() == newBase.get_base_point(1)) { missile_list[i].Move_pslope(15); } //else if (missile_list[i].is_enemy()) missile_list[i].Move_pslope(1); else { missile_list[i].Move_pslope(8); } //draw missile and missile tip missile_list[i].Draw(g); g.FillEllipse(new SolidBrush(Color.White), missile_list[i].get_currentPoint().X - 1, missile_list[i].get_currentPoint().Y - 1, 2, 2); } else//missile at final pos then make explosion { current_explosion = new Ellipse10C(Color.Red, missile_list[i].get_final_point(), 0, 0, 60); explosion_list.Add(current_explosion); missile_list.RemoveAt(i); explosion_timer.Start(); explode_player.Play(); } } extra_explosion();//draw the chain explosions for when missiles encounter explosions DrawingPanel.Invalidate(); //if no more missiles and it's the end of the level so initiate check to transfer to next level if (enemy_missile_list.Count == 0 && bomber_list.Count == 0 && end_of_level == true) { wait_for_level_over = true; } }