void MakeRoom(struct Room rs[100], int *lenrs,uint32_t *gen){ int x = GenRand(gen) % TileDim; int y = GenRand(gen) % TileDim; int w = GenRand(gen) % RestWidMax+WidMin; int h = GenRand(gen) % RestWidMax+WidMin; if(x+w>=TileDim || y+h>=TileDim || x==0 || y==0) return; int nocrash = CheckColl(x,y,w,h,rs,*lenrs); if (nocrash==0){ struct Room r; r.X = x; r.Y = y; r.W = w; r.H = h; r.N = *lenrs; rs[*lenrs]=r; *lenrs = *lenrs+1; } }
//-------------------------------------------------------------------------------------- // Render a frame //-------------------------------------------------------------------------------------- void Render() { // Update our time static float t = 0.0f; float delta_t = 0.0f; { static DWORD dwTimeStart = 0; DWORD dwTimeCur = GetTickCount(); if( dwTimeStart == 0 ) dwTimeStart = dwTimeCur; float old_t = t; t = ( dwTimeCur - dwTimeStart ) / 1000.0f; delta_t = t-old_t; } { sphParticle particles[32]; for(size_t i=0; i<_countof(particles); ++i) { particles[i].position = ist::simdvec4_set(GenRand()*0.5f, GenRand()*0.5f, GenRand()*0.5f-7.5f, 1.0f); particles[i].velocity = _mm_set1_ps(0.0f); } g_sphgrid.addParticles(particles, _countof(particles)); } { static PerformanceCounter s_timer; static float s_prev = 0.0f; PerformanceCounter timer; g_sphgrid.update(1.0f); g_pImmediateContext->UpdateSubresource( g_pCubeInstanceBuffer, 0, NULL, &g_sphgrid.particles, 0, 0 ); if(s_timer.getElapsedMillisecond() - s_prev > 1000.0f) { char buf[128]; _snprintf(buf, _countof(buf), " SPH update: %d particles %.3fms\n", g_sphgrid.num_active_particles, timer.getElapsedMillisecond()); OutputDebugStringA(buf); ::SetWindowTextA(g_hWnd, buf); s_prev = s_timer.getElapsedMillisecond(); } } { CBChangesEveryFrame cb; XMVECTOR eye = g_camera.getEye(); { XMMATRIX rot = XMMatrixRotationZ(XMConvertToRadians(0.1f)); eye = XMVector4Transform(eye, rot); } g_camera.setEye(eye); g_camera.updateMatrix(); XMMATRIX vp = g_camera.getViewProjectionMatrix(); cb.ViewProjection = XMMatrixTranspose( vp ); cb.CameraPos = (FLOAT*)&eye; cb.LightPos = XMFLOAT4(10.0f, 10.0f, -10.0f, 1.0f); cb.LightColor = XMFLOAT4(0.9f, 0.9f, 0.9f, 1.0f); cb.MeshShininess = 200.0f; g_pImmediateContext->UpdateSubresource( g_pCBChangesEveryFrame, 0, NULL, &cb, 0, 0 ); } float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; // red, green, blue, alpha g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor ); g_pImmediateContext->ClearDepthStencilView( g_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 ); { ID3D11Buffer *buffers[] = {g_pCubeVertexBuffer, g_pCubeInstanceBuffer}; UINT strides[] = {sizeof(SimpleVertex), sizeof(sphParticle), }; UINT offsets[] = {0, 0}; g_pImmediateContext->IASetVertexBuffers( 0, ARRAYSIZE(buffers), buffers, strides, offsets ); } g_pImmediateContext->IASetInputLayout( g_pCubeVertexLayout ); g_pImmediateContext->IASetIndexBuffer( g_pCubeIndexBuffer, DXGI_FORMAT_R16_UINT, 0 ); g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); // Render the cube g_pImmediateContext->VSSetShader( g_pCubeVertexShader, NULL, 0 ); g_pImmediateContext->VSSetConstantBuffers( 0, 1, &g_pCBChangesEveryFrame ); g_pImmediateContext->PSSetShader( g_pCubePixelShader, NULL, 0 ); g_pImmediateContext->PSSetConstantBuffers( 0, 1, &g_pCBChangesEveryFrame ); g_pImmediateContext->DrawIndexedInstanced( 36, (UINT)g_sphgrid.num_active_particles, 0, 0, 0 ); // Present our back buffer to our front buffer g_pSwapChain->Present( 1, 0 ); // vsync on //g_pSwapChain->Present( 0, 0 ); // vsync off }
int WINAPI WinMain(HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows message Structure bool done = false; if (MessageBox(NULL, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO) { fullscreen = false; // Windowed Mode } // Create Our OpenGL Window if (!CreateGLWindow("pokemon", 640, 480, 16, fullscreen)) { return 0; // Quit If Window Was Not Created } arrow.Init(20, 20); player.Init(20, 20, 0); Timer = Timer.TimerInit(); // 음악 로딩 for (loop1 = 0; loop1 < NUM_BGM; loop1++) { BGM[loop1] = LoadMP3(hWnd, path_BGM[loop1]); } BGM[0] = mciSendCommand(1, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); CountLoop = 0; while (!done) // Loop That Runs While done=FALSE { TranslateMessage(&msg); DispatchMessage(&msg); // Is There A Message Waiting? if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) // Have We Received A Quit Message? { done = true; } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { float start = Timer.TimerGetTime(); // Grab Timer Value Before We Draw // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene() if ((!DrawGLScene() && active) || keys[VK_ESCAPE]) // Active? Was There A Quit Received? { done = true; // ESC or DrawGLScene Signalled A Quit } else // Not Time To Quit, Update Screen { SwapBuffers(hDC); // Swap Buffers (Double Buffering) } while (Timer.TimerGetTime() < start + float(steps[adjust] * GAMESPEED * 1.0f)) {} // Waste Cycles On Fast Systems if (keys[VK_F1]) // Is F1 Being Pressed? { keys[VK_F1] = false; // If So Make Key FALSE KillGLWindow(); // Kill Our Current Window fullscreen = !fullscreen; // Toggle Fullscreen / Windowed Mode // Recreate Our OpenGL Window if (!CreateGLWindow("pokemon", 640, 480, 16, fullscreen)) { return 0; // Quit If Window Was Not Created } } if (active) // If Programs Active Move Objects { if (interrupt) { // 인트로로 인한 게임 정지 if (intro) { Map.map_number = animation; // 추가 입력 받으면 게임 시작 if (CountLoop > LENGTH && keys['Z']) { mciSendCommand(1, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(4, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); nowplaying = 4; interrupt = false; intro = false; // 게임 셋팅 Map.IsMap = true; Map.Loading_Map(map_DB[2]); //211033 player.SetObjects(11, 4); Map.map_number = 2; animation = 0; CountLoop = LENGTH; } if (CountLoop % LENGTH == 0) { animation++; animation = animation % 6; } CountLoop += steps[adjust]; } // 메뉴 켜서 게임 정지 if (isMenuOn) { if (keys['X']) { keys['X'] = 0; isMenuOn = false; interrupt = false; Map.Loading_Map(map_DB[Map.map_number]); CountLoop = LENGTH; arrow.SetObjects(20, 20); player.SetObjects(player.x, player.y); } else { arrow.MovementByKeyInput(VK_LEFT); arrow.MovementByKeyInput(VK_UP); arrow.MovementByKeyInput(VK_RIGHT); arrow.MovementByKeyInput(VK_DOWN); arrow.SetObjects(arrow.x, arrow.y); } } // Yes No if (YesNo) { if (keys['X']) { keys['X'] = 0; YesNo = false; Answer = 1; player.SetObjects(player.x, player.y); Map.Loading_Map(map_DB[Map.map_number]); CountLoop = LENGTH; } if (keys['Z']) { keys['Z'] = 0; YesNo = false; Answer = arrow.x - 12 + arrow.y - 5; arrow.SetObjects(20, 20); player.SetObjects(player.x, player.y); Map.Loading_Map(map_DB[Map.map_number]); CountLoop = LENGTH; } else { arrow.MovementByKeyInput(VK_LEFT); arrow.MovementByKeyInput(VK_UP); arrow.MovementByKeyInput(VK_RIGHT); arrow.MovementByKeyInput(VK_DOWN); arrow.SetObjects(arrow.x, arrow.y); } } // 대화 interrupt if (!battle && Talk) { if (wait == 0) { if (keys['Z']) { keys['Z'] = 0; if (CurrentNPC.GetLink() == 5) // 엔딩용 링크 { mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = 15; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } if (CurrentNPC.GetLink() == 4) { pika.Heal(); mciSendCommand(11, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); mciSendCommand(11, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); } if (CurrentNPC.GetLink() == 3) { gugu = War.selectPoke(CurrentNPC.GetLevel(), CurrentNPC.GetSelect()); addExp = pika.getAddExp() - 3 * (pika.getLevel() - gugu->getLevel()); //적 레벨에 내 레벨을 뺀후 곱하기 3의 경험치 패널티 if (addExp <= 0) addExp = 1; interrupt = battle = true; CurrentBattlePoke = CurrentNPC.GetSelect(); if (Map.map_number == 8) { // 로켓단 보스들과의 브금. mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = 13; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } else { mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = 6; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY| MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } OK = false; BattleTalk = 1; arrow.SetObjects(9, 8); Map.Loading_Map(list_DB[0]); } else if (CurrentNPC.GetLink() == 2) { if (!YesNo && Answer == -1) { YesNo = true; arrow.SetObjects(12, 5); X_Answer = 12; Y_Answer = 5; Map.Loading_Map(list_DB[0]); } else if (Answer != -1) { if (Answer == 0) { CurrentNPC.SetYesNext(); Answer = -1; } else if (Answer == 1) { CurrentNPC.SetNoNext(); Answer = -1; } } } else { interrupt = Talk = CurrentNPC.GetLink(); CurrentNPC.SetYesNext(); } } } else if ((CountLoop % LENGTH == 0) && (wait > 0)) { wait--; } else { CountLoop += steps[adjust]; } } // 배틀 if (OK && battle && ((BattleTalk == 2) || (BattleTalk == 3))) { // 후공은 자동 if (BattleTalk == 3) { RamdomSkill = GenRand(1, 2); War.opponentTurn(&pika, gugu, RamdomSkill); OK = false; Answer = -1; } // X 선택시 스킬 창이면 스킬창 끔 else if (keys['X']) { keys['X'] = 0; if (!skill) { interrupt = battle = false; arrow.SetObjects(20, 20); player.SetObjects(player.x, player.y); Map.Loading_Map(map_DB[Map.map_number]); CountLoop = LENGTH; } else if (skill) { skill = false; arrow.SetObjects(9, 8); } } /* 선택. * -3 : 스킬 1번, -2 : 스킬 2번 * 0 : 싸운다 3 : x * 1 : x 4 : 도망가다 */ else if (keys['Z']) { keys['Z'] = 0; Answer = arrow.x - 9 + arrow.y - 8; if (OK && (Answer == -3 || Answer == -2)) { // 스킬 선택 했으면 if (BattleTalk == 2) { mciSendCommand(8, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); mciSendCommand(8, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); skill = false; War.playerTurn(&pika, gugu, Answer + 3); OK = false; } } // 싸운다 else if (Answer == 0) { skill = true; arrow.SetObjects(7, 7); CountLoop = LENGTH; } // 도망간다 else if (Answer == 4) { interrupt = battle = BattleTalk = OK = false; arrow.SetObjects(20, 20); player.SetObjects(player.x, player.y); Map.Loading_Map(map_DB[Map.map_number]); CountLoop = LENGTH; Answer = -1; } } else { arrow.MovementByKeyInput(VK_LEFT); arrow.MovementByKeyInput(VK_UP); arrow.MovementByKeyInput(VK_RIGHT); arrow.MovementByKeyInput(VK_DOWN); arrow.SetObjects(arrow.x, arrow.y); } } if (BattleTalk && !OK) { if (keys['X'] || keys['Z']) { keys['X'] = keys['Z'] = false; if (BattleTalk == 1) { OK = true; BattleTalk++; } else if (BattleTalk == 2) { OK = true; BattleTalk++; if (0 >= gugu->getVital()) { BattleTalk = 4; OK = false; } else { mciSendCommand(8, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); mciSendCommand(8, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); } } else if (BattleTalk == 3) { if(0 >= pika.getVital()) { BattleTalk = 7; gameover = true; } else { OK = true; BattleTalk--; } arrow.SetObjects(9, 8); } else if (BattleTalk == 4) { pika.ExpUp(gugu->getLevel()); OK = false; BattleTalk = 5; if (nowplaying == 9) { // 야생 포켓몬 브금이라면? 와일드 포켓몬 승리 재생 mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = 10; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } else { // 트레이너 배틀 브금이라면? 트레이너 배틀 승리 재생 mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = 7; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } } else if (BattleTalk == 5) { OK = false; BattleTalk = 6; } // 배틀 끝 else if (BattleTalk == 6) { delete gugu; BattleTalk = 0; interrupt = battle = false; CountLoop = LENGTH; Answer = -1; arrow.SetObjects(20, 20); if (gameover) { /* 게임 오버 * 전에 싸우던 상대방 NoNext, HP 리셋, 나의 HP 리셋 * 센터 앞으로 위치 리셋, 맵 리셋, npc 리셋 */ if (player.tile != 1) { CurrentNPC.SetNoNext(); } Map.DeleteNPC(); pika.Heal(); gameover = Talk = false; CountLoop = 0; Map.IsMap = true; Map.map_number = 0; player.direct = 3; player.x = 8; player.y = 5; player.tile = 0; } else { interrupt = Talk = false; if (player.tile != 1) { CurrentNPC.SetYesNext(); CurrentNPC.SetDeletePoke(); } } player.SetObjects(player.x, player.y); Map.Loading_Map(map_DB[Map.map_number]); mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = BGM_map[Map.map_number] + 1; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } else if (BattleTalk == 7) { OK = false; BattleTalk = 6; } } } } else { // 멈춰있을때 메뉴 부름 if (keys['X'] && !player.WalkAnimation(CountLoop)) { isMenuOn = !isMenuOn; interrupt = true; arrow.SetObjects(11, 0); Map.Loading_Map(list_DB[0]); keys['X'] = 0; } // npc 말걸기 else if (keys['Z'] && !player.WalkAnimation(CountLoop)) { // z 눌렀을때 앞이 NPC 인지 확인 if (Map.Check_Map(player.x + (player.direct - 1) % 2, player.y + (player.direct - 2) % 2) == 5) { // 맞다면 누군지 탐색 for (loop1 = 0; loop1 < Map.num_npc; loop1++) { if ((Map.NPC[loop1].x == player.x + (player.direct - 1) % 2) && (Map.NPC[loop1].y == player.y + (player.direct - 2) % 2)) { TalkNPC = loop1; Map.NPC[loop1].Check_Direct((player.direct + 2) % 4); break; } } if (TalkNPC != -1) { interrupt = Talk = true; keys['Z'] = 0; wait = 8; CountLoop = 0; Answer = -1; } } else TalkNPC = -1; } else { if (player.Check_Stop() && (Map.Check_Map(player.x, player.y) == 3)) { Map.DeleteNPC(); Map.Link_Map(&(player.x), &(player.y)); Map.Loading_Map(map_DB[Map.map_number]); player.SetObjects(player.x, player.y); if (nowplaying != BGM_map[Map.map_number] + 1) { mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = BGM_map[Map.map_number] + 1; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } CountLoop = 0; } if (player.Check_Stop() && MEET) { if (GenRand(0, 10) == 10) { MEET = false; CurrentBattlePoke = GenRand(1,2) + Map.map_number; gugu = War.selectPoke(CurrentBattlePoke + GenRand(0,1), CurrentBattlePoke); addExp = pika.getAddExp() - 3 * (pika.getLevel() - gugu->getLevel()); //적 레벨에 내 레벨을 뺀후 곱하기 3의 경험치 패널티 if (addExp <= 0) addExp = 1; interrupt = battle = true; mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = 9; // 야생 전투 음악 재생! mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); OK = false; BattleTalk = 1; arrow.SetObjects(9, 8); Map.Loading_Map(list_DB[0]); } else { MEET = false; } } // 로켓단이 플레이어에게 싸움을 건다 if (player.Check_Stop() && Map.Check_Map(player.x, player.y) == 6) { TalkNPC = Map.map_array[player.x][player.y] / 10; if (CurrentNPC.GetSelect() != 0) { wait = 8; //keys['Z'] = true; CountLoop = 0; interrupt = Talk = true; Answer = -1; mciSendCommand(nowplaying, MCI_STOP, MCI_NOTIFY, (DWORD)(LPVOID)&mciPlay); mciSendCommand(nowplaying, MCI_SEEK, MCI_SEEK_TO_START, (DWORD)(LPVOID)&mciPlay); nowplaying = 12; mciSendCommand(nowplaying, MCI_PLAY, MCI_NOTIFY | MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&mciPlay); } else { Map.map_array[player.x][player.y] = 1; } } //방향키 입력 받으면 움직임 player.MovementByKeyInput(VK_LEFT); player.MovementByKeyInput(VK_UP); player.MovementByKeyInput(VK_RIGHT); player.MovementByKeyInput(VK_DOWN); player.WalkAnimation(CountLoop); // Move player from (fx, fy) to (x, y) player.MoveObject(steps[adjust], CountLoop); CountLoop += steps[adjust]; } } } } } //Shutdown KillGLWindow(); return (msg.wParam); }