Click here to Skip to main content
Click here to Skip to main content

Projectile Motion in Picturebox C#.Net

, 9 Mar 2013
Rate this:
Please Sign up or sign in to vote.

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.

 

 

 

 

 

 

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 

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

public Form1()
        {
            InitializeComponent();
        }
        int TimerCounter = 0;
        byte Duck_Pos = 5; 
       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             

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

History 

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)

About the Author

Syed Ubaid Ali Jafri

United States United States
Information Security Expert

Comments and Discussions

 
QuestionWork Pinmemberxaaqib12-Mar-13 10:41 
AnswerRe: Work PinmemberUbaid Ali14-Mar-13 20:40 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 10 Mar 2013
Article Copyright 2013 by Syed Ubaid Ali Jafri
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid