//stick man
void DrawMan(int x, int colour)
{
int y = 300;
//set colour
setcolor(colour);
//Draw Man
circle(x, y, 10);
line(x-10, y+20,x+10, y+20);
line(x, y+10, x, y+30);
line(x, y+30, x-10, y+50);
line(x, y+30, x+10, y+50);
}
int main(void)
{
int x_position = 9;
int y_position = 300;
gravity = 9.81;
~~~
~~~
//Throw a ball
case \'p\':
if (key == 0)
key = getch();
if (key == \'p\')
{
printf(\"***SELECT ANGLE AND SPEED***\\n\");
printf(\"what is the angle: \");
scanf(\"%lf\",&angle);
printf(\"what is the speed: \");
scanf(\"%lf\",&velocity);
vel_y= velocity*sin(angle * PI/180.0);
vel_x= velocity*cos(angle * PI/180.0);
pos_y = y_position;
moveto((int)x_position+10, (int)y_position+20);
/* Loop over time */
for (pos_x = x_position; pos_y <= y_position+30; pos_x++)
{
/* Calculate new height */
time = (pos_x - x_position) / vel_x;
pos_y = y_position - (vel_y * time) + (gravity * time * time);
/* Draw a line */
lineto((int)pos_x+10, (int)pos_y+20);
}
//////////////////////////////////// 못움직이게 시도 하고 있는 구문
//if (key=77) 77은 키보드 화살표 숫자
// if(x_position <= || x_position >= )
// x_position = ;
// DrawMan(x_position, (int) colour);
//////////////if (key=75) 75 또한 키보드 화살표 숫자
// x_position =;
// DrawMan(x_position, (int) colour);
///////////////////////////////////
/// if (key=\'p\') p는 공을 던지도록 정해준 구문
printf(\" Press \'c\' button\\n\");
////////////////////////////////////////
}
//clean the screen
case \'c\':
if (key ==0)
key = getch();
if (key == \'c\')
{
cleardevice();
setbkcolor(BLACK);
DrawMan(x_position,(int) colour);
}
여기서 공을 던진 후 스틱맨이 움직이지 못하고 p를 눌러도 공을 다시 못던지게 만들고
오직 c 만 누르라고 메시지 뜨게 만들고 싶은데
생각하는게 저 위에 구문처럼
if(만약 77을 유저가 누르게 되면)
스틱맨은 움직이지 못하고
공을 던진 상태 그대로만 있는다
if(만약 75 을 유저가 누르게 되면)
스틱맨은 그상태를 유지하고
공을 던진 상태 그대로만 있는다
if(만약 p 을 유저가 누르게 되면)
스틱맨은 그상태를 유지하고
공을 던진 상태 그대로만 있는다
printf(\" Press \'c\' button\\n\");
(화면에 c버튼을 누르라고 보여준다)
이렇게 하려면 x_position 즉 스틱맨의 x값을 알아서 움직거리와 같다고만 지정해주면 될것 같은데
그 지금까지 움직인 x값을 알수가 없네...ㅠㅠ 그래서 p눌렀을때 공을 던지니까 거기서 나온 pos_x값을
이용해서 잡으려고 해도 쉽지 않아...
횽들 좀 알려줘 ㅠㅠ
길어서 패스 이런말만은 제발;;; ㅠㅠ
요약 : 스틱맨을 어떻게 못 움직이게 만들 수 있을까?
댓글 0