#include\"resource.h\"
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,
       HINSTANCE hPrevInstance,
       LPSTR IpCmdLine,
       int nShowCmd)
{
 HWND hWnd;
 MSG mSg;

 char szTitle[]=\"원의 충돌체크 하면서 충돌하는 프로그램\";
 char szClass[]=\"Class\";

 WNDCLASSEX WndEx;

 WndEx.cbSize=sizeof(WndEx);
 WndEx.style=NULL;
 WndEx.lpfnWndProc=WndProc;
 WndEx.cbClsExtra=0;
 WndEx.cbWndExtra=0;
 WndEx.hInstance=hInstance;
 WndEx.hIcon=LoadIcon(NULL,\"IDI_ICON\");
 WndEx.hCursor=LoadCursor(NULL,IDC_ARROW);
 WndEx.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
 WndEx.lpszMenuName=NULL;
 WndEx.lpszClassName=szClass;
 WndEx.hIconSm=LoadIcon(hInstance,\"IDI_ICON\");

 RegisterClassEx(&WndEx);

 hWnd=CreateWindowEx(NULL,
  szClass,
  szTitle,
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  640,
  480,
  NULL,
  NULL,
  hInstance,
  NULL);

 ShowWindow(hWnd,nShowCmd);
 UpdateWindow(hWnd);

 while(TRUE)//메세지는 여기서 만들어짐
 {
  if(PeekMessage(&mSg,NULL,0,0,PM_NOREMOVE))
  {
   if(!GetMessage(&mSg,NULL,0,0))
    break;
   TranslateMessage(&mSg);
   DispatchMessage(&mSg);
  }
 }
 return mSg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,
       UINT uMsg,
       WPARAM wParam,
       LPARAM IParam)

{
 HDC hDC;
 PAINTSTRUCT pS;

 char szText[100],szText2[100],szText3[100],szText4[100];
 HPEN hPen;
 
 static int nX1=0,nY1=0,nX2=40,nY2=40,mX1=40,mY1=0,mX2=60,mY2=20;
 static int nSwX=+10,nSwY=+10,mSwX=+10,mSwY=+10;//속도값 변경시켜주는 곳
 


 
 switch(uMsg)
 {
 case WM_KEYDOWN:
  if(LOWORD(wParam)==VK_RETURN)
  SetTimer(hWnd,1,100,NULL);

  if(LOWORD(wParam)==VK_SPACE)
   KillTimer(hWnd,1);
  
  return FALSE;

 case WM_TIMER:
   hDC=GetDC(hWnd);

   InvalidateRect(hWnd,NULL,TRUE);
   UpdateWindow(hWnd);

   sprintf(szText,\"nX1:%d,nY1:%d,nX2:%d,nY2:%d\",nX1,nX2,nY1,nY2);
   TextOut(hDC,5,5,szText,lstrlen(szText));
   sprintf(szText2,\"nSwX:%d,nSwY:%d\",nSwX,nSwY);
   TextOut(hDC,5,20,szText2,lstrlen(szText2));
   
   sprintf(szText3,\"mX1:%d,mY1:%d,mX2:%d,mY2:%d\",mX1,mX2,mY1,mY2);
   TextOut(hDC,10,20,szText3,lstrlen(szText3));
   sprintf(szText4,\"mSwX:%d,mSwY:%d\",mSwX,mSwY);
   TextOut(hDC,20,40,szText4,lstrlen(szText4));

   nX1+=nSwX;
   nX2+=nSwX;
   mX1+=mSwX;
   mX2+=mSwX;
   
  
  int check(int nX1,int nY1,int nX2,int nY2,int mX1,int mX2,int mY1,int mY2)
 {
  if(nY2<mY1)
   return 0;
  if(nY1>mY2)
   return 0;
  if(nX2<mX1)
   return 0;
  if(nX1>mX2)
   return 0;

  return 1;
 }

 


   if(nX1<0)
   {
    nX1=0;
    nX2=40;
    nSwX=-nSwX;
   }
   if(nX2>640)
   {
    nX1=640-1-40;
    nX2=640-1;
    nSwX=-nSwX;
   }
   nY1+=nSwY;
   nY2+=nSwY;
   if(nY1<0)
   {
    nY1=0;
    nY2=40;
    nSwY=-nSwY;
   }
   if(nY2>=480)
   {
    nY1=480-1-40;
    nY2=480-1;
    nSwY=-nSwY;
   }
   if(mX1<0)
   {
    mX1=0;
    mX2=40;
    mSwX=-mSwX;
   }
   if(mX2>640)
   {
    mX1=640-1-40;
    mX2=640-1;
    mSwX=-mSwX;
   }
   mY1+=mSwY;
   mY2+=mSwY;
   if(mY1<0)
   {
    mY1=0;
    mY2=40;
    mSwY=-mSwY;
   }
   if(mY2>=480)
   {
    mY1=480-1-40;
    mY2=480-1;
    mSwY=-mSwY;
   }
  
 
   return FALSE;
   


 

 case WM_PAINT:
  hDC=BeginPaint(hWnd,&pS);
  hPen=CreatePen(PS_SOLID,2,RGB(255,0,0));
  SelectObject(hDC,hPen);
  Ellipse(hDC,nX1,nY1,nX2,nY2);
  Ellipse(hDC,mX1,mY1,mX2,mY2);
  EndPaint(hWnd,&pS);
  return FALSE;
 
   
 case WM_DESTROY:
  KillTimer(hWnd,1); 
  PostQuitMessage(0);
  return FALSE;
 }
 return DefWindowProc(hWnd,uMsg,wParam,IParam);
}

 



이거 원의 자유 운동인데

int check(int nX1,int nY1,int nX2,int nY2,int mX1,int mX2,int mY1,int mY2)
 {
  if(nY2<mY1)
   return 0;
  if(nY1>mY2)
   return 0;
  if(nX2<mX1)
   return 0;
  if(nX1>mX2)
   return 0;

  return 1;
 }
나 이함수를 넣어서 원끼리 충돌 일으켜서 움직이는거 하고 싶은데 선언하는곳에다가 넣으면 지역함수 오류 뜨는데 이거 어떻게 해야되나요 형들 ㅠㅠ