Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#4.0

Projectile Motion in Picturebox C#.Net

0.00/5 (No votes)
10 Mar 2013CPOL 21.9K   1.4K  

Introduction

C#.Net consist a large varieties of Libraries and namespace,  when considering an application which requires a motion that may be projectile or hyperbola. In the context of this statement C#.Net has provided System.Drawing Library and Point Class to draw the point on different Axis (x,y). Implementing projectile motion using for loops and other techniques create complexities and coding overhead for the programmers. This technique will help you to create projectile motion using timer and Graph Logic.

Image 1

 

 

 

 

 

 

Background

Projectile motion is difficult to implement in C#.Net. when placing a Position on Windows Form it immediately triggers, this is a common problem faced by different Students and professionals. 

Using the code 

Image 2

This graph will help the user to draw any motion in C#.Net . As the axis are defined and Described in the above image

C#
public Form1()
        {
            InitializeComponent();
        }
        int TimerCounter = 0;
        byte Duck_Pos = 5; 
C++
void Duck_SmallJump()
 {
     TimerCounter++;
     if (TimerCounter <= 10)
         duck.Location = new Point(duck.Location.X - 4, duck.Location.Y - 6);
     else if (TimerCounter > 10 && TimerCounter <= 15)
         duck.Location = new Point(duck.Location.X - 6, duck.Location.Y - 4);
     else if (TimerCounter > 15 && TimerCounter <= 20)
         duck.Location = new Point(duck.Location.X - 8, duck.Location.Y + 4);
     else if (TimerCounter > 20 && TimerCounter <= 30)
         duck.Location = new Point(duck.Location.X - 8, duck.Location.Y + 6);

     else
     {
         timer1.Enabled = false;
         TimerCounter = 0;
         Duck_Pos -= 1;
     }
 }

Points of Interest             Image 3

<o:p> In Form Design, A property named Double Buffered should be checked true in order to minimize the latency of pictureBox. 

History <o:p>

Defining the Dimension are always the critical area in programming, to identify the location of axis and placing the new point on that location mostly the complex task.   

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)