Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace WindowsFormsApplication2
- {
- public partial class Form1 : Form
- {
- Timer ticker = new Timer();
- List<ButtonPos> buttons = new List<ButtonPos>();
- struct ButtonPos
- {
- public Button button;
- public Vector2 Velocity;
- public int LifeTime;
- }
- struct Vector2
- {
- public float X;
- public float Y;
- public Vector2(float X, float Y)
- {
- this.X = X;
- this.Y = Y;
- }
- }
- Random rnd = new Random();
- public Form1()
- {
- InitializeComponent();
- ticker.Tick += ticker_Tick;
- ticker.Interval = 15;
- ticker.Start();
- }
- DateTime time = DateTime.Now;
- Vector2 Gravitation = new Vector2(0, 5.5f);
- float factor = 0.05f;
- void ticker_Tick(object sender, EventArgs e)
- {
- var diff = (DateTime.Now - time);
- var ntime = new TimeSpan(2000000);
- if (diff > ntime)
- {
- buttons.Add(new ButtonPos
- {
- button = new Button(),
- Velocity = new Vector2(rnd.Next(-100, 100), -150 + rnd.Next(-100, 0)),
- LifeTime = 200
- });
- var newbutton = buttons[buttons.Count-1];
- newbutton.button.Parent = this;
- newbutton.button.Location = label1.Location;
- newbutton.button.Text = "+";
- newbutton.button.Show();
- newbutton.button.Enabled = true;
- time = DateTime.Now;
- }
- for (int i = 0; i < buttons.Count; i++ )
- {
- var btn = buttons[i];
- btn.button.Location = new Point((int)(btn.button.Location.X + btn.Velocity.X * factor), (int)(btn.button.Location.Y + btn.Velocity.Y * factor));
- if (btn.button.Location.Y > this.ClientSize.Height)
- btn.Velocity = new Vector2(btn.Velocity.X, btn.Velocity.Y * -1);
- btn.Velocity = new Vector2(btn.Velocity.X + Gravitation.X, btn.Velocity.Y + Gravitation.Y);
- btn.LifeTime--;
- if (btn.LifeTime < 0)
- {
- buttons.RemoveAt(i);
- btn.button.Hide();
- }
- else
- buttons[i] = btn;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement