Untitled
raw download clone
CSHARP
views 23
,
size 2262 b
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        int radius, position_x, position_y, speed_x, speed_y;
        Color color;
        Random random = new Random();
        private Timer Game_Timer = new Timer();
    
        ball[] Balls = new ball[1];

        public Form1()
        {
            InitializeComponent();
            //DoubleBuffered = true;

            //Initilaze Timer
            Game_Timer.Interval = (Convert.ToInt32(1000 / 10));
            Game_Timer.Tick += new EventHandler(Game_Tick);

            //Create Balls
            for (int i = 0; i < Balls.Length; i++)
            {
                radius = random.Next(30, 80);
                position_x = random.Next(radius, Width - radius);
                position_y = random.Next(radius, Height - radius);
                speed_x = random.Next(5, 20);
                speed_y = random.Next(5, 20);
                color = Color.FromArgb(random.Next(0, 255), random.Next(5, 255), random.Next(5, 255));

                Balls[i] = new ball(radius, position_x, position_y, speed_x, speed_y, color);
            }

            //start Timer
            Game_Timer.Enabled = true;
            Game_Timer.Start();

        }

        private void Game_Tick(object myobject, EventArgs myEventArgs)
        {          
            foreach (ball Ball in Balls)
            {
                Ball.MoveBall(this);                
            }

            Invalidate();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics draw = CreateGraphics();
            DrawBalls(draw);
        }

        private void DrawBalls(Graphics draw)
        {
            foreach(ball Ball in Balls)
            {
                Brush brush = new SolidBrush(Ball.color);
                draw.FillEllipse(brush, Ball.position_x - Ball.radius, Ball.position_y - Ball.radius, Ball.radius, Ball.radius);
            }            
        }
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.