1) 지식 창고는 본인이 작성한 콘텐츠(팁/노하우/리소스/강좌 등)을 무료 혹은 가상화폐인 납포인트를 통해 공유하는 공간입니다.
2) 본인이 작성한 콘텐츠에 대해서만 지식 창고에 등록할 수 있으며, 저작권에 위배되는 콘텐츠는 사전경고 없이 삭제될 수 있습니다.
3) 콘텐츠 구매 및 첨부파일 다운로드는 회원그룹 '연구원' 이상 가능하오니, 경험치를 쌓아 진급한 후에 이용 부탁드립니다.
4) 무료 콘텐츠의 본문은 구매절차 없이 즉시 이용할 수 있으며, 판매 납포인트가 있는 콘텐츠는 구매 후 이용할 수 있습니다.
5) 콘텐츠 판매에 따른 납포인트 수익은 지정한 비율(50%)에 따라 판매자에게 지급하며, 납포인트 수익을 통해 진급을 빨리할 수 있습니다.
6) 구매 후 평가를 하면 구매 납포인트의 20%를 돌려 드립니다.
판매자 | 밍구리 | 판매 납포인트 | 무료 | 평점 | 0점 / 총 0명 참여 |
---|
Win32API 를 이용해서 갤러그 게임을 만들었습니다.
소스가 헤더파일하나와 cpp, 리소스 파일로만 이루어져 있어서
처음 게임프로그래밍 하시는분에게 많은 도움이 되었으면 좋겠습니다. ^^;
게임이 끝날때 ini파일로 저장하며
게임 시작시 ini파일을 읽어들여서 끝날 당시의 상태를 불러옵니다.
잘 구현하면 세이브/로드 기능이 되겠쬬 ^^
아무튼 많은 도움이 되시길 ~~ :)
작성툴 : Visual C++ 6
//galaga.cpp //버젼 정보 //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ☆━─ 08-08-08, 헤더파일 써주자 Alex. ─━☆ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ #include "defines.h" #include <math.h> #define PI 3.141592f
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ☆━─ 08-08-08, 전역변수 써주는 곳 Alex. ─━☆ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ HINSTANCE g_hInst; //전역 인스턴스의 핸들선언 char g_ClassName[128] = "Alex"; //클래스 이름 char g_WinName[128] = "공공의 적을 죽여보자!! -- 돌아온 갤러그 제작: 박민규 SPACE:총알 [S]:필살 좌우 : 좌우이동."; //윈도우 이름 HWND g_hWnd; //윈도우의 핸들 tagImage g_Image[IMG_END]; tagPlane g_Enemy[ENEMY_END]; tagBullet g_EnemyBullet[ENEMY_END][10];
//보통총알 tagBullet g_PlaneBullet[10]; tagBullet g_PlaneBullet2[10];
//필살기 tagBullet g_PlaneBullet3[10];
tagPlane g_Plane; RECT g_rcWnd; char g_szBuf[ENEMY_END+1][128]; //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ☆━─ 08-08-08, 함수의 프로토 타입 써주는 곳 Alex. ─━☆ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); void Output(HDC hdc); void Move(void); void SetUp(void); void Release(void); void Fire(void); void FireSpecial(void); void GetKey(void); //적이 총알을 발사(ENEMY형의 인자를 받음); //Timer에서 계속해서 실행 void EnemyFire(ENEMY nRand); void Collision(void);
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ☆━─ 08-08-08, 윈도우 메인 함수 Alex. ─━☆ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance ,LPSTR lpszCmdParam, int nCmdShow) { MSG Message; //메세지 구조체 선언 WNDCLASS WndClass; //윈도우 클래스 선언 g_hInst = hInstance; //인스턴스를 얻는다
WndClass.cbClsExtra = 0; //여분메모리 WndClass.cbWndExtra = 0; //여분메모리 WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //배경색상 지정 WndClass.hCursor = LoadCursor(NULL,IDC_ARROW); //커서를 읽는다 WndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION); //아이콘을 읽는다 WndClass.hInstance = hInstance; //윈도우 클래스의 인스턴스 WndClass.lpfnWndProc = (WNDPROC)WndProc; //윈도우 프로시저의 이름 WndClass.lpszClassName = g_ClassName; //윈도우 클래스의 이름 WndClass.lpszMenuName = NULL; //메뉴의 이름 WndClass.style = CS_HREDRAW | CS_VREDRAW; //윈도우의 스타일 RegisterClass(&WndClass); //클래스를 등록한다
//윈도우를 만든다 g_hWnd = CreateWindow(g_ClassName, g_WinName, WS_OVERLAPPEDWINDOW, 0, 0, WINSIZEX, WINSIZEY, NULL, (HMENU)NULL, hInstance, NULL); SetUp(); ShowWindow(g_hWnd, nCmdShow); /* while(true) { /// 메시지큐에 메시지가 있으면 메시지 처리 if( PeekMessage( &Message, NULL, 0U, 0U, PM_REMOVE ) ) { if(Message.message == WM_QUIT) break; TranslateMessage( &Message ); DispatchMessage( &Message ); } /// 처리할 메시지가 없으면 Render()함수 호출 // Render(); }*/
//메세지 루프 while(GetMessage(&Message,0,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } Release(); return Message.wParam; }
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ☆━─ 08-08-08, 윈도우 프로시저 Alex. ─━☆ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; SYSTEMTIME st; int i;
switch(iMessage) { case WM_CREATE:
break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); Output(hdc);
EndPaint(hWnd, &ps); break; case WM_TIMER: //시간을 얻는다. GetLocalTime(&st); for(i = 0 ; i < 10; i++) { EnemyFire((ENEMY)((st.wSecond+i) % ENEMY_END)); EnemyFire((ENEMY)((st.wSecond+i+3) % ENEMY_END)); } Move(); GetKey(); //키보드 입력 Collision(); //충돌처리 InvalidateRect(g_hWnd, NULL, false); break; case WM_KEYDOWN: switch(wParam) { case VK_ESCAPE: PostMessage( hWnd, WM_DESTROY, 0, 0L ); break; } break; case WM_DESTROY: PostQuitMessage(0); return 0; } return(DefWindowProc(hWnd,iMessage,wParam,lParam)); }
void Output(HDC hdc) { int i,j;
HBRUSH MyBrush, OldBrush;
BitBlt(g_Image[IMG_BACK].MemDC, 0, 0, WINSIZEX, WINSIZEY, g_Image[IMG_SPACE].MemDC, 0, 0, SRCCOPY);
//울편 비행기 찍는다 if(g_Plane.bDead == false) { TransparentBlt(g_Image[IMG_BACK].MemDC, g_Plane.rcPos.left, g_Plane.rcPos.top, g_Image[IMG_PLANE].nWidth, g_Image[IMG_PLANE].nHeight, g_Image[IMG_PLANE].MemDC, 0, 0, g_Image[IMG_PLANE].nWidth, g_Image[IMG_PLANE].nHeight, RGB(255, 0, 255)); }
//━━━━━적 비행기 출력 시작 //박경림 for(i = ENEMY_RECT1; i <= ENEMY_RECT3; i++) { if(g_Enemy[i].bDead == false) { BitBlt(g_Image[IMG_BACK].MemDC, g_Enemy[i].rcPos.left, g_Enemy[i].rcPos.top, g_Image[IMG_ENEMY2].nWidth, g_Image[IMG_ENEMY2].nHeight, g_Image[IMG_ENEMY2].MemDC, 0, 0, SRCCOPY); }
//경림 에너지 if( g_Enemy[i].nHP >= 0) { MyBrush = CreateSolidBrush(RGB(255,255,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Enemy[i].rcPos.left, g_Enemy[i].rcPos.top-10, g_Enemy[i].rcPos.right,g_Enemy[i].rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
MyBrush = CreateSolidBrush(RGB(255,0,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Enemy[i].rcPos.left, g_Enemy[i].rcPos.top-10, g_Enemy[i].rcPos.right - (g_Enemy[i].rcPos.right - g_Enemy[i].rcPos.left) *g_Enemy[i].nHP/500,g_Enemy[i].rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush); } } //소피 for(i = ENEMY_SOPI1; i <= ENEMY_SOPI5; i++) { if(g_Enemy[i].bDead == false) { BitBlt(g_Image[IMG_BACK].MemDC, g_Enemy[i].rcPos.left, g_Enemy[i].rcPos.top, g_Image[IMG_ENEMY1].nWidth, g_Image[IMG_ENEMY1].nHeight, g_Image[IMG_ENEMY1].MemDC, 0, 0, SRCCOPY); } //소피 에너지 if( g_Enemy[i].nHP >= 0) { MyBrush = CreateSolidBrush(RGB(255,255,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Enemy[i].rcPos.left, g_Enemy[i].rcPos.top-10, g_Enemy[i].rcPos.right,g_Enemy[i].rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
MyBrush = CreateSolidBrush(RGB(255,0,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Enemy[i].rcPos.left, g_Enemy[i].rcPos.top-10, g_Enemy[i].rcPos.right - (g_Enemy[i].rcPos.right - g_Enemy[i].rcPos.left) *g_Enemy[i].nHP/100,g_Enemy[i].rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush); } }
//전인권 if(g_Enemy[ENEMY_DRUG].bDead == false) { BitBlt(g_Image[IMG_BACK].MemDC, g_Enemy[ENEMY_DRUG].rcPos.left, g_Enemy[ENEMY_DRUG].rcPos.top, g_Image[IMG_ENEMY3].nWidth, g_Image[IMG_ENEMY3].nHeight, g_Image[IMG_ENEMY3].MemDC, 0, 0, SRCCOPY); }
//인권이 에너지 MyBrush = CreateSolidBrush(RGB(255,255,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Enemy[ENEMY_DRUG].rcPos.left, g_Enemy[ENEMY_DRUG].rcPos.top-10, g_Enemy[ENEMY_DRUG].rcPos.right,g_Enemy[ENEMY_DRUG].rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
MyBrush = CreateSolidBrush(RGB(255,0,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Enemy[ENEMY_DRUG].rcPos.left, g_Enemy[ENEMY_DRUG].rcPos.top-10, g_Enemy[ENEMY_DRUG].rcPos.right - (g_Enemy[ENEMY_DRUG].rcPos.right - g_Enemy[ENEMY_DRUG].rcPos.left) *g_Enemy[ENEMY_DRUG].nHP/1000,g_Enemy[ENEMY_DRUG].rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
//━━━━━적 비행기 출력끝. //적총알찍기. for(i = 0; i < ENEMY_END; i++) { for(j = 0; j <5; j++) { Ellipse(g_Image[IMG_BACK].MemDC , g_EnemyBullet[i][j].ptCenter.x - g_EnemyBullet[i][j].nRadius , g_EnemyBullet[i][j].ptCenter.y - g_EnemyBullet[i][j].nRadius , g_EnemyBullet[i][j].ptCenter.x + g_EnemyBullet[i][j].nRadius , g_EnemyBullet[i][j].ptCenter.y + g_EnemyBullet[i][j].nRadius);
if( i ==ENEMY_RECT1||i ==ENEMY_RECT2||i ==ENEMY_RECT3 ) { TransparentBlt(g_Image[IMG_BACK].MemDC , g_EnemyBullet[i][j].ptCenter.x - g_EnemyBullet[i][j].nRadius , g_EnemyBullet[i][j].ptCenter.y - g_EnemyBullet[i][j].nRadius , g_Image[IMG_ENEMY2].nWidth-80,g_Image[IMG_ENEMY2].nHeight-50 , g_Image[IMG_ENEMY2].MemDC, 0, 0 , g_Image[IMG_ENEMY2].nWidth, g_Image[IMG_ENEMY2].nHeight, RGB(255, 0, 255));
} else if( i == ENEMY_DRUG) { TransparentBlt(g_Image[IMG_BACK].MemDC , g_EnemyBullet[i][j].ptCenter.x - g_EnemyBullet[i][j].nRadius , g_EnemyBullet[i][j].ptCenter.y - g_EnemyBullet[i][j].nRadius , g_Image[IMG_ENEMY3].nWidth-100, g_Image[IMG_ENEMY3].nHeight-100 , g_Image[IMG_ENEMY3].MemDC, 0, 0 , g_Image[IMG_ENEMY3].nWidth, g_Image[IMG_ENEMY3].nHeight, RGB(255, 0, 255));
}
else { TransparentBlt(g_Image[IMG_BACK].MemDC , g_EnemyBullet[i][j].ptCenter.x - g_EnemyBullet[i][j].nRadius , g_EnemyBullet[i][j].ptCenter.y - g_EnemyBullet[i][j].nRadius , g_Image[IMG_ENEMY1].nWidth-50, g_Image[IMG_ENEMY1].nHeight-50 , g_Image[IMG_ENEMY1].MemDC, 0, 0 , g_Image[IMG_ENEMY1].nWidth, g_Image[IMG_ENEMY1].nHeight, RGB(255, 0, 255));
}
} }
//아군 총알 for(i = 0; i < 10; i++) { /* Ellipse(g_Image[IMG_BACK].MemDC , g_PlaneBullet[i].ptCenter.x - g_PlaneBullet[i].nRadius , g_PlaneBullet[i].ptCenter.y - g_PlaneBullet[i].nRadius , g_PlaneBullet[i].ptCenter.x + g_PlaneBullet[i].nRadius , g_PlaneBullet[i].ptCenter.y + g_PlaneBullet[i].nRadius);*/ TransparentBlt(g_Image[IMG_BACK].MemDC , g_PlaneBullet[i].ptCenter.x - g_PlaneBullet[i].nRadius , g_PlaneBullet[i].ptCenter.y - g_PlaneBullet[i].nRadius , g_Image[IMG_MISSILE1].nWidth, g_Image[IMG_MISSILE1].nHeight , g_Image[IMG_MISSILE1].MemDC, 0, 0 , g_Image[IMG_MISSILE1].nWidth, g_Image[IMG_MISSILE1].nHeight, RGB(255, 0, 255)); } //아군 총알2 for(i = 0; i < 10; i++) { /* Ellipse(g_Image[IMG_BACK].MemDC , g_PlaneBullet2[i].ptCenter.x - g_PlaneBullet[i].nRadius , g_PlaneBullet2[i].ptCenter.y - g_PlaneBullet2[i].nRadius , g_PlaneBullet2[i].ptCenter.x + g_PlaneBullet2[i].nRadius , g_PlaneBullet2[i].ptCenter.y + g_PlaneBullet2[i].nRadius);*/ TransparentBlt(g_Image[IMG_BACK].MemDC , g_PlaneBullet2[i].ptCenter.x - g_PlaneBullet2[i].nRadius , g_PlaneBullet2[i].ptCenter.y - g_PlaneBullet2[i].nRadius , g_Image[IMG_MISSILE1].nWidth, g_Image[IMG_MISSILE1].nHeight , g_Image[IMG_MISSILE1].MemDC, 0, 0 , g_Image[IMG_MISSILE1].nWidth, g_Image[IMG_MISSILE1].nHeight, RGB(255, 0, 255)); }
//아군 스페셜 총알 for(i = 0; i < 10; i++) { MyBrush = CreateHatchBrush(3,RGB(0,200,200)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Ellipse(g_Image[IMG_BACK].MemDC , g_PlaneBullet3[i].ptCenter.x - g_PlaneBullet3[i].nRadius , g_PlaneBullet3[i].ptCenter.y - g_PlaneBullet3[i].nRadius , g_PlaneBullet3[i].ptCenter.x + g_PlaneBullet3[i].nRadius , g_PlaneBullet3[i].ptCenter.y + g_PlaneBullet3[i].nRadius);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
}
//인터페이스 출력 /* for(i = 0 ; i < ENEMY_END ; i++) { wsprintf(g_szBuf[i], "에너지 : %d",g_Enemy[i].nHP); TextOut(g_Image[IMG_BACK].MemDC, g_Enemy[i].rcPos.left,g_Enemy[i].rcPos.top - 20,g_szBuf[i],strlen(g_szBuf[i]) ); }*/ // wsprintf(g_szBuf[ENEMY_END+1], "에너지 : %d마법 : %d",g_Plane.nHP,g_Plane.nMP); // TextOut(g_Image[IMG_BACK].MemDC, g_Plane.rcPos.left, g_Plane.rcPos.top - 30,g_szBuf[ENEMY_END+1],strlen(g_szBuf[ENEMY_END+1]) ); //플레이어 에너지 MyBrush = CreateSolidBrush(RGB(255,255,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Plane.rcPos.left, g_Plane.rcPos.top-10, g_Plane.rcPos.right,g_Plane.rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
MyBrush = CreateSolidBrush(RGB(255,0,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Plane.rcPos.left, g_Plane.rcPos.top-10, g_Plane.rcPos.right - (g_Plane.rcPos.right - g_Plane.rcPos.left) *g_Plane.nHP/1000,g_Plane.rcPos.top);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush); //플레이어 MP MyBrush = CreateSolidBrush(RGB(0,0,255)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Plane.rcPos.left, g_Plane.rcPos.top-20, g_Plane.rcPos.right,g_Plane.rcPos.top-10);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
MyBrush = CreateSolidBrush(RGB(255,0,0)); OldBrush = (HBRUSH) SelectObject(g_Image[IMG_BACK].MemDC, MyBrush);
Rectangle(g_Image[IMG_BACK].MemDC, g_Plane.rcPos.left, g_Plane.rcPos.top-20, g_Plane.rcPos.right - (g_Plane.rcPos.right - g_Plane.rcPos.left) *g_Plane.nMP/1000,g_Plane.rcPos.top-10);
SelectObject(g_Image[IMG_BACK].MemDC,OldBrush); DeleteObject(MyBrush);
//최종출력. BitBlt(hdc, 0, 0, WINSIZEX, WINSIZEY, g_Image[IMG_BACK].MemDC, 0, 0, SRCCOPY); }
void Move(void) {
SYSTEMTIME st; GetLocalTime(&st);
//인권이 움직이기.
int i,j; //━━━━━━━아군총알 움직이기 for(i =0 ; i < 10; i++) { if(g_PlaneBullet[i].bFired== false) continue; g_PlaneBullet[i].ptCenter.x += long(cosf(g_PlaneBullet[i].fAngle) * g_PlaneBullet[i].fSpeed); g_PlaneBullet[i].ptCenter.y += long(-sinf(g_PlaneBullet[i].fAngle) * g_PlaneBullet[i].fSpeed);
} //━━━━━━━아군총알 움직이기끝. //━━━━━━━아군총알2 움직이기 for(i =0 ; i < 10; i++) { if(g_PlaneBullet2[i].bFired== false) continue; g_PlaneBullet2[i].ptCenter.x += long(cosf(g_PlaneBullet2[i].fAngle) * g_PlaneBullet2[i].fSpeed); g_PlaneBullet2[i].ptCenter.y += long(-sinf(g_PlaneBullet2[i].fAngle) * g_PlaneBullet2[i].fSpeed);
} //━━━━━━━아군총알2 움직이기끝. //━━━━━━━스페셜 총알 움직이기 시작 for(i =0 ; i < 10; i++) { if(g_PlaneBullet3[i].bFired== false) continue; g_PlaneBullet3[i].fAngle = 0.5 + rand() % 3; g_PlaneBullet3[i].ptCenter.x += long(cosf(g_PlaneBullet3[i].fAngle) * g_PlaneBullet3[i].fSpeed); g_PlaneBullet3[i].ptCenter.y += long(-sinf(g_PlaneBullet3[i].fAngle) * g_PlaneBullet3[i].fSpeed);
} //━━━━━━━스페셜총알 움직이기끝.
//━━━━━━적 총알 움직이기 시작 for(i =0 ; i < ENEMY_END; i++) { for(j =0 ; j < 10; j++) { if(g_EnemyBullet[i][j].bFired== false) continue; g_EnemyBullet[i][j].ptCenter.x += long(cosf(g_EnemyBullet[i][j].fAngle) * g_EnemyBullet[i][j].fSpeed); g_EnemyBullet[i][j].ptCenter.y += long(-sinf(g_EnemyBullet[i][j].fAngle) * g_EnemyBullet[i][j].fSpeed); }
} //━━━━━━적 총알 움직이기 끝
//━━━━총알과 작업역영 처리시작 ━━━━━━━━━━━━━━━━━━━ for(i =0 ; i < ENEMY_END; i++) { for(j =0 ; j < 10; j++) { if(PtInRect(&g_rcWnd, g_EnemyBullet[i][j].ptCenter) == false) g_EnemyBullet[i][j].bFired = false; }
}
for(i =0 ; i < 10; i++) { if(PtInRect(&g_rcWnd, g_PlaneBullet[i].ptCenter) == false) { g_PlaneBullet[i].ptCenter.y -= 500; g_PlaneBullet[i].bFired = false; } } for(i =0 ; i < 10; i++) { if(PtInRect(&g_rcWnd, g_PlaneBullet2[i].ptCenter) == false) { g_PlaneBullet2[i].ptCenter.y -= 500; g_PlaneBullet2[i].bFired = false; } }
for(i =0 ; i < 10; i++) { if(PtInRect(&g_rcWnd, g_PlaneBullet3[i].ptCenter) == false) { g_PlaneBullet3[i].ptCenter.y -= 500; g_PlaneBullet3[i].bFired = false; } }
//━━━━총알과 작업역영 처리끝 ━━━━━━━━━━━━━━━━━━━
}
//적 총알 초기화(타이머에서 호출) void EnemyFire(ENEMY nRand) { if(g_Enemy[nRand].bDead == true) return; int i;
//적을 랜덤으로 설정 // int nRand = rand() % ENEMY_END; POINT ptPlane, ptEnemy;
//겟앵글 함수를 써주기 위해 RECT형을 POINT형으로 변환함 ptPlane.x = (g_Plane.rcPos.right - g_Plane.rcPos.left) /2 + g_Plane.rcPos.left; ptPlane.y = (g_Plane.rcPos.bottom - g_Plane.rcPos.top) /2 + g_Plane.rcPos.top; ptEnemy.x = (g_Enemy[nRand].rcPos.right - g_Enemy[nRand].rcPos.left) /2 + g_Enemy[nRand].rcPos.left; ptEnemy.y = (g_Enemy[nRand].rcPos.bottom - g_Enemy[nRand].rcPos.top) /2 + g_Enemy[nRand].rcPos.top; for(i =0 ; i < 10; i++) { if(g_EnemyBullet[nRand][i].bFired == true) continue; g_EnemyBullet[nRand][i].bFired = true; g_EnemyBullet[nRand][i].fAngle = GetAngle(ptEnemy, ptPlane); g_EnemyBullet[nRand][i].fSpeed = 3; g_EnemyBullet[nRand][i].ptCenter.x = ptEnemy.x; g_EnemyBullet[nRand][i].ptCenter.y = ptEnemy.y; g_EnemyBullet[nRand][i].nRadius = 5;
break; } }
//아군총알 초기화(SPACE누를시) void Fire(void) { int i;
POINT ptPlane; //겟앵글 함수를 써주기 위해 RECT형을 POINT형으로 변환함 ptPlane.x = (g_Plane.rcPos.right - g_Plane.rcPos.left) /2 + g_Plane.rcPos.left; ptPlane.y = (g_Plane.rcPos.bottom - g_Plane.rcPos.top) /2 + g_Plane.rcPos.top;
for(i =0 ; i < 10; i++) { if(g_PlaneBullet[i].bFired == true) continue; g_PlaneBullet[i].bFired = true; g_PlaneBullet[i].nRadius = 5; g_PlaneBullet[i].fAngle = PI / 2; g_PlaneBullet[i].fSpeed = 5; g_PlaneBullet[i].ptCenter.x = ptPlane.x-25; g_PlaneBullet[i].ptCenter.y = ptPlane.y;
break; }
for(i =0 ; i < 10; i++) { if(g_PlaneBullet2[i].bFired == true) continue; g_PlaneBullet2[i].bFired = true; g_PlaneBullet2[i].nRadius = 5; g_PlaneBullet2[i].fAngle = PI / 2; g_PlaneBullet2[i].fSpeed = 5; g_PlaneBullet2[i].ptCenter.x = ptPlane.x+25; g_PlaneBullet2[i].ptCenter.y = ptPlane.y;
break; }
}
void FireSpecial(void) { int i;
POINT ptPlane; //겟앵글 함수를 써주기 위해 RECT형을 POINT형으로 변환함 ptPlane.x = (g_Plane.rcPos.right - g_Plane.rcPos.left) /2 + g_Plane.rcPos.left; ptPlane.y = (g_Plane.rcPos.bottom - g_Plane.rcPos.top) /2 + g_Plane.rcPos.top;
for(i =0 ; i < 10; i++) { if(g_PlaneBullet3[i].bFired == true) continue; g_PlaneBullet3[i].bFired = true; g_PlaneBullet3[i].nRadius = 50; g_PlaneBullet3[i].fAngle = PI / 2; g_PlaneBullet3[i].fSpeed = 3; g_PlaneBullet3[i].ptCenter.x = ptPlane.x; g_PlaneBullet3[i].ptCenter.y = ptPlane.y;
break; }
} void SetUp(void) { HDC hdc; int i;
GetClientRect(g_hWnd, &g_rcWnd); hdc = GetDC(g_hWnd); for(i = 0; i < IMG_END; i++) { g_Image[i].MemDC = CreateCompatibleDC(hdc); g_Image[i].bit = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BACK) + i); g_Image[i].obit = (HBITMAP)SelectObject(g_Image[i].MemDC, g_Image[i].bit); } ReleaseDC(g_hWnd, hdc);
//이미지 관련크기 g_Image[IMG_PLANE].nWidth = 67, g_Image[IMG_PLANE].nHeight = 74; g_Image[IMG_ENEMY1].nWidth = 85; g_Image[IMG_ENEMY1].nHeight = 85; g_Image[IMG_ENEMY2].nWidth = 91, g_Image[IMG_ENEMY2].nHeight = 110; g_Image[IMG_ENEMY3].nWidth = 118, g_Image[IMG_ENEMY3].nHeight = 156;
g_Image[IMG_MISSILE1].nWidth = 24, g_Image[IMG_MISSILE1].nHeight = 73; g_Image[IMG_MISSILE2].nWidth = 24, g_Image[IMG_MISSILE1].nHeight = 73; g_Image[IMG_MISSILE3].nWidth = 24, g_Image[IMG_MISSILE1].nHeight = 25; g_Image[IMG_MISSILE4].nWidth = 24, g_Image[IMG_MISSILE1].nHeight = 25;
//비행기 관련 셋업
// INI 에서 불러 드릴수 있도록함. char szFileName[128]; GetCurrentDirectory(127, szFileName); strcat(szFileName, "\\Info.ini");
g_Plane.rcPos.left = GetPrivateProfileInt("플레이어1정보","left",0, szFileName); g_Plane.rcPos.top = GetPrivateProfileInt("플레이어1정보","top",0, szFileName); g_Plane.rcPos.right = g_Plane.rcPos.left + g_Image[IMG_PLANE].nWidth; g_Plane.rcPos.bottom = g_Plane.rcPos.top + g_Image[IMG_PLANE].nHeight; g_Plane.nHP = GetPrivateProfileInt("플레이어1정보","nHP",0, szFileName); g_Plane.nMP = GetPrivateProfileInt("플레이어1정보","nMP",0, szFileName); g_Plane.nSpeed = GetPrivateProfileInt("플레이어1정보","nSpeed",0, szFileName); /* INI에서 읽어들임. SetRect(&g_Plane.rcPos, 500, 650, 500 + g_Image[IMG_PLANE].nWidth, 650 + g_Image[IMG_PLANE].nHeight); g_Plane.nHP = 1000; g_Plane.nMP = 1000; g_Plane.nSpeed = 3;*/
//━━━━적 비행기 셋업 시작
//전인권 INI파일로 대체 g_Enemy[ENEMY_DRUG].rcPos.left = GetPrivateProfileInt("전인권정보","IG.left",0, szFileName); g_Enemy[ENEMY_DRUG].rcPos.top = GetPrivateProfileInt("전인권정보","IG.top",0, szFileName); g_Enemy[ENEMY_DRUG].rcPos.right = GetPrivateProfileInt("전인권정보","IG.right",0, szFileName); g_Enemy[ENEMY_DRUG].rcPos.bottom = GetPrivateProfileInt("전인권정보","IG.bottom",0, szFileName); g_Enemy[ENEMY_DRUG].nHP = GetPrivateProfileInt("전인권정보","IG.nHP",0, szFileName); /* SetRect(&g_Enemy[ENEMY_DRUG].rcPos, 450, 20, 450 + g_Image[IMG_ENEMY3].nWidth, 20 + g_Image[IMG_ENEMY3].nHeight); g_Enemy[ENEMY_DRUG].nHP = 1000;*/
for(i = ENEMY_RECT1; i <= ENEMY_RECT3; i++) { SetRect(&g_Enemy[i].rcPos, 150 + 300 * (i - ENEMY_RECT1), 200, 150 + g_Image[IMG_ENEMY2].nWidth + 300 * (i - ENEMY_RECT1), 200 + g_Image[IMG_ENEMY2].nHeight); g_Enemy[i].nHP = 500; }
for(i = ENEMY_SOPI1; i <= ENEMY_SOPI5; i++) { SetRect(&g_Enemy[i].rcPos, 200 + 150 * (i - ENEMY_SOPI1), 400, 200 + g_Image[IMG_ENEMY1].nWidth + 150 * (i - ENEMY_SOPI1), 400 + g_Image[IMG_ENEMY1].nHeight); g_Enemy[i].nHP = 100; } //━━━━적 비행기 셋업 끝.
SetTimer(g_hWnd, 0, 10, NULL); }
void Release(void) { int i;
for(i = 0; i < IMG_END; i++) { SelectObject(g_Image[i].MemDC, g_Image[i].obit); DeleteObject(g_Image[i].bit); DeleteDC(g_Image[i].MemDC);
}
KillTimer(g_hWnd, 0);
/*/ INI 에서 불러 드릴수 있도록함. SetRect(&g_Plane.rcPos, 500, 650, 500 + g_Image[IMG_PLANE].nWidth, 650 + g_Image[IMG_PLANE].nHeight); g_Plane.nHP = 1000; g_Plane.nMP = 1000; g_Plane.nSpeed = 3;*/
char szFileName[128]; GetCurrentDirectory(127, szFileName); strcat(szFileName, "\\Info.ini");
char szBuf[128];
//플레이어 정보 INI에 저장 itoa(g_Plane.rcPos.left, szBuf, 10); WritePrivateProfileString("플레이어1정보","left",szBuf,szFileName); itoa(g_Plane.rcPos.top, szBuf, 10); WritePrivateProfileString("플레이어1정보","top",szBuf,szFileName); itoa(g_Plane.rcPos.right, szBuf, 10); WritePrivateProfileString("플레이어1정보","right",szBuf,szFileName); itoa(g_Plane.rcPos.bottom, szBuf, 10); WritePrivateProfileString("플레이어1정보","bottom",szBuf,szFileName); itoa(g_Plane.nHP, szBuf, 10); WritePrivateProfileString("플레이어1정보","nHP",szBuf,szFileName); itoa(g_Plane.nMP, szBuf, 10); WritePrivateProfileString("플레이어1정보","nMP",szBuf,szFileName); itoa(g_Plane.nSpeed, szBuf, 10); WritePrivateProfileString("플레이어1정보","nSpeed",szBuf,szFileName);
//인권이 정보 INI에 저장 //g_Enemy[ENEMY_DRUG].rcPos.left = GetPrivateProfileInt("전인권정보","인권.left",0, szFileName); itoa(g_Enemy[ENEMY_DRUG].rcPos.left, szBuf, 10); WritePrivateProfileString("전인권정보","IG.left",szBuf,szFileName); itoa(g_Enemy[ENEMY_DRUG].rcPos.top, szBuf, 10); WritePrivateProfileString("전인권정보","IG.top",szBuf,szFileName); itoa(g_Enemy[ENEMY_DRUG].rcPos.right, szBuf, 10); WritePrivateProfileString("전인권정보","IG.right",szBuf,szFileName); itoa(g_Enemy[ENEMY_DRUG].rcPos.bottom, szBuf, 10); WritePrivateProfileString("전인권정보","IG.bottom",szBuf,szFileName); itoa(g_Enemy[ENEMY_DRUG].nHP, szBuf, 10); WritePrivateProfileString("전인권정보","IG.nHP",szBuf,szFileName);
}
//두점 사이의 앵글 구하기 float GetAngle(POINT ptPivot, POINT ptGuest) {
int nWidth, nHeight; float fHypotenuse; float fAngle;
nWidth = ptGuest.x - ptPivot.x; nHeight = ptGuest.y - ptPivot.y; fHypotenuse = float(sqrt((float)(nWidth * nWidth + nHeight * nHeight)));
fAngle = acosf(nWidth / fHypotenuse);
if(ptGuest.y > ptPivot.y) { fAngle = 2 * PI - fAngle; }
return fAngle;
}
void Collision(void) {
int i,j;
//적총알과 아군 충돌
for(i=0; i < ENEMY_END; i++) { for(j=0; j < 10; j++) { if(PtInRect(&g_Plane.rcPos, g_EnemyBullet[i][j].ptCenter) && g_EnemyBullet[i][j].bFired==true && g_Plane.bDead == false) { g_EnemyBullet[i][j].ptCenter.y += 500; g_EnemyBullet[i][j].bFired = false; g_Plane.nHP--;
//죽음 처리 if(g_Plane.nHP <= 0) g_Plane.bDead = true; } } }
//아군 총알과 적 충돌 for(i=0; i < ENEMY_END; i++) { for(j=0; j < 10; j++) { if(PtInRect(&g_Enemy[i].rcPos, g_PlaneBullet[j].ptCenter) && g_PlaneBullet[j].bFired==true && g_Enemy[i].bDead == false) {
g_PlaneBullet[j].ptCenter.y -= 500; g_PlaneBullet[j].bFired = false; g_Enemy[i].nHP--; //죽음 처리 if( g_Enemy[i].nHP <= 0) g_Enemy[i].bDead = true;
} } } for(i=0; i < ENEMY_END; i++) { for(j=0; j < 10; j++) { if(PtInRect(&g_Enemy[i].rcPos, g_PlaneBullet2[j].ptCenter) && g_PlaneBullet2[j].bFired==true && g_Enemy[i].bDead == false) { g_PlaneBullet2[j].ptCenter.y -= 500; g_PlaneBullet2[j].bFired = false; g_Enemy[i].nHP--; //죽음 처리 if( g_Enemy[i].nHP <= 0) g_Enemy[i].bDead = true;
} } }
//초필살 for(i=0; i < ENEMY_END; i++) { for(j=0; j < 10; j++) { if(PtInRect(&g_Enemy[i].rcPos, g_PlaneBullet3[j].ptCenter) && g_PlaneBullet3[j].bFired==true && g_Enemy[i].bDead == false) {
g_Enemy[i].nHP--; //죽음 처리 if( g_Enemy[i].nHP <= 0) g_Enemy[i].bDead = true;
} } }
}
//두점 사이 거리 구하기.
float GetDistance(POINT ptPivot, POINT ptGuest) { float fDistance = (float)sqrt(float( int(ptPivot.x - ptGuest.x)*int(ptPivot.x - ptGuest.x) + int(ptPivot.y - ptGuest.y)*int(ptPivot.y - ptGuest.y) )); return fDistance;
}
void GetKey(void) { static bool bFire[2]={false};
if(GetKeyState(VK_LEFT) & 0x8000) { OffsetRect(&g_Plane.rcPos, -g_Plane.nSpeed, 0);
if(g_Plane.rcPos.left < 0) { OffsetRect(&g_Plane.rcPos, -g_Plane.rcPos.left, 0); } } if(GetKeyState(VK_RIGHT) & 0x8000) { OffsetRect(&g_Plane.rcPos, g_Plane.nSpeed, 0);
if(g_Plane.rcPos.right > WINSIZEX) { OffsetRect(&g_Plane.rcPos, -(g_Plane.rcPos.right - WINSIZEX), 0); } } //총 쏘기. if(GetKeyState(VK_SPACE) & 0x8000) { bFire[0] = true; } else if(bFire[0] ==true) { Fire(); bFire[0] = false;
}
//필살기 쏘기 if(GetKeyState('S') & 0x8000) { if(g_Plane.nMP >=0) bFire[1] = true; } else if(bFire[1] ==true) { FireSpecial(); g_Plane.nMP -= 10; bFire[1] = false;
} }
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // ☆━─ 08-08-08, 참고사항들 Alex. ─━☆ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//defines.h #include <windows.h> //윈도우 헤더파일을 인크루드 #include "resource.h"
#define WINSIZEX 1024 #define WINSIZEY 768
enum IMAGE {IMG_BACK, IMG_SPACE, IMG_PLANE, IMG_ENEMY1, IMG_ENEMY2, IMG_ENEMY3, IMG_MISSILE1, IMG_MISSILE2, IMG_MISSILE3, IMG_MISSILE4, IMG_END};
enum ENEMY {ENEMY_SOPI1, ENEMY_SOPI2, ENEMY_SOPI3, ENEMY_SOPI4, ENEMY_SOPI5, ENEMY_RECT1, ENEMY_RECT2, ENEMY_RECT3, ENEMY_DRUG, ENEMY_END};
struct tagBullet { bool bFired; float fAngle; int nRadius; float fSpeed; POINT ptCenter; };
struct tagImage { HDC MemDC; HBITMAP bit, obit; int nWidth, nHeight; };
struct tagPlane { RECT rcPos; int nHP; int nMP; int nSpeed; bool bDead; };
float GetAngle(POINT ptPivot, POINT ptGuest); float GetDistance(POINT ptPivot, POINT ptGuest);