Exemplo n.º 1
0
 public bool CheckUnderTheBall(WonderBall wonderBall, int sizeOfBlock, int height)
 {
     return(Math.Abs(height - 100 - wonderBall.Y - sizeOfBlock / 2) < 10 &&
            this.FirstFloor[wonderBall.X / sizeOfBlock].IsBlock ||
            Math.Abs(height - 350 - wonderBall.Y - sizeOfBlock / 2) < 10 &&
            this.SecondFloor[wonderBall.X / sizeOfBlock].IsBlock);
 }
Exemplo n.º 2
0
        public static Tuple <WonderBall, Level, double, int> GetNextStep(
            WonderBall wonderBall,
            Level level,
            double speed,
            int indexOfLevel,
            int sizeOfBlock,
            GameForm form)
        {
            speed         = speed + (gravity - 0.01 * speed) * 0.1;
            wonderBall.Y  = wonderBall.Y + (int)(speed * 0.1 + gravity * 0.01);
            wonderBall.X -= Math.Sign(wonderBall.X - form.PointToClient(Cursor.Position).X) * 2;

            if (wonderBall.Y > 600)
            {
                wonderBall.Y = 0;
                indexOfLevel++;
                level = Level.GetRandomLevel(form.Width / sizeOfBlock, indexOfLevel / 5);
            }
            else if (wonderBall.Y <= 0 && speed < 0)
            {
                speed = -speed * wonderBall.JumpForce;
            }

            if (wonderBall.X >= form.Width)
            {
                wonderBall.X = 1;
            }
            else if (wonderBall.X <= 0)
            {
                wonderBall.X = form.Width - 1;
            }


            if (level.CheckUnderTheBall(wonderBall, sizeOfBlock, form.Height) || level.CheckUpperTheBall(wonderBall, sizeOfBlock, form.Height))
            {
                if (level.FirstFloor[wonderBall.X / sizeOfBlock].IsDeath || level.SecondFloor[wonderBall.X / sizeOfBlock].IsDeath)
                {
                    wonderBall.X = int.MaxValue;
                }
                else if (level.CheckUnderTheBall(wonderBall, sizeOfBlock, form.Height) && speed > 0)
                {
                    speed = -speed * wonderBall.JumpForce;
                }
                else if (level.CheckUpperTheBall(wonderBall, sizeOfBlock, form.Height) && speed < 0)
                {
                    speed = -speed * wonderBall.JumpForce;
                }
            }

            return(new Tuple <WonderBall, Level, double, int>(wonderBall, level, speed, indexOfLevel));
        }
Exemplo n.º 3
0
        public GameForm()
        {
            DoubleBuffered = true;
            Cursor.Hide();
            ClientSize = new Size(height, width);

            var speed        = 0.0;
            var indexOfLevel = 0;

            var wonderBall = new WonderBall(new Point(200, 200), sizeOfBlock - 10, 0.9);

            wonderBall.Position = this.PointToClient(new Point(Cursor.Position.X, this.PointToScreen(wonderBall.Position).Y));

            var level = Level.GetRandomLevel(width / sizeOfBlock, 0);

            var time  = 0;
            var timer = new Timer();

            timer.Interval = 10;
            timer.Tick    += (sender, args) =>
            {
                time++;
                Invalidate();
            };
            timer.Start();

            Paint += (sender, args) =>
            {
                var indexOfBlock = 0;
                foreach (var cell in level.FirstFloor)
                {
                    args.Graphics.FillRectangle(cell.Brush, indexOfBlock * sizeOfBlock, height - 60, sizeOfBlock,
                                                sizeOfBlock);
                    indexOfBlock++;
                    //args.Graphics.DrawImage(new Bitmap(Minecraft.block, sizeOfBlock, sizeOfBlock),
                    //    indexOfBlock * sizeOfBlock, height - 60);
                }

                indexOfBlock = 0;
                foreach (var cell in level.SecondFloor)
                {
                    args.Graphics.FillRectangle(cell.Brush, indexOfBlock * sizeOfBlock, height - 310, sizeOfBlock,
                                                sizeOfBlock);
                    indexOfBlock++;
                }

                args.Graphics.FillEllipse(Brushes.Yellow,
                                          this.PointToClient(Cursor.Position).X - wonderBall.Size / 2,
                                          wonderBall.Y,
                                          wonderBall.Size + 5,
                                          wonderBall.Size + 5);

                args.Graphics.DrawImage(new Bitmap(Minecraft.ball, wonderBall.Size + 5, wonderBall.Size + 5),
                                        wonderBall.X - wonderBall.Size / 2,
                                        wonderBall.Y);

                args.Graphics.DrawString("Scores: " + ((double)(1 + indexOfLevel) / 2 * indexOfLevel).ToString(), new Font("Arial", 20), Brushes.Black, 0, 0);

                var game = Game.GetNextStep(wonderBall, level, speed, indexOfLevel, sizeOfBlock, this);

                wonderBall   = game.Item1;
                level        = game.Item2;
                speed        = game.Item3;
                indexOfLevel = game.Item4;

                if (wonderBall.X == int.MaxValue)
                {
                    timer.Stop();
                    args.Graphics.DrawString("GAME OVER", new Font("Calibri", 52), Brushes.Red, width / 3, height / 2);
                }
            };
        }