Dungeon::Dungeon() { black = GetColor(0, 0, 0); yellow = GetColor(255, 255, 0); white = GetColor(255, 255, 255); blue = GetColor(0, 0, 255); SetTransColor(255, 255, 255); //白を透過色に yajirushi_h = LoadGraph("./dungeon/yajirushi.png"); SetTransColor(0, 0, 0); //一応戻す event_h = LoadGraph("./img/2bikkuri.bmp"); if (yajirushi_h == -1) { DrawString(0, 0, "Error!", GetColor(255, 0, 0)); WaitKey(); } SetUseZBuffer3D(TRUE); //深度ステンシルバッファ SetWriteZBuffer3D(TRUE); //。今のところ必要ない…と思いきや、一方通行の壁が荒ぶることへの対処ができる。一瞬暗くなるのは仕方ない? option = Option::GetInstance(); savedata = SaveData::GetInstance(); menu = Menu::GetInstance(); player = new Player(Prologue::RIAJU); LoadDungeon(3); }
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){ SetWindowText("Title"); SetGraphMode(WINDOW_WIDTH , WINDOW_HEIGHT,32 ); ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); int LoadImage = LoadGraph("Natsuiro/BLOCK/load.png"); DrawExtendGraph(0,0,WINDOW_WIDTH,WINDOW_HEIGHT, LoadImage ,false); ScreenFlip(); SetTransColor(255,0,255); Awake(); long long TIME = GetNowHiPerformanceCount(); # if BENCHMARK == TRUE long long int count = GetNowCount(); # endif while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && !CheckHitKey(KEY_INPUT_ESCAPE) ){ GameLoop(); Sleep( (unsigned long)max( 16 - (int)( GetNowHiPerformanceCount() - TIME ) / 1000 , 0 ) ); TIME = GetNowHiPerformanceCount(); # if BENCHMARK == TRUE DrawFormatString(WINDOW_WIDTH-200,0,BLACK,"FPS %d (%dms)", (int)( 1000/( GetNowCount() - count ) ) , GetNowCount() - count ); count = GetNowCount(); # endif } DxLib_End(); return 0; }
//********************************************************* // ゲームの初期化を行う //********************************************************* int GameInit(void) { // Dxライブラリ初期化前の処理 SetGraphMode(WIN_W, WIN_H, 32); ChangeWindowMode(TRUE); // ウィンドウモードで起動 SetMainWindowText("テスト"); // ウィンドウタイトルを設定 // Dxライブラリの初期化 // エラーが起きたら直ちに終了 if (DxLib_Init() == -1) return -1; // Dxライブラリ初期化後の処理 SetDrawScreen(DX_SCREEN_BACK); // 描画先を裏画面にする SetTransColor(0, 255, 0); // ここまでゲーム固有の初期化 // 正常終了 return 0; }
bool CxImageWMF::Decode(CxFile *hFile, long nForceWidth, long nForceHeight) { if (hFile == NULL) return false; HENHMETAFILE hMeta; HDC hDC; int cx,cy; //save the current position of the file long pos = hFile->Tell(); // Read the Metafile and convert to an Enhanced Metafile METAFILEHEADER mfh; hMeta = ConvertWmfFiletoEmf(hFile, &mfh); if (hMeta) { // ok, it's a WMF ///////////////////////////////////////////////////////////////////// // We use the original WMF size information, because conversion to // EMF adjusts the Metafile to Full Screen or does not set rclBounds at all // ENHMETAHEADER emh; // UINT uRet; // uRet = GetEnhMetaFileHeader(hMeta, // handle of enhanced metafile // sizeof(ENHMETAHEADER), // size of buffer, in bytes // &emh); // address of buffer to receive data // if (!uRet){ // DeleteEnhMetaFile(hMeta); // return false; // } // // calculate size // cx = emh.rclBounds.right - emh.rclBounds.left; // cy = emh.rclBounds.bottom - emh.rclBounds.top; ///////////////////////////////////////////////////////////////////// // calculate size // scale the metafile (pixels/inch of metafile => pixels/inch of display) // mfh.inch already checked to be <> 0 hDC = ::GetDC(0); int cx1 = ::GetDeviceCaps(hDC, LOGPIXELSX); int cy1 = ::GetDeviceCaps(hDC, LOGPIXELSY); ::ReleaseDC(0, hDC); cx = (mfh.bbox.right - mfh.bbox.left) * cx1 / mfh.inch; cy = (mfh.bbox.bottom - mfh.bbox.top) * cy1 / mfh.inch; } else { // maybe it's an EMF... hFile->Seek(pos,SEEK_SET); ENHMETAHEADER emh; hMeta = ConvertEmfFiletoEmf(hFile, &emh); if (!hMeta){ strcpy(info.szLastError,"corrupted WMF"); return false; // definitively give up } // ok, it's an EMF // calculate size cx = emh.rclBounds.right - emh.rclBounds.left; cy = emh.rclBounds.bottom - emh.rclBounds.top; } if (info.nEscape) { // Check if cancelled DeleteEnhMetaFile(hMeta); strcpy(info.szLastError,"Cancelled"); return false; } if (!cx || !cy) { DeleteEnhMetaFile(hMeta); strcpy(info.szLastError,"empty WMF"); return false; } if (nForceWidth) cx=nForceWidth; if (nForceHeight) cy=nForceHeight; ShrinkMetafile(cx, cy); // !! Otherwise Bitmap may have bombastic size HDC hDC0 = GetDC(0); // DC of screen HBITMAP hBitmap = CreateCompatibleBitmap(hDC0, cx, cy); // has # colors of display hDC = CreateCompatibleDC(hDC0); // memory dc compatible with screen ReleaseDC(0, hDC0); // don't need anymore. get rid of it. if (hDC){ if (hBitmap){ RECT rc = {0,0,cx,cy}; int bpp = ::GetDeviceCaps(hDC, BITSPIXEL); HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap); // clear out the entire bitmap with windows background // because the MetaFile may not contain background information DWORD dwBack = XMF_COLOR_BACK; #if XMF_SUPPORT_TRANSPARENCY if (bpp == 24) dwBack = XMF_COLOR_TRANSPARENT; #endif DWORD OldColor = SetBkColor(hDC, dwBack); ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); SetBkColor(hDC, OldColor); //retrieves optional palette entries from the specified enhanced metafile PLOGPALETTE plogPal; PBYTE pjTmp; HPALETTE hPal; int iEntries = GetEnhMetaFilePaletteEntries(hMeta, 0, NULL); if (iEntries) { if ((plogPal = (PLOGPALETTE)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(DWORD) + sizeof(PALETTEENTRY)*iEntries )) == NULL) { DeleteObject(hBitmap); DeleteDC(hDC); DeleteEnhMetaFile(hMeta); strcpy(info.szLastError,"Cancelled"); return false; } plogPal->palVersion = 0x300; plogPal->palNumEntries = (WORD) iEntries; pjTmp = (PBYTE) plogPal; pjTmp += 4; GetEnhMetaFilePaletteEntries(hMeta, iEntries, (PPALETTEENTRY)pjTmp); hPal = CreatePalette(plogPal); GlobalFree(plogPal); SelectPalette(hDC, hPal, FALSE); RealizePalette(hDC); } // Play the Metafile into Memory DC BOOL bRet = PlayEnhMetaFile(hDC, // handle to a device context hMeta, // handle to an enhanced metafile &rc); // pointer to bounding rectangle SelectObject(hDC, hBitmapOld); DeleteEnhMetaFile(hMeta); // we are done with this one if (info.nEscape) { // Check if cancelled DeleteObject(hBitmap); DeleteDC(hDC); strcpy(info.szLastError,"Cancelled"); return false; } // the Bitmap now has the image. // Create our DIB and convert the DDB into DIB if (!Create(cx, cy, bpp, CXIMAGE_FORMAT_WMF)) { DeleteObject(hBitmap); DeleteDC(hDC); return false; } #if XMF_SUPPORT_TRANSPARENCY if (bpp == 24) { RGBQUAD rgbTrans = { XMF_RGBQUAD_TRANSPARENT }; SetTransColor(rgbTrans); } #endif // We're finally ready to get the DIB. Call the driver and let // it party on our bitmap. It will fill in the color table, // and bitmap bits of our global memory block. bRet = GetDIBits(hDC, hBitmap, 0, (UINT)cy, GetBits(), (LPBITMAPINFO)pDib, DIB_RGB_COLORS); DeleteObject(hBitmap); DeleteDC(hDC); return (bRet!=0); } else { DeleteDC(hDC); } } else { if (hBitmap) DeleteObject(hBitmap); } DeleteEnhMetaFile(hMeta); return false; }
bool CxImageICO::Decode(CxFile *hFile) { if (hFile==NULL) return false; DWORD off = hFile->Tell(); //<yuandi> int page=info.nFrame; //internal icon structure indexes // read the first part of the header ICONHEADER icon_header; hFile->Read(&icon_header,sizeof(ICONHEADER),1); icon_header.idType = my_ntohs(icon_header.idType); icon_header.idCount = my_ntohs(icon_header.idCount); // check if it's an icon or a cursor if ((icon_header.idReserved == 0) && ((icon_header.idType == 1)||(icon_header.idType == 2))) { info.nNumFrames = icon_header.idCount; // load the icon descriptions ICONDIRENTRY *icon_list = (ICONDIRENTRY *)malloc(icon_header.idCount * sizeof(ICONDIRENTRY)); int c; for (c = 0; c < icon_header.idCount; c++) { hFile->Read(icon_list + c, sizeof(ICONDIRENTRY), 1); icon_list[c].wPlanes = my_ntohs(icon_list[c].wPlanes); icon_list[c].wBitCount = my_ntohs(icon_list[c].wBitCount); icon_list[c].dwBytesInRes = my_ntohl(icon_list[c].dwBytesInRes); icon_list[c].dwImageOffset = my_ntohl(icon_list[c].dwImageOffset); } if ((page>=0)&&(page<icon_header.idCount)){ if (info.nEscape == -1) { // Return output dimensions only head.biWidth = icon_list[page].bWidth; head.biHeight = icon_list[page].bHeight; #if CXIMAGE_SUPPORT_PNG if (head.biWidth==0 && head.biHeight==0) { // Vista icon support hFile->Seek(off + icon_list[page].dwImageOffset, SEEK_SET); CxImage png; png.SetEscape(-1); if (png.Decode(hFile,CXIMAGE_FORMAT_PNG)){ Transfer(png); info.nNumFrames = icon_header.idCount; } } #endif //CXIMAGE_SUPPORT_PNG free(icon_list); info.dwType = CXIMAGE_FORMAT_ICO; return true; } // get the bit count for the colors in the icon <CoreyRLucier> BITMAPINFOHEADER bih; hFile->Seek(off + icon_list[page].dwImageOffset, SEEK_SET); if (icon_list[page].bWidth==0 && icon_list[page].bHeight==0) { // Vista icon support #if CXIMAGE_SUPPORT_PNG CxImage png; if (png.Decode(hFile,CXIMAGE_FORMAT_PNG)){ Transfer(png); info.nNumFrames = icon_header.idCount; } SetType(CXIMAGE_FORMAT_ICO); #endif //CXIMAGE_SUPPORT_PNG } else { // standard icon hFile->Read(&bih,sizeof(BITMAPINFOHEADER),1); bihtoh(&bih); c = bih.biBitCount; // allocate memory for one icon Create(icon_list[page].bWidth,icon_list[page].bHeight, c, CXIMAGE_FORMAT_ICO); //image creation // read the palette RGBQUAD pal[256]; if (bih.biClrUsed) hFile->Read(pal,bih.biClrUsed*sizeof(RGBQUAD), 1); else hFile->Read(pal,head.biClrUsed*sizeof(RGBQUAD), 1); SetPalette(pal,head.biClrUsed); //palette assign //read the icon if (c<=24){ hFile->Read(info.pImage, head.biSizeImage, 1); } else { // 32 bit icon BYTE* buf=(BYTE*)malloc(4*head.biHeight*head.biWidth); BYTE* src = buf; hFile->Read(buf, 4*head.biHeight*head.biWidth, 1); #if CXIMAGE_SUPPORT_ALPHA if (!AlphaIsValid()) AlphaCreate(); #endif //CXIMAGE_SUPPORT_ALPHA for (long y = 0; y < head.biHeight; y++) { BYTE* dst = GetBits(y); for(long x=0;x<head.biWidth;x++){ *dst++=src[0]; *dst++=src[1]; *dst++=src[2]; #if CXIMAGE_SUPPORT_ALPHA AlphaSet(x,y,src[3]); #endif //CXIMAGE_SUPPORT_ALPHA src+=4; } } free(buf); } // apply the AND and XOR masks int maskwdt = ((head.biWidth+31) / 32) * 4; //line width of AND mask (always 1 Bpp) int masksize = head.biHeight * maskwdt; //size of mask BYTE *mask = (BYTE *)malloc(masksize); if (hFile->Read(mask, masksize, 1)){ bool bGoodMask=false; for (int im=0;im<masksize;im++){ if (mask[im]!=255){ bGoodMask=true; break; } } if (bGoodMask && c != 32){ #if CXIMAGE_SUPPORT_ALPHA bool bNeedAlpha = false; if (!AlphaIsValid()){ AlphaCreate(); } else { bNeedAlpha=true; //32bit icon } int x,y; for (y = 0; y < head.biHeight; y++) { for (x = 0; x < head.biWidth; x++) { if (((mask[y*maskwdt+(x>>3)]>>(7-x%8))&0x01)){ AlphaSet(x,y,0); bNeedAlpha=true; } } } if (!bNeedAlpha) AlphaDelete(); #endif //CXIMAGE_SUPPORT_ALPHA //check if there is only one transparent color RGBQUAD cc,ct; long* pcc = (long*)&cc; long* pct = (long*)&ct; int nTransColors=0; int nTransIndex=0; for (y = 0; y < head.biHeight; y++){ for (x = 0; x < head.biWidth; x++){ if (((mask[y*maskwdt+(x>>3)] >> (7-x%8)) & 0x01)){ cc = GetPixelColor(x,y,false); if (nTransColors==0){ nTransIndex = GetPixelIndex(x,y); nTransColors++; ct = cc; } else { if (*pct!=*pcc){ nTransColors++; } } } } } if (nTransColors==1){ SetTransColor(ct); SetTransIndex(nTransIndex); #if CXIMAGE_SUPPORT_ALPHA AlphaDelete(); //because we have a unique transparent color in the image #endif //CXIMAGE_SUPPORT_ALPHA } // <vho> - Transparency support w/o Alpha support if (c <= 8){ // only for icons with less than 256 colors (XP icons need alpha). // find a color index, which is not used in the image // it is almost sure to find one, bcs. nobody uses all possible colors for an icon BYTE colorsUsed[256]; memset(colorsUsed, 0, sizeof(colorsUsed)); for (y = 0; y < head.biHeight; y++){ for (x = 0; x < head.biWidth; x++){ colorsUsed[BlindGetPixelIndex(x,y)] = 1; } } int iTransIdx = -1; for (x = (int)(head.biClrUsed-1); x>=0 ; x--){ if (colorsUsed[x] == 0){ iTransIdx = x; // this one is not in use. we may use it as transparent color break; } } // Go thru image and set unused color as transparent index if needed if (iTransIdx >= 0){ bool bNeedTrans = false; for (y = 0; y < head.biHeight; y++){ for (x = 0; x < head.biWidth; x++){ // AND mask (Each Byte represents 8 Pixels) if (((mask[y*maskwdt+(x>>3)] >> (7-x%8)) & 0x01)){ // AND mask is set (!=0). This is a transparent part SetPixelIndex(x, y, (BYTE)iTransIdx); bNeedTrans = true; } } } // set transparent index if needed if (bNeedTrans) SetTransIndex(iTransIdx); #if CXIMAGE_SUPPORT_ALPHA AlphaDelete(); //because we have a transparent color in the palette #endif //CXIMAGE_SUPPORT_ALPHA } } } else if(c != 32){
bool CxImageICO::Decode(CxFile *hFile) { if (hFile==NULL) return false; DWORD off = hFile->Tell(); //<yuandi> int page=info.nFrame; //internal icon structure indexes // read the first part of the header ICONHEADER icon_header; hFile->Read(&icon_header,sizeof(ICONHEADER),1); // check if it's an icon if ((icon_header.idReserved == 0) && (icon_header.idType == 1)) { info.nNumFrames = icon_header.idCount; // load the icon descriptions ICONDIRENTRY *icon_list = (ICONDIRENTRY *)malloc(icon_header.idCount * sizeof(ICONDIRENTRY)); int c; for (c = 0; c < icon_header.idCount; c++) hFile->Read(icon_list + c, sizeof(ICONDIRENTRY), 1); if ((info.nFrame>=0)&&(info.nFrame<icon_header.idCount)){ // get the bit count for the colors in the icon <CoreyRLucier> BITMAPINFOHEADER bih; hFile->Seek(off + icon_list[page].dwImageOffset, SEEK_SET); hFile->Read(&bih,sizeof(BITMAPINFOHEADER),1); c = bih.biBitCount; // allocate memory for one icon Create(icon_list[page].bWidth,icon_list[page].bHeight, c, CXIMAGE_FORMAT_ICO); //image creation // read the palette RGBQUAD pal[256]; hFile->Read(pal,head.biClrUsed*sizeof(RGBQUAD), 1); SetPalette(pal,head.biClrUsed); //palette assign //read the icon if (c<=24){ hFile->Read(info.pImage, head.biSizeImage, 1); } else { // 32 bit icon BYTE* dst = info.pImage; BYTE* buf=(BYTE*)malloc(4*head.biHeight*head.biWidth); BYTE* src = buf; hFile->Read(buf, 4*head.biHeight*head.biWidth, 1); #if CXIMAGE_SUPPORT_ALPHA if (!AlphaIsValid()) AlphaCreate(); #endif //CXIMAGE_SUPPORT_ALPHA for (long y = 0; y < head.biHeight; y++) { for(long x=0;x<head.biWidth;x++){ *dst++=src[0]; *dst++=src[1]; *dst++=src[2]; #if CXIMAGE_SUPPORT_ALPHA AlphaSet(x,y,src[3]); #endif //CXIMAGE_SUPPORT_ALPHA src+=4; } } free(buf); } // apply the AND and XOR masks int maskwdt = ((head.biWidth+31) / 32) * 4; //line width of AND mask (always 1 Bpp) int masksize = head.biHeight * maskwdt; //size of mask BYTE *mask = (BYTE *)malloc(masksize); if (hFile->Read(mask, masksize, 1)){ #if CXIMAGE_SUPPORT_ALPHA bool bNeedAlpha = false; if (!AlphaIsValid()){ AlphaCreate(); AlphaSet(255); } else { bNeedAlpha=true; //32bit icon } for (int y = 0; y < head.biHeight; y++) { for (int x = 0; x < head.biWidth; x++) { if (((mask[y*maskwdt+(x>>3)]>>(7-x%8))&0x01)){ AlphaSet(x,y,0); bNeedAlpha=true; } } } if (!bNeedAlpha) AlphaDelete(); #endif //CXIMAGE_SUPPORT_ALPHA if (c==24){ //check if there is only one transparent color RGBQUAD cc,ct; long* pcc = (long*)&cc; long* pct = (long*)&ct; int nTransColors=0; for (int y = 0; y < head.biHeight; y++){ for (int x = 0; x < head.biWidth; x++){ if (((mask[y*maskwdt+(x>>3)] >> (7-x%8)) & 0x01)){ cc = GetPixelColor(x,y); if (nTransColors==0){ nTransColors++; ct = cc; } else { if (*pct!=*pcc){ nTransColors++; } } } } } if (nTransColors==1){ SetTransColor(ct); SetTransIndex(0); #if CXIMAGE_SUPPORT_ALPHA AlphaDelete(); //because we have a unique transparent color in the image #endif //CXIMAGE_SUPPORT_ALPHA } }
void Dungeon::LoadDungeon(int floor) //行く予定の階層の情報を読み込むかつ初期化 { switch (floor) { case 1: fp = fopen("./dungeon/dungeon1/floor1/map.cns", "r"); strcpy(dungeon_name, "dungeon1/floor1"); break; case 2: fp = fopen("./dungeon/dungeon1/floor2/map.cns", "r"); strcpy(dungeon_name, "dungeon1/floor2"); break; case 3: fp = fopen("./dungeon/dungeon1/floor3/map.cns", "r"); strcpy(dungeon_name, "dungeon1/floor3"); break; } floors = floor; //GraphFilter(kabe_handle, DX_GRAPH_FILTER_GAUSS, 32, 55600); if (fp == NULL) //エラーチェック { DrawString(0, 0, "Error!", GetColor(255, 0, 0)); WaitKey(); } fscanf(fp, "%d,%d", &x_max, &z_max); for (int i = 0; i < z_max; i++) { for (int i2 = 0; i2 < x_max; i2++) { fscanf(fp, "%d,", &map_data[i][i2]); //fscanf(fp, "%c"); } } fscanf(fp, "%d,%d", &start_x, &start_z); fscanf(fp, "%d", &feel_flag); fscanf(fp, "%s", kabe_name); fscanf(fp, "%d,%d,%d", &fog_r, &fog_g, &fog_b); fscanf(fp, "%f,%f", &fog_start, &fog_goal); SetTransColor(255, 255, 255); //白を透過色に kabe_handle = LoadGraph(kabe_name); SetTransColor(0, 0, 0); //一応戻す if (kabe_handle == -1) //エラーチェック { DrawString(0, 0, "Error!", GetColor(255, 0, 0)); WaitKey(); } if (feel_flag) { int keep = 0; for (int i = 0; i < z_max / 2; i++) { for (int i2 = 0; i2 < x_max; i2++) { keep = map_data[i][i2]; map_data[i][i2] = map_data[z_max - i - 1][i2]; map_data[z_max - i - 1][i2] = keep; } } } //情報の初期化 pos_x = start_x; pos_z = start_z; state = 0; time = 0; muki = 0; nowchoose = 0; state = 0; minimap_flag = 1; //カメラの初期化 target_camera = VGet(pos_x * 100 + 50, 50, pos_z * 100 + 100); player_camera = VGet(pos_x * 100 + 50, 50, pos_z * 100); //フォグの設定 SetFogEnable(TRUE); SetFogColor(fog_r, fog_g, fog_b); SetFogStartEnd(fog_start, fog_goal); }