Example #1
0
        private void StartGame()
        {
            Cursor.Hide();
            GameOver = false; MainMenu = false; MainMenuOpening = false; LevelFinished = false;
            Score    = 0; Life = 3; Level = 1; ScoreOnBoard = 0;
            line     = new DXLine(400f, 640f);

            walls = new List <DXWall>();
            walls.Add(new DXWall(WallType.Vertical, 48f, 120f));
            walls.Add(new DXWall(WallType.Vertical, 896f, 120f));
            walls.Add(new DXWall(WallType.Horizontal, 48f, 104f));

            balls = new List <Ball>();
            Ball b = new Ball(0f, 0f);

            b.BrokeBox += b_BrokeBox; b.TouchLine += b_TouchLine;
            b.SetDeterminateVelocity(15f, 0.25f, -Math.PI * 0.75); b.MaxVelocity = 30f;
            balls.Add(b);

            boxes = DXLevels.OpenLevel(Level);

            LoadAnimations();

            balls[0].AddRectangleOfLine(line);
            balls[0].AddRectanglesOfWalls(walls);
            balls[0].Boxes = boxes;
        }
Example #2
0
        public void CollectableCollectionCheckTest()
        {
            Collectables c = new MultiBall(0f, 0f);
            DXLine       l = new DXLine(0f, 50f);

            c.AddLine(l);

            Assert.IsFalse(c.Collected);

            c.PosY = l.LineRectangle.Top;
            c.PosX = l.LineRectangle.Right;

            c.CollectionCheck(l.LineRectangle);

            Assert.IsTrue(c.Collected);
        }
Example #3
0
        public void moveLineTest()
        {
            DXLine line = new DXLine(70, 0);

            float temp = line.PosX;

            line.MoveRight = true;
            line.MoveLine();
            Assert.AreEqual(line.PosX, temp + 20);

            line.MoveRight = false;

            temp          = line.PosX;
            line.MoveLeft = true;
            line.MoveLine();
            Assert.AreEqual(line.PosX, temp - 20);
        }
Example #4
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        private void StartGame()
        {
            countdown       = 105;
            GameOver        = false;
            MainMenu        = false;
            MainMenuOpening = false;
            LevelFinished   = false;
            Score           = 0;
            Life            = 3;
            Level           = 1;
            ScoreOnBoard    = 0;
            line            = new DXLine(400f, 707f);

            walls = new List <DXWall>();
            walls.Add(new DXWall(WallType.Vertical, 48f, 120f));
            walls.Add(new DXWall(WallType.Vertical, 896f, 120f));
            walls.Add(new DXWall(WallType.Horizontal, 48f, 104f));

            balls = new List <Ball>();
            Ball b = new Ball(0f, 0f);

            b.BrokeBox  += b_BrokeBox;
            b.TouchLine += b_TouchLine;
            b.SetDeterminateVelocity(15f, 0.25f, -Math.PI * 0.75);
            b.MaxVelocity = 30f;
            balls.Add(b);

            backGround = new BackgroundPage();

            boxes = DXLevels.OpenLevel(Level);
            colls = DXCollectables.OpenCollectables(Level);

            foreach (Collectables c in colls)
            {
                c.AddLine(line);
            }

            LoadAnimations();

            balls[0].AddRectangleOfLine(line);
            balls[0].AddRectanglesOfWalls(walls);
            balls[0].Boxes        = boxes;
            balls[0].Collectables = colls;
        }
Example #5
0
        //public void MoveBall()
        //{
        //    float leftPoint = posX, rightPoint = posX + 16f, topPoint = posY, bottomPoint = posY + 16f,
        //        bounceX = 0f, bounceY = 0f;

        //    foreach (RectangleF _rect in OtherRectangles)
        //    {
        //        float deltaRight = _rect.Left - rightPoint, deltaLeft = _rect.Right - leftPoint,
        //            deltaTop = _rect.Bottom - topPoint, deltaBottom = _rect.Top - bottomPoint;
        //        bool betweenTopAndBottom = topPoint + 8 >= _rect.Top + velY && topPoint + 8 <= _rect.Bottom + velY,
        //            betweenLeftAndRight = leftPoint + 8 >= _rect.Left + velX && leftPoint + 8 <= _rect.Right + velY;
        //        if (deltaRight >= 0 && deltaRight < velX && betweenTopAndBottom)
        //        { bounceX += 2 * deltaRight - velX; velX = -velX; }
        //        if (deltaLeft <= 0 && deltaLeft > velX && betweenTopAndBottom)
        //        { bounceX += 2 * deltaLeft - velX; velX = -velX; }
        //        if (deltaBottom >= 0 && deltaBottom < velY && betweenLeftAndRight)
        //        { bounceY += 2 * deltaBottom - velY; velY = -velY; }
        //        if (deltaTop <= 0 && deltaTop > velY && betweenLeftAndRight)
        //        { bounceY += 2 * deltaTop - velY; velY = -velY; }
        //    }
        //    posX += bounceX; posY += bounceY;
        //    posX += velX; posY += velY;

        //    ballBrush.ResetTransform();
        //    ballBrush.TranslateTransform(posX, posY);
        //    ballRectangle.X = posX; ballRectangle.Y = posY;
        //}

        //private void CalculateBounceTarget()
        //{
        //    float centerX, centerY;
        //    float dv, dvx, dvy;
        //    double ang;
        //    ang = Math.Atan((float)(velX / velY));
        //    dv = 0.1f; dvx = dv * ((float)Math.Cos(ang)); dvy = dv * ((float)Math.Sin(ang));
        //    centerX = (ballRectangle.Right + ballRectangle.Left) / 2;
        //    centerY = (ballRectangle.Bottom + ballRectangle.Top) / 2;
        //    while (true)
        //    {
        //        centerX += dvx; centerY += dvy;
        //        foreach (RectangleF _rect in AllRectangles)
        //        {
        //            float delXLeft = Math.Abs(centerX - _rect.Left), delXRight = centerX - _rect.Left,
        //                delYTop = centerY - _rect.Top, delYBottom = centerY - _rect.Bottom;
        //            if (delXLeft < 16f)
        //            {
        //                break;
        //            }
        //        }
        //    }
        //}

        //public void IntersectRectangle(RectangleF destRect)
        //{
        //    PointF[] _points = new PointF[4];
        //    _points[0] = new PointF((ballRectangle.Right + ballRectangle.Left) / 2, ballRectangle.Top);
        //    _points[1] = new PointF(ballRectangle.Right, (ballRectangle.Bottom + ballRectangle.Top) / 2);
        //    _points[2] = new PointF((ballRectangle.Right + ballRectangle.Left) / 2, ballRectangle.Bottom);
        //    _points[3] = new PointF(ballRectangle.Left, (ballRectangle.Bottom + ballRectangle.Top) / 2);
        //    if (IntersectPointToRectangle(_points[0], destRect) || IntersectPointToRectangle(_points[2], destRect))
        //    { velY = -velY; MoveBall(); }
        //    if (IntersectPointToRectangle(_points[1], destRect) || IntersectPointToRectangle(_points[3], destRect))
        //    { velX = -velX; MoveBall(); }
        //}

        //private bool IntersectPointToRectangle(PointF _point, RectangleF _rect)
        //{
        //    return _point.Y > _rect.Top && _point.Y < _rect.Bottom && _point.X > _rect.Left && _point.X < _rect.Right;
        //}

        public void AddRectangleOfLine(DXLine __line)
        {
            _line = __line;
        }
Example #6
0
 public void AddLine(DXLine _line)
 {
     line = _line;
 }