james johnson

james johnson

  • NA
  • 5
  • 2.5k

Adding Gravity to Drawings

Feb 19 2011 11:59 AM
Hi, im creating a pshyics based drawing game much like "Powder-Toy". The user simply selects the material they want to build with, then draw it. The materials react with each other in different ways. So far i have added the ability to draw in "TNT", "Brick" and "Water" but ive got stuck. i need a way to add gravity to the water object as its being drawn in. I then want it to stop falling once its hit something solid, E.g. a brick bucket.
Bellow is the code:

namespace SandBox
{
    public partial class Form1 : Form
    {
        int Gravity = -10;

        SolidBrush ADDTNT;
        SolidBrush ADDBrick;
        SolidBrush ADDWater;
        bool paintTNT = false;
        bool paintBrick = false;
        bool paintWater = false;
        bool paintEnable = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void AddTNT(object sender, MouseEventArgs e)
        {
            txtMaterial.Text = "TNT";
            paintTNT = true;
            paintBrick = false;
            paintWater = false;
        }
       
        private void AddBrick(object sender, EventArgs e)
        {
            txtMaterial.Text = "Brick";
            paintTNT = false;
            paintBrick = true;
            paintWater = false;
        }

        private void AddWater(object sender, EventArgs e)
        {
            txtMaterial.Text = "Water";
            paintTNT = false;
            paintBrick = false;
            paintWater = true;
        } 

        private void Paint(object sender, MouseEventArgs e)
        {
            if (paintTNT & paintEnable)
            {
                ADDTNT = new SolidBrush(Color.Red);
                Graphics g = panel1.CreateGraphics();
                g.FillEllipse(ADDTNT, e.X, e.Y, 10, 10);
                g.Dispose();
            }

            if (paintBrick & paintEnable)
            {
                ADDBrick = new SolidBrush(Color.Brown);
                Graphics g = panel1.CreateGraphics();
                g.FillEllipse(ADDBrick, e.X, e.Y, 10, 10);
                g.Dispose();
            }

            if (paintWater & paintEnable)
            {
                ADDWater = new SolidBrush(Color.Blue);
                Graphics g = panel1.CreateGraphics();
                g.FillEllipse(ADDWater, e.X, e.Y, 10, 10);
                g.Dispose();
            }
        }

        private void PaintEnable(object sender, MouseEventArgs e)
        {
            paintEnable = true;
        }

        private void PaintDisable(object sender, MouseEventArgs e)
        {
            paintEnable = false;
        }
    }
}

Thanks alot for any help :):):)

Answers (3)