Example #1
0
 public void AddBall()
 {
     Ball anotherball = new Ball();
     anotherball.CenterPositionF = new Point(buffle.left + BuffleWidth / 2, BuffleTop - (int)Radius);
     anotherball.MoveDirection = Vector2.GetRandomVector2(0.9f, 1.0f, -0.9f, -1.0f);
     anotherball.lv = Energy/5;
     balls.Add(anotherball);
 }
Example #2
0
        bool CheckCollision(Ball thisball)
        {
            bool flag = false;
            bool x_turn = false;
            bool y_turn = false;
            if (thisball.CenterPositionF.Y > BuffleTop)
            {
                gamerunning = false;
                return false;
            }
            if (bricks_remained == 0)
            {
                gamerunning = false;
                return false;
            }
            if (thisball.CenterPositionF.Y > BuffleTop - Radius)
            {
                if (thisball.CenterPositionF.X > buffle.left && thisball.CenterPositionF.X < buffle.left + BuffleWidth)
                {
                    flag = true;
                    y_turn = true;
                    thisball.MoveDirection.X = ((float)(thisball.CenterPositionF.X - buffle.left - BuffleWidth / 2) / (float)Radius);
                    while (thisball.MoveDirection.X * thisball.MoveDirection.X >= 4.0f)
                        thisball.MoveDirection.X += (thisball.MoveDirection.X > 0) ? (-1.0f) : 1.0f;
                }
            }

            Brick br;
            List<Brick> br_rm = new List<Brick>();
            for (int i = 0; i < bricks.Count(); i++)
            {
                br = bricks[i];
                if (thisball.CenterPositionF.X > br.Pos.Left - Radius
                    && thisball.CenterPositionF.X < br.Pos.Left + br.Pos.Width + Radius)
                {
                    if (thisball.CenterPositionF.Y > br.Pos.Top - Radius
                    && thisball.CenterPositionF.Y < br.Pos.Top + br.Pos.Height + Radius)
                    {
                        flag = true;
                        for (int j = 0; j < 1 + thisball.lv; j++ )
                        {
                            if (br.HitBrick())
                            {
                                bricks_remained--;
                                br_rm.Add(br);
                                break;
                            }
                        }
                        if (thisball.CenterPositionF.X < br.Pos.Left
                            || thisball.CenterPositionF.X > br.Pos.Left + br.Pos.Width)
                            x_turn = true;
                        if (thisball.CenterPositionF.Y < br.Pos.Top
                            || thisball.CenterPositionF.Y > br.Pos.Top + br.Pos.Height)
                            y_turn = true;
                    }
                }
            }
            if (thisball.CenterPositionF.Y < Pos.Top + Radius)
            {
                flag = true;
                y_turn = true;
            }
            if (thisball.CenterPositionF.X < Pos.Left + Radius
                || thisball.CenterPositionF.X > Pos.Right - Radius)
            {
                flag = true;
                x_turn = true;
            }
            if (x_turn) thisball.MoveDirection.X *= -1;
            if (y_turn) thisball.MoveDirection.Y *= -1;

            Item newitem;
            foreach (Brick b in br_rm)
            {
                bricks.Remove(b);
                //item produced
                if (GetRandom.GetRandomFloat() <= 0.4f)
                {
                    newitem = new Item(b.Pos.Location, GetRandom.GetRandomInt(6), BuffleTop, ItemFallFactor);
                    items.Add(newitem);
                }
            }

            return flag;
        }
Example #3
0
        public void Init(int lv)
        {
            //def global values
            BuffleTop = Pos.Bottom - 30;
            BallMoveFactor = 6.0f + 1.0f * lv;
            BuffleMoveDistance = 15 + 3 * lv;
            ItemFallFactor = 4 + 1 * lv;
            Energy = 0;
            canmove = false;
            gamerunning = false;
            //add buffle
            buffle = new Board(0, Pos.Left + Pos.Width / 2, BuffleTop, BuffleWidth);
            //add first ball
            balls.Clear();
            Ball thisball = new Ball();
            thisball.CenterPositionF = new PointF(buffle.left + BuffleWidth / 2, BuffleTop - Radius);
            thisball.MoveDirection = Vector2.GetRandomVector2(0.9f, 1.0f, -0.9f, -1.0f);
            thisball.lv = 0;
            balls.Add(thisball);
            //add bricks
            bricks.Clear();
            bricks_remained = 0;

            int bricktotalheight = 8 + lv;
            bricktotalheight = (bricktotalheight > 12) ? 12 : bricktotalheight;

            for (int i = 0; i < Pos.Width / brickwidth; i++)
            {
                for (int j = 0; j < bricktotalheight; j++)
                {
                    if (GetRandom.GetRandomFloat() <= 0.5f)
                    {
                        int lv_rnd = lv + 1;
                        lv_rnd = lv_rnd > 5 ? 5 : lv_rnd;
                        lv_rnd = GetRandom.GetRandomInt(lv_rnd);

                        Brick newbrick = new Brick(lv_rnd, new Rectangle(Pos.Left + i * brickwidth,
                            Pos.Top + j * brickheight, brickwidth, brickheight));
                        bricks.Add(newbrick);
                        if (lv_rnd != 4)
                        {
                            bricks_remained++;
                        }

                    }
                }
            }
            //clear items
            items.Clear();
        }