1 / 13

벽치기 게임

벽치기 게임. 경기장 구성. CPoint s. int b_pos. Symbol 및 전역변수 정의. 프로그램에 사용된 변수들. #define BAR_HEIGHT 100 #define BAR_WIDTH 30 #define BALL_SIZE 30 CPoint s; // 볼의 위치 CPoint inc; // 볼의 위치 변화량 int b_pos = 0; // bar 의 위치 BOOL is_moving = FALSE; // 게임중인가 ?. 볼의 움직임.

amir-hewitt
Télécharger la présentation

벽치기 게임

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 벽치기 게임 • 경기장 구성 CPoint s int b_pos

  2. Symbol 및 전역변수 정의 • 프로그램에 사용된 변수들 #define BAR_HEIGHT 100 #define BAR_WIDTH 30 #define BALL_SIZE 30 CPoint s; // 볼의 위치 CPoint inc; // 볼의 위치 변화량 int b_pos = 0; // bar의 위치 BOOL is_moving = FALSE; // 게임중인가?

  3. 볼의 움직임 • 볼의 움직임 : 볼이 어떻게 움직이는가? • Timer의 사용 • Timer를 사용하여 볼을 움직임 • 왼쪽 마우스를 click 하면 볼이 움직이기 시작함. s.x = 10; s.y = 10; inc.x = 10; inc.y = 5; s = s + inc; // s.x = s.x + inc.x; s.y = s.y + inc.y Invalidate();

  4. 볼이 벽에 부딪혔을 때 반사 • 반사는 어떻게? 3 1 1 2 4

  5. 볼이 벽에 부딪혔을 때 반사 • 반사는 어떻게? s = s + inc; if ( ___________________ ) { // 왼쪽벽에 부딪혔을 때 __________________; __________________; } 1

  6. 볼의 움직임 시작 및 중단 • OnLButtonDown void CLecture211View::OnLButtonDown(UINT nFlags, CPoint point) { if ( is_moving ) { KillTimer(0); is_moving = FALSE; } else { inc.x = 30; inc.y = (rand() % 21) - 10; s.x = 0; s.y = rand() % 300; SetTimer(0,50,NULL); // 50 ms마다 WM_TIMER 메시지 발생 is_moving = TRUE; } CView::OnLButtonDown(nFlags, point); }

  7. OnTimer 함수 • OnTimer 함수 1 void CLecture211View::OnTimer(UINT nIDEvent) { CRect rect; GetClientRect(&rect); s = s + inc; if ( s.x < 0 ) { s.x = -s.x; inc.x = -inc.x; } if ( s.y + BALL_SIZE > rect.Height() ) { s.y = rect.Height() - BALL_SIZE - (s.y - rect.Height() + BALL_SIZE); inc.y = -inc.y; } 1 4

  8. OnTimer 함수 • OnTimer 함수 2 if ( s.y < 0 ) { s.y = -s.y; inc.y = -inc.y; } if ( s.x + BALL_SIZE > rect.Width() - 100 ) { … } Invalidate(); } 3 2

  9. bat 에 맞았을 경우 • 배트에 맞았을 경우  게임을 조금 재미 있게 하기 위해서 변화를 줌 inc.x = -inc.x; 1 1 inc.y = -inc.y inc.y = inc.y - 5; if ( inc.y > 0 ) inc.y = inc.y - 1; else if ( inc.y < 0 ) inc.y = inc.y + 1; inc.y = inc.y + 5; inc.y = -inc.y; 2 2 3 3 4 4 5 5 inc.x = -inc.x;

  10. OnDraw 함수 void CLecture211View::OnDraw(CDC* pDC) { CLecture211Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CBrush brush1, brush2, *pOldBrush; CRect rect; GetClientRect(&rect); brush1.CreateSolidBrush(RGB(255,0,0)); pOldBrush = (CBrush *) pDC->SelectObject(&brush1); if ( is_moving ) pDC->Ellipse(s.x,s.y,s.x+29,s.y+29); brush2.CreateSolidBrush(RGB(0,0,255)); pDC->SelectObject(&brush2); pDC->Rectangle(rect.Width() - 100, b_pos, rect.Width() - 100 + 30, b_pos + 100); pDC->SelectObject(pOldBrush); }

  11. OnMouseMove 함수 void CLecture211View::OnMouseMove(UINT nFlags, CPoint point) { CClientDC dc(this); CBrush brush1, brush2, *pOldBrush; CRect rect; GetClientRect(&rect); b_pos = point.y; if ( b_pos + 100 > rect.Height() ) b_pos = rect.Height() - 100; CView::OnMouseMove(nFlags, point); }

  12. Key board로 조작하기 위한 routine • Key를 누르면 WM_KEYDOWN 이 발생함 void CLecture211View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CRect rect; GetClientRect(&rect); if ( nChar == VK_DOWN ) { b_pos = b_pos + 30; if ( b_pos + 100 > rect.Height() ) b_pos = rect.Height() - 100; } else if ( nChar == VK_UP ) { b_pos = b_pos - 30; if ( b_pos < 0 ) b_pos = 0; } CView::OnKeyDown(nChar, nRepCnt, nFlags); }

  13. Term Project • Term Project 발표 12월 9일 • Powerpoint 자료를 만들어 올 것 • 추가한 기능 등을 발표 • 프로그램의 동작 시연 • 시간은 1인당 3분 이내 • 제출할 것 • powerpoint 자료 출력한 것 • 프로그램의 핵심 부분의 출력 및 간단한 설명

More Related