Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. namespace LaBall
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.  
  6.         private int x = 0;
  7.         private int speed = 1;
  8.         private int hit = 0;
  9.         private int yball;
  10.         private int xball;
  11.         private int size = 25;
  12.  
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.             timer1.Interval = 10;
  17.             timer1.Start();
  18.         }
  19.  
  20.         private void timer1_Tick(object sender, EventArgs e)
  21.         {
  22.             x += speed;
  23.  
  24.             if (x > Size.Width) x = 0;
  25.  
  26.             SolidBrush pen = new SolidBrush(Color.Red);
  27.             Graphics g = pictureBox1.CreateGraphics();
  28.             Bitmap b = new Bitmap(Properties.Resources.Wasser, Size);
  29.             g.DrawImage(b, 0, 0);
  30.             Rectangle ball = new Rectangle(x, 100, size, size);
  31.             g.FillEllipse(pen, ball);
  32.  
  33.             g.Dispose();
  34.         }
  35.  
  36.       /*  private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  37.         {
  38.             if (e.KeyChar == '+')
  39.             {
  40.                 speed++;
  41.             }
  42.             if (e.KeyChar == '-')
  43.             {
  44.                 speed--;
  45.             }
  46.             if (speed > 30) speed = 30;
  47.             if (speed < 0) speed = 0;
  48.         } */
  49.  
  50.        
  51.         private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  52.         {
  53.             if (e.KeyChar == 'g')
  54.             {
  55.                 size++;    // Ball soll größer werden
  56.             }
  57.             if (e.KeyChar == 'k')
  58.             {
  59.                 size--; // Ball soll kleiner werden
  60.             }
  61.             if (size > 50) size = 50;
  62.             if (size < 10) size = 10;
  63.         }
  64.  
  65.         private void pictureBox1_MouseDown_1(object sender, MouseEventArgs e)
  66.         {
  67.             //  if (e.X <= xball + 25 && e.X >= xball - 25 && e.Y <= yball + 25 && e.Y >= yball - 25) //Prüft im durchmesser 25 pixel ob mausklick in der GraPHik ist.
  68.             if (e.X < xball + size && e.X > xball && e.Y < yball + size && e.Y > yball)
  69.             {
  70.                 hit++;
  71.                 lbl1_hit.Text = Convert.ToString(hit);
  72.             }
  73.         }
  74.  
  75.         private void lbl1_hit_Click(object sender, EventArgs e)
  76.         {
  77.             lbl1_hit.Parent = pictureBox1;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement