Пример #1
0
        private void Timer_Tick(object sender, EventArgs e) // na sekoja sekunda od timerot da se pravi update na ammo, pozicija i sl.
        {
            if (playerHealth > 1)
            {
                pbHealth.Value = playerHealth;
            }
            else
            {
                gameOver     = true;
                Player.Image = Properties.Resources.dead;
                GameOver gg = new GameOver(igrach, mainMenu);
                gg.Show();

                mainMenu.Hide();
                this.Close();
                Timer.Stop();
            }
            if (playerHealth < 40 && !pbHealth.IsDisposed)
            {
                pbHealth.SetState(2);
            }

            lblMadeKills.Text = igrach.Points.ToString();
            lblTotalAmmo.Text = ammo.ToString();

            if (goLeft == true && Player.Left > 0)
            {
                Player.Left -= speed;
            }
            if (goRight == true && Player.Left + Player.Width < this.ClientSize.Width - 15)
            {
                Player.Left += speed;
            }
            if (goUp == true && Player.Top > 45)
            {
                Player.Top -= speed;
            }
            if (goDown == true && Player.Top + Player.Height < this.ClientSize.Height - 15)
            {
                Player.Top += speed;
            }

            foreach (Control x in this.Controls) // sobiranje na ammo, dvizenje na zombies i presmetuvanje udari, i dodavanje health
            {
                foreach (Control j in Controls)
                {
                    if (j is PictureBox && (string)j.Tag == "health" && j.Bounds.IntersectsWith(Player.Bounds))
                    {
                        if (pbHealth.Value > 80)
                        {
                            pbHealth.Value = 100;
                            playerHealth   = 100;
                        }
                        else
                        {
                            playerHealth  += 20;
                            pbHealth.Value = playerHealth;
                            if (pbHealth.Value > 40)
                            {
                                pbHealth.SetState(1);
                            }
                            else
                            {
                                pbHealth.SetState(1);
                                pbHealth.SetState(2);
                            }

                            //label1.Text = playerHealth.ToString();
                        }
                        this.Controls.Remove(j);
                        j.Dispose();
                    }
                }
                if (x is PictureBox && (string)x.Tag == "ammo")
                {
                    if (Player.Bounds.IntersectsWith(x.Bounds))
                    {
                        this.Controls.Remove(x);
                        ((PictureBox)x).Dispose();
                        ammo += 5;
                    }
                }

                if (x is PictureBox && (string)x.Tag == "zombie")
                {
                    if (x.Left > Player.Left)
                    {
                        x.Left -= zombieSpeed;
                        ((PictureBox)x).Image = Properties.Resources.zleft;
                    }

                    if (x.Left < Player.Left)
                    {
                        x.Left += zombieSpeed;
                        ((PictureBox)x).Image = Properties.Resources.zright;
                    }

                    if (x.Top < Player.Top)
                    {
                        x.Top += zombieSpeed;
                        ((PictureBox)x).Image = Properties.Resources.zdown;
                    }

                    if (x.Top > Player.Top)
                    {
                        x.Top -= zombieSpeed;
                        ((PictureBox)x).Image = Properties.Resources.zup;
                    }

                    if (Player.Bounds.IntersectsWith(x.Bounds))
                    {
                        playerHealth -= 2;
                    }
                }

                foreach (Control j in this.Controls)
                {
                    if (j is PictureBox && (string)j.Tag == "bullet" && x is PictureBox && (string)x.Tag == "zombie")
                    {
                        if (j.Bounds.IntersectsWith(x.Bounds))
                        {
                            igrach.IncreasePoints();
                            if (igrach.Points % 10 == 0 && igrach.Points != 0)
                            {
                                dropHealth();
                            }
                            this.Controls.Remove(x);
                            x.Dispose();
                            this.Controls.Remove(j);
                            j.Dispose();
                            MakeZombies();
                        }
                    }
                }
            }
        }