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
<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.