예제 #1
0
        public void move(OknoGry okno, Paddle belka)
        {
            if (visible)
            {
                x += speedX;
                y += speedY;

                if (x < 0)
                {
                    x       = 0;
                    speedX *= -1;
                }
                else if (x + width > okno.Width)
                {
                    x       = okno.Width - width;
                    speedX *= -1;
                }

                if (((x > belka.getX() && x < belka.getX() + belka.getWidth()) || (x + width > belka.getX() && x + width < belka.getX() + belka.getWidth())) &&
                    (y + height > belka.getY() && y + height < belka.getY() + belka.getHeight()))//warunek zderzenia z belka
                {
                    applyBonus(bonus, belka, okno.pilka, okno.lista, okno);
                    dezaktywuj();
                }
                else if (y + height > okno.Height)
                {
                    dezaktywuj();
                }
            }
        }
예제 #2
0
        public void move(OknoGry okno, Paddle belka)
        {
            if (visible)
            {
                x += speedX;
                y += speedY;

                if (x < 0)
                {
                    x = 0;
                    speedX *= -1;
                }
                else if (x + width > okno.Width)
                {
                    x = okno.Width - width;
                    speedX *= -1;
                }

                if (((x > belka.getX() && x < belka.getX() + belka.getWidth()) || (x + width > belka.getX() && x + width < belka.getX() + belka.getWidth())) &&
                    (y + height > belka.getY() && y + height < belka.getY() + belka.getHeight()))//warunek zderzenia z belka
                {
                    applyBonus(bonus, belka, okno.pilka, okno.lista, okno);
                    dezaktywuj();
                }
                else if (y + height > okno.Height)
                {
                    dezaktywuj();
                }
            }
        }
예제 #3
0
        /*
         * Instantiate GameCanvas and add game elements into it: ball, paddle and bricks.
         * */
        private void setupGameField(int rows, int columns)
        {
            //Canvas size width 600 height 350
            //Settting up canvas
            GameCanvas            = new Canvas();
            GameCanvas.Height     = spCanvas.Height;
            GameCanvas.Width      = spCanvas.Width;
            GameCanvas.Background = new SolidColorBrush(Colors.Black);
            spCanvas.Children.Add(GameCanvas);
            GameCanvas.Tapped += GameCanvas_Tapped;

            //Adding bricks 3.0
            _bricks = new List <Brick>();
            LevelBuilder lb = new LevelBuilder();

            _bricks = lb.getNewRandomLevelLayout(rows, columns, GameCanvas);

            foreach (Brick brick in _bricks)
            {
                GameCanvas.Children.Add(brick.getBrick());
            }

            //Adding Paddle 1.0
            paddle = new Paddle((int)(GameCanvas.Width / 2) - 50, (int)(GameCanvas.Height) - 6, 100, 6);
            Canvas.SetLeft(paddle.getPaddle(), paddle.getX());
            Canvas.SetTop(paddle.getPaddle(), paddle.getY());
            GameCanvas.Children.Add(paddle.getPaddle());

            //Adding Ball 1.0
            ball = new Ball(paddle.getX() + (paddle.getWidth() / 2), paddle.getY() - 11, 10, 10);
            Canvas.SetLeft(ball.getBall(), ball.getX());
            Canvas.SetTop(ball.getBall(), ball.getY());
            GameCanvas.Children.Add(ball.getBall());
        }
예제 #4
0
 public void setStart(Paddle belka, OknoGry okno)
 {
     setX(belka.getX() + belka.getWidth() / 2 - width / 2);
     setY(okno.Height - belka.getHeight() - height - 40);
     setSpeedX(6);
     setSpeedY(-6);
     belka.setWidth(belka.getBitmap().Width);
 }
예제 #5
0
        public void move(Paddle belka, OknoGry okno)
        {
            if (!okno.gra)
            {
                x = belka.getX() + belka.getWidth() / 2 - width / 2;
            }
            else
            {
                x += speedX;
                y += speedY;//poruszanie sie pilki
                if (x < 0)
                {
                    x = 0;
                    speedX *= -1;
                }
                else if (x > okno.Width - width)
                {
                    x = okno.Width - width;
                    speedX *= -1;
                }
                if (y < 0)
                {
                    y = 0;
                    speedY *= -1;
                }
                else if (y > okno.Height - height)
                {
                    okno.gra = false;
                    setStart(belka, okno);
                    Message poziom = new Message(okno.Width / 2, okno.Height / 2, "Tracisz zycie!", 1000, false, Color.Black);
                    okno.listaMessage.Add(poziom);//dodanie wiadomości
                    okno.pilka.setBalls(okno.pilka.getBalls() - 1);

                    if (okno.pilka.getBalls() <= 0)
                    {
                        MessageBox.Show("Przegrana!");
                        Application.Exit();
                    }

                }//sprawdzenie czy nie wychodzi poza ramy
                if(this*belka>0)
                {
                    speedY *= -1;
                }//kolizja z belka

            }
        }
예제 #6
0
        public void move(Paddle belka, OknoGry okno)
        {
            if (!okno.gra)
            {
                x = belka.getX() + belka.getWidth() / 2 - width / 2;
            }
            else
            {
                x += speedX;
                y += speedY;//poruszanie sie pilki
                if (x < 0)
                {
                    x       = 0;
                    speedX *= -1;
                }
                else if (x > okno.Width - width)
                {
                    x       = okno.Width - width;
                    speedX *= -1;
                }
                if (y < 0)
                {
                    y       = 0;
                    speedY *= -1;
                }
                else if (y > okno.Height - height)
                {
                    okno.gra = false;
                    setStart(belka, okno);
                    Message poziom = new Message(okno.Width / 2, okno.Height / 2, "Tracisz zycie!", 1000, false, Color.Black);
                    okno.listaMessage.Add(poziom);//dodanie wiadomości
                    okno.pilka.setBalls(okno.pilka.getBalls() - 1);

                    if (okno.pilka.getBalls() <= 0)
                    {
                        MessageBox.Show("Przegrana!");
                        Application.Exit();
                    }
                }//sprawdzenie czy nie wychodzi poza ramy
                if (this * belka > 0)
                {
                    speedY *= -1;
                }//kolizja z belka
            }
        }
예제 #7
0
 public void setStart(Paddle belka, OknoGry okno)
 {
     setX(belka.getX() + belka.getWidth() / 2 - width / 2);
     setY(okno.Height - belka.getHeight() - height - 40);
     setSpeedX(6);
     setSpeedY(-6);
     belka.setWidth(belka.getBitmap().Width);
 }
예제 #8
0
 private void updatePaddlePosition(AccelerometerReading reading)
 {
     // use the AccelerationY: if < -0.04 move right
     //                        if >0.04 move left
     //Check if is started if not, the ball will move along the paddle
     if (isStarted)
     {
         if (reading.AccelerationY > 0.04)
         {
             if (!((double)paddle.getPaddle().GetValue(Canvas.LeftProperty) <= 0))
             {
                 // move left
                 paddle.setX(paddle.getX() - increment);
                 Canvas.SetLeft(paddle.getPaddle(), paddle.getX());
             }
         }
         else if (reading.AccelerationY < -0.04)
         {
             if (!((double)paddle.getPaddle().GetValue(Canvas.LeftProperty) >= (GameCanvas.ActualWidth - paddle.getPaddle().Width)))
             {
                 // move right
                 paddle.setX(paddle.getX() + increment);
                 Canvas.SetLeft(paddle.getPaddle(), paddle.getX());
             }
         }
     }
     else
     {
         if (reading.AccelerationY > 0.1)
         {
             if (!((double)paddle.getPaddle().GetValue(Canvas.LeftProperty) <= 0))
             {
                 // move left
                 ball.setX(ball.getX() - increment);
                 Canvas.SetLeft(ball.getBall(), ball.getX());
                 paddle.setX(paddle.getX() - increment);
                 Canvas.SetLeft(paddle.getPaddle(), paddle.getX());
             }
         }
         else if (reading.AccelerationY < -0.1)
         {
             if (!((double)paddle.getPaddle().GetValue(Canvas.LeftProperty) >= (GameCanvas.ActualWidth - paddle.getPaddle().Width)))
             {
                 // move right
                 ball.setX(ball.getX() + increment);
                 Canvas.SetLeft(ball.getBall(), ball.getX());
                 paddle.setX(paddle.getX() + increment);
                 Canvas.SetLeft(paddle.getPaddle(), paddle.getX());
             }
         }
     }
 }