private void WrogStrzelaLosowo() { int losPotwow = randomaLiczba.Next(gra.ListaWrogow.Count - 6, gra.ListaWrogow.Count); if (gra.ListaWrogow[losPotwow] != null && gra.ListaWrogow[losPotwow].ZablokowaneStrzelaniaPrzezPotwora == false) //mozna strzelac { gra.ListaWrogow[losPotwow].ZablokowaneStrzelaniaPrzezPotwora = true; ShotControl shot = new ShotControl() { Location = new Point(gra.ListaWrogow[losPotwow].Lokalizacja.X, gra.ListaWrogow[losPotwow].Lokalizacja.Y), ID = losPotwow }; this.Controls.Add(shot); this.listaStrzalowWroga.Add(shot); } }
private void zegarGry0_Tick(object sender, EventArgs e) { zegarGry0.Stop(); if (Analizator.Zycia == 0) { return; } gra.RuchWroga1(); foreach (var item in listaStrzalow) { item.Location = new Point(item.Location.X, item.Location.Y - 5); } //wykryj kolizje! CzyMojPociskTrafil(); CzyTrafilMniePocisk(); if (listaStrzalowWroga.Count < 2) { WrogStrzelaLosowo(); } ShotControl doUsuniecia = null; foreach (var item in listaStrzalowWroga) { item.Location = new Point(item.Location.X, item.Location.Y + 5); if (item.Location.Y > pbPlayer.Location.Y) { doUsuniecia = item; } } if (doUsuniecia != null) { if (doUsuniecia.ID > gra.ListaWrogow.Count) { doUsuniecia.ID--; } gra.ListaWrogow[doUsuniecia.ID - 1].ZablokowaneStrzelaniaPrzezPotwora = false; listaStrzalowWroga.Remove(doUsuniecia); this.Controls.Remove(doUsuniecia); } zegarGry0.Start(); }
private void Form1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.A) { pbPlayer.Location = new Point(pbPlayer.Location.X - 10, pbPlayer.Location.Y); } else if (e.KeyChar == (char)Keys.D) { pbPlayer.Location = new Point(pbPlayer.Location.X + 10, pbPlayer.Location.Y); } else if (e.KeyChar == (char)Keys.S) { ShotControl shot = new ShotControl(); shot.UstawLokalizacje(new Point(pbPlayer.Location.X + pbPlayer.Width / 2, pbPlayer.Location.Y - shot.Height)); listaStrzalow.Add(shot); this.Controls.Add(shot); } else if (e.KeyChar == (char)Keys.Q) { Thread.Sleep(1000); Application.Restart(); } }