Ejemplo n.º 1
0
 private void KEYPRESS(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.R)
     {
         b = new ball(25, 125, 1, 0, 2 * PIf);
     }
 }
Ejemplo n.º 2
0
 public Form1()
 {
     InitializeComponent();
     canvas = new Bitmap(500, 500);
     g      = Graphics.FromImage(canvas);
     b      = new ball(25, 125, 1, 0, 2 * PIf);
     rnd    = new Random();
 }
Ejemplo n.º 3
0
        private void GAMELOOP_Tick(object sender, EventArgs e)
        {
            b.dx = (float)Math.Cos(b.a);
            b.dy = (float)Math.Sin(b.a);
            b.x += b.dx * 8;
            b.y += b.dy * 8;

            //Console.WriteLine(b.y + " " + (lefty + 50) + " " + lefty);

            if ((b.y >= lefty - 25 && b.y <= lefty + 25) && b.x <= 10 && !hl)
            {
                //hit
                float isc = lefty - b.y;
                b.a = b.a + PIf - -((float)Math.Sin(isc) / 2);
                Console.WriteLine(isc);
                hl = true;
            }
            if ((b.y >= righty - 25 && b.y <= righty + 25) && b.x >= 485 && !hr)
            {
                //hit
                float isc = righty - b.y;
                b.a = b.a + PIf - -((float)Math.Sin(isc) / 2);
                Console.WriteLine(isc);
                hr = true;
            }
            if (b.y <= 0 && !ht)
            {
                Console.WriteLine("hit roof");
                //hit roof
                b.a = -b.a;
                ht  = true;
            }
            if (b.y >= 250 && !hb)
            {
                //hit floor
                Console.WriteLine("hit floor");
                b.a = -b.a;
                hb  = true;
            }

            if (b.y > 0 && b.y < 250 && b.x > 10 && b.x < 485)
            {
                hl = false;
                hr = false;
                ht = false;
                hb = false;
            }

            if (b.x < 0 || b.x > 500)
            {
                b     = new ball(25, 125, 1, 0, 2 * PIf);
                death = 5;
            }

            drawGame();
        }