Beispiel #1
0
        private bool ProveraLokacije(Igrac igrac)
        {
            bool res = false;;

            res = Canvas.GetLeft(ell) + ell.Width >= Canvas.GetLeft(igrac.Rect) && /*(Canvas.GetLeft(ell) >= Canvas.GetLeft(igrac.Rect) &&*/ Canvas.GetLeft(ell) <= Canvas.GetLeft(igrac.Rect) + igrac.Rect.Width && Canvas.GetTop(igrac.Rect) > Canvas.GetTop(ell) && Canvas.GetTop(igrac.Rect) < Canvas.GetTop(ell) + ell.Height;
            return(res);
        }
Beispiel #2
0
 public void Pomeraj(double width, double height, Igrac igrac, ref bool res)
 {
     //MessageBox.Show($"{Canvas.GetLeft(ell)}");
     if (Canvas.GetLeft(ell) >= width - ell.Width || Canvas.GetLeft(ell) <= 0)
     {
         ugao = -ugao;
     }
     if (Canvas.GetTop(ell) <= 0)
     {
         ugao = 180 - ugao;
     }
     if (ProveraLokacije(igrac))
     {
         ChangeUgao(igrac.Rect);
         //ugao = 180 - ugao;
     }
     res = Reset(igrac, height);
     if (!res)
     {
         double radians = (Math.PI / 180) * ugao;
         Vector vector  = new Vector {
             X = Math.Sin(radians), Y = -Math.Cos(radians)
         };
         Canvas.SetLeft(ell, Canvas.GetLeft(Ell) + vector.X * brzina);
         Canvas.SetTop(ell, Canvas.GetTop(Ell) + vector.Y * brzina);
     }
 }
Beispiel #3
0
 /*public Blokovi(int w, int h, double sirina, double height)
  * {
  *  bricks = new Cigla[w, h];
  *  for (int i = 0; i < w; i++)
  *  {
  *      for (int j = 0; j < h; j++)
  *      {
  *          Random r = new Random();
  *          int tmp = r.Next(1, 3);
  *          Rectangle rect = new Rectangle();
  *          rect.Width = sirina - (w - 1) * razmak;
  *          rect.Width /= w;
  *          rect.Height = height / 2 - (h - 1) * razmak;
  *          rect.Height /= h;
  *          Canvas.SetLeft(rect,j * rect.Width + razmak * j);
  *          Canvas.SetTop(rect, i * rect.Height + razmak * i);
  *          bricks[i, j] = new Cigla(rect, tmp);
  *      }
  *  }
  * }*/
 public Blokovi(Canvas c, Label lbLvl, Igrac ig)
 {
     cnv = c;
     MakeMatrix();
     lb     = lbLvl;
     level  = 1;
     player = ig;
 }
Beispiel #4
0
        private bool Reset(Igrac rectIgrac, double height)
        {
            if (Canvas.GetTop(ell) + ell.Height >= height)
            {
                //timer.Stop();
                Canvas.SetTop(ell, Canvas.GetTop(rectIgrac.Rect) - ell.ActualHeight - 1);
                Canvas.SetLeft(ell, Canvas.GetLeft(rectIgrac.Rect) + rectIgrac.Rect.Width / 2 - ell.Width / 2);
                rectIgrac.IsLaunched = false;

                return(true);
            }
            return(false);
        }
Beispiel #5
0
 public void BaseSet(Igrac rectIgrac)
 {
     Canvas.SetTop(ell, Canvas.GetTop(rectIgrac.Rect) - ell.ActualHeight - 1);
     Canvas.SetLeft(ell, Canvas.GetLeft(rectIgrac.Rect) + rectIgrac.Rect.Width / 2 - ell.Width / 2);
     rectIgrac.IsLaunched = false;
 }
Beispiel #6
0
        public bool Pogodjen(Loptica ball, Igrac igrac, ref int score, Label lb, ref bool rad)
        {
            for (int i = 0; i < bricks.GetLength(0); i++)
            {
                for (int j = 0; j < bricks.GetLength(1); j++)
                {
                    if (bricks[i, j] == null)
                    {
                        continue;
                    }
                    Rectangle blok    = bricks[i, j].Blok;
                    Ellipse   lopta   = ball.Ell;
                    double    circleR = lopta.Width / 2;

                    double levo_blok = Canvas.GetLeft(bricks[i, j].Blok);
                    double gore_blok = Canvas.GetTop(bricks[i, j].Blok);

                    double levo_lopta = Canvas.GetLeft(ball.Ell);
                    double gore_lopta = Canvas.GetTop(ball.Ell);

                    double halfX = blok.Width / 2;
                    double halfY = blok.Height / 2;

                    double lopta_centarX = levo_lopta + lopta.Width / 2;
                    double lopta_centarY = gore_lopta + lopta.Height / 2;

                    double centerX = lopta_centarX - (levo_blok + halfX);
                    double centerY = lopta_centarY - (gore_blok + halfY);

                    double sideX = Math.Abs(centerX) - halfX;
                    double sideY = Math.Abs(centerY) - halfY;

                    if (sideX < 0 || sideY < 0)
                    {
                        if (Math.Abs(sideX) < circleR && sideY < 0)
                        {
                            ball.Odbij_Desno_Levo();

                            if (bricks[i, j].Pogodjen(ref score, lb))
                            {
                                cnv.Children.Remove(bricks[i, j].Blok);
                                bricks[i, j] = null;
                            }
                            bool p = false;
                            ball.Pomeraj(cnv.Width, cnv.Height, igrac, ref p);
                            return(LevelUp_Myb(ball, ref rad));
                        }
                        else if (Math.Abs(sideY) < circleR && sideX < 0)
                        {
                            ball.Odbij_Gore_Dole();

                            if (bricks[i, j].Pogodjen(ref score, lb))
                            {
                                cnv.Children.Remove(bricks[i, j].Blok);
                                bricks[i, j] = null;
                            }
                            bool p = false;
                            ball.Pomeraj(cnv.Width, cnv.Height, igrac, ref p);
                            return(LevelUp_Myb(ball, ref rad));
                        }
                    }
                    if (sideX * sideX + sideY * sideY < circleR * circleR)
                    {
                        ball.Odbij_Gore_Dole();
                        ball.Odbij_Desno_Levo();

                        if (bricks[i, j].Pogodjen(ref score, lb))
                        {
                            cnv.Children.Remove(bricks[i, j].Blok);
                            bricks[i, j] = null;
                        }
                        bool p = false;
                        ball.Pomeraj(cnv.Width, cnv.Height, igrac, ref p);
                        return(LevelUp_Myb(ball, ref rad));
                    }

                    /*if (gore_blok + blok.Height >= gore_lopta && gore_blok <= gore_lopta + lopta.Height)
                     * {
                     *  //MessageBox.Show("cao");
                     *  if (levo_blok + blok.Width >= levo_lopta && levo_blok <= levo_lopta + lopta.Width)
                     *  {
                     *      //if (!Cosak(ball, i, j))
                     *      {
                     *          if (levo_blok + blok.Width <= levo_lopta + lopta.Width || levo_lopta < levo_blok)
                     *              ball.Odbij_Desno_Levo();
                     *          if (gore_lopta + lopta.Height > gore_blok || gore_lopta < gore_blok)
                     *              ball.Odbij_Gore_Dole();
                     *      }
                     *
                     *      double dy = gore_blok - gore_lopta;
                     *      dy = Math.Abs(dy);
                     *      if(dy<blok.Height-3)
                     *      {
                     *          ball.Odbij_Desno_Levo();
                     *      }
                     *      else
                     *      {
                     *          if (gore_lopta + lopta.Height > gore_blok || gore_lopta < gore_blok)
                     *              ball.Odbij_Gore_Dole();
                     *      }
                     *
                     *      //if (gore_lopta + lopta.Height > gore_blok || gore_lopta < gore_blok)
                     *          ball.Odbij_Gore_Dole();
                     *      else
                     *      if (levo_blok + blok.Width <= levo_lopta + lopta.Width || levo_lopta < levo_blok)
                     *          ball.Odbij_Desno_Levo();
                     *
                     *
                     *
                     *      if (bricks[i, j].Pogodjen())
                     *      {
                     *          cnv.Children.Remove(bricks[i, j].Blok);
                     *          bricks[i, j] = null;
                     *      }
                     *      bool p = false;
                     *      ball.Pomeraj(cnv.Width,cnv.Height,igrac,ref p);
                     *      return;
                     *  }
                     * }*/
                }
            }
            return(false);
        }