-
drawing a stick man
Hi,
This is a part of my project where i have drawn a stick man. As you can see in the code that i have used constants like (radius *2) etc to draw hand ,leg, head etc to draw the stick man. I am just wondering if it is considered a good programming practice or is there any other way around to accomplish the same task-just more eloquently.
Please keep in mind that i am quite a newbie and only familiar with functions and arrays and some other basic stuff. Have not reached to the "pointers" yet.
thanks
Code:
circle((int)x_position, (int)y_position, (int)radius); //head
line((int)x_position,(int)(y_position + radius),(int)x_position,(int)(y_position + (radius*4))); //body
line((int)(x_position-(radius*2)),(int)(y_position+(radius*2)),(int)(x_position+(radius*2)),(int)(y_position+(radius*2))); //hand
line((int)x_position,(int)(y_position+(radius*4)),(int)(x_position+radius),(int)(y_position+(radius*5))); //right leg
line((int)x_position,(int)(y_position+(radius*4)),(int)(x_position-radius),(int)(y_position+(radius*5))); //left leg
line((int)0,(int)(y_position+(radius*5)),(int)640,(int)(y_position+(radius*5))); // ground
-
Well I am confused why you are doing all those casts other than that it looks ok.
-
thanks,
do not worry about casting. As i said it is part of a project where stick man throws a projectile and if i use int then it will be funny path- not exactly like a parabola. Since those functions can only take int values.
Yes this code is working but i just wanna know if there is any efficient way to do it. I am thinking of skipping those constants somehow...
-
First of all, let me guess, your screen is 640x480. :) Second, 640 is already an int, you don't need to cast it.
See above.
Code:
((int)x_position,(int)(y_position + radius),
You only need those casts if the variables concernced aren't ints.