Click here to Skip to main content
15,885,435 members
Articles / Programming Languages / C# 4.0
Tip/Trick

Projectile Motion in Picturebox C#.Net

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
9 Mar 2013CPOL 21.4K   1.4K   6   2

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)


Written By
United States United States
Information Security Expert

Comments and Discussions

 
QuestionWork Pin
xaaqib12-Mar-13 10:41
xaaqib12-Mar-13 10:41 
AnswerRe: Work Pin
Syed Ubaid Ali Jafri14-Mar-13 20:40
Syed Ubaid Ali Jafri14-Mar-13 20:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.