⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 一個簡單的RPG遊戲DEMO源碼
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		  else if (arrary[hero.x1][hero.y1] == 0)
		  {
			if ((hero.x1 + 40 == 460) && (hero.y1 == 160))
			{
				hero.x1 -= 10;
				duihua = 2;
				return;
			}	   
           pBBuf->BltFast( 0 , 0 , pOPla[zai], CRect(0,0,640,480) , DDBLTFAST_WAIT);
	       	 if (tab)
			 {
	          pBBuf->BltFast(0, 380, pOPla[13], CRect(0, 0, 640,100) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
			  pBBuf->BltFast(5, 385, pOPla[14], CRect(0, 0, 85,85) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
			 }
		   pBBuf->BltFast(hero.x1, hero.y1, pOPla[i3++], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);   	
		   if (!room) 
		   {
		   pBBuf->BltFast(whero.x1, whero.y1, pOPla[zhi], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);   	   
		   }
		   else 
		   {
		      pBBuf->BltFast(450, 160, pOPla[23], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
		   }
		  }
		  if (i3 > 7)
		  {
		    i3 = 6;
		  }
	   }
 if (nChar == VK_SPACE)
 {	   
	 if (numx == 1)
	 {	
	    denble(num);  
	 	 ++num;
	    return;
	 }
    if (room)
	{
		if ((duihua != 6) && (duihua != 0))
		{
		  pBBuf->BltFast( 0 , 0 , pOPla[zai], CRect(0,0,640,480) , DDBLTFAST_WAIT);
		   pBBuf->BltFast(0, 380, pOPla[28 + duihua], CRect(0, 0, 640,100) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
		    //显示主人公的头像
		   if ((duihua == 2) || (duihua == 4))
		   {
			   pBBuf->BltFast(5, 385, pOPla[14], CRect(0, 0, 85,85) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
		   }  
		   //显示公主的头像
		   else 
		   {
		       pBBuf->BltFast(5, 385, pOPla[34], CRect(0, 0, 85,85) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
		   }
		   ++duihua;
		   pBBuf->BltFast(450, 160, pOPla[23], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
		   pBBuf->BltFast(hero.x1, hero.y1, pOPla[i3], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
		   pPSur->Flip(NULL, DDFLIP_WAIT);
		}
		else 
		{
	       pBBuf->BltFast( 0 , 0 , pOPla[zai], CRect(0,0,640,480) , DDBLTFAST_WAIT);
           pBBuf->BltFast(450, 160, pOPla[23], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
		   pBBuf->BltFast(hero.x1, hero.y1, pOPla[i3], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
		   pPSur->Flip(NULL, DDFLIP_WAIT);
		   duihua = 0;
		}
		  return;
	}
    else
	{
		   tab = !tab;
		  if (tab)
		  {	
		    pBBuf->BltFast( 0 , 0 , pOPla[zai], CRect(0, 0, 640, 480) , DDBLTFAST_WAIT);
		     pBBuf->BltFast(0, 380, pOPla[13], CRect(0, 0, 640,100) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
			 pBBuf->BltFast(5, 385, pOPla[14], CRect(0, 0, 85,85) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
		    if (hero.y1 > whero.y1)
			{ 
		     pBBuf->BltFast(whero.x1, whero.y1, pOPla[zhi], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
             pBBuf->BltFast(hero.x1, hero.y1, pOPla[hero.control], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);  	   	
			}
	        else if (hero.y1 <= whero.y1)
			{
		     pBBuf->BltFast(hero.x1, hero.y1, pOPla[hero.control], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
			 pBBuf->BltFast(whero.x1, 150, pOPla[zhi], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
			}
		  }
	}
 }
	   pPSur->Flip(NULL, DDFLIP_WAIT);
	CFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}


void CMainFrame::colorkey(int i)
{
    key.dwColorSpaceHighValue = 0x0000;
	key.dwColorSpaceLowValue = 0x0000;
	pOPla[i]->SetColorKey(DDCKEY_SRCBLT, &key);
}

void CMainFrame::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default 
//	  down = 0;
	if (!room)
	{
	 if ((whero.x1 > 40) && (control == 1))
	 { 
		 if (numx == 0)
		 {
		  whero.x1 -= 10;
		   bmove(zhi);
		  ++zhi;
		  if (whero.x1 <= 40)
		  {
			  control = 2;
			  zhi = 10;
			  return ;
		  }
			 if (zhi == 10)
			 {
				 zhi = 8;
			 }
		 }
	 }
	      if ((whero.x1 < 530) && (control == 2))
		  { 
		   if (numx == 0)
		   {
              whero.x1 += 10;
			  bmove(zhi);
			  ++zhi;
			   if (whero.x1 >= 530)
			   {
			     control = 1;
				 zhi = 8;
				 return ;
			   }
			   if (zhi == 12)
			   {
			     zhi = 10;
			   }
		   }
		  }
	}
		  CFrameWnd::OnTimer(nIDEvent);
}





void CMainFrame::chuli(CString str, int width, int height, int i)
{
    desc.dwWidth = width; 
	desc.dwHeight = height; 
	result = pDD7->CreateSurface(&desc, &pOPla[i], NULL); 
	if(result !=DD_OK)
	{
  		MessageBox("建立幕后内存区失败!");
		return;
	}
	bitmap = (HBITMAP)::LoadImage(NULL,str,IMAGE_BITMAP, width, height, LR_LOADFROMFILE);
    ::SelectObject(hdc,bitmap);       //设定hdc中的位图为bitmap
	pOPla[i]->GetDC(&hdc1);  
         //取得幕后内存区的DC
	::BitBlt(hdc1, 0, 0, width, height, hdc, 0, 0, SRCCOPY); //将位图复制到幕后内存区中
	pOPla[i]->ReleaseDC(hdc1);
}

void CMainFrame::chu(CString str, int num)
{
    desc.dwWidth = 80; 
	desc.dwHeight = 160; 
	int k = num;
	int 	x1 = 0;
	int	y1 = 0;
	bitmap = (HBITMAP)::LoadImage(NULL,str,IMAGE_BITMAP, 80, 160, LR_LOADFROMFILE);
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			result = pDD7->CreateSurface(&desc, &pOPla[k], NULL); 
			if(result !=DD_OK)
			{
				MessageBox("建立幕后内存区失败!");
				return;
			}  
	       //    bitmap = (HBITMAP)::LoadImage(NULL,str,IMAGE_BITMAP, 80, 160, LR_LOADFROMFILE);
			::SelectObject(hdc,bitmap);       //设定hdc中的位图为bitmap
			pOPla[k]->GetDC(&hdc1);  

			//取得幕后内存区的DC
			::BitBlt(hdc1, 0, 0, 80, 160, hdc, x1, y1, SRCCOPY); //将位图复制到幕后内存区中
			pOPla[k]->ReleaseDC( hdc1 );
			++k;
			x1 += 40;
		}
		x1 = 0;
		y1 += 40;
	}
}

void CMainFrame::chu1(CString str)
{
    desc.dwWidth = 80; 
	desc.dwHeight = 160; 
	int k = 8;
    int	x1 = 0;
     int y1 = 40;
		 bitmap = (HBITMAP)::LoadImage(NULL,str,IMAGE_BITMAP, 80, 160, LR_LOADFROMFILE);
			 for (int j = 0; j < 2; j++)
			 {
				 for (int i = 0; i < 2; i++)
				 {
				  result = pDD7->CreateSurface(&desc, &pOPla[k], NULL); 
	              if(result !=DD_OK)
				  {
  		           MessageBox("建立幕后内存区失败!");
		           return;
				  }  
                   ::SelectObject(hdc,bitmap);       //设定hdc中的位图为bitmap
	              pOPla[k]->GetDC(&hdc1);  
         //取得幕后内存区的DC
	               ::BitBlt(hdc1, 0, 0, 80, 160, hdc, x1, y1, SRCCOPY); //将位图复制到幕后内存区中
		           pOPla[k]->ReleaseDC( hdc1 );
			       ++k;
				   x1 += 40;
				 }
				 x1 = 0;
				 y1 += 80;
			 }
}

void CMainFrame::bmove(int &zhi)
{
	pBBuf->BltFast( 0 , 0 , pOPla[zai], CRect(0,0,640,480) , DDBLTFAST_WAIT);
     if (tab)
	 {
	    pBBuf->BltFast(0, 380, pOPla[13], CRect(0, 0, 640,100) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
	    pBBuf->BltFast(5, 385, pOPla[14], CRect(0, 0, 85,85) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
	 }

	if ((whero.x1 - 30 == hero.x1) && (whero.y1 == hero.y1))
	{
	    numx = 1;	
		whero.x1 += 10;
	     return;
	}
    if ((whero.x1 + 30 == hero.x1) && (whero.y1 == hero.y1))
	{ 
	  numx = 1;
	  if (num == 20)
	  {
	    numx = 0;
	  }
	  whero.x1 -= 10;
	  return;
	}
  	 if (hero.y1 > whero.y1)
	 {
		 pBBuf->BltFast(whero.x1, whero.y1, pOPla[zhi], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
       pBBuf->BltFast(hero.x1, hero.y1, pOPla[hero.control], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);  	   	
	 }
	else if (hero.y1 <= whero.y1)
	{
		pBBuf->BltFast(hero.x1, hero.y1, pOPla[hero.control], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
	   pBBuf->BltFast(whero.x1, 150, pOPla[zhi], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
	}
		 pPSur->Flip(NULL, DDFLIP_WAIT);
}
//这个函数用来设置city地图不能行走的地方
void CMainFrame::Inarrary()
{
     for (int k = 0; k < 640; k++)
     {
		 for (int j = 0; j < 480; j++)
		 {
		   arrary[k][j] = 0;
		 }
	 }
     for (k = 0; k < 480; k++)
	 {
	     arrary[0][k] = 1;
		 arrary[610][k] = 1;
	 }
	 for (k = 0; k < 610; k++)
	 {
	   arrary[k][10] = 1;
	 }
   for (int i = 0; i <= 3; i++)
   {
     for (int k = aj[i].x0; k <= aj[i].x1; k++)
		 for (int j = aj[i].y0; j <= aj[i].y1; j++)
		 {
		    arrary[k][j] = 1;
		 }
   }
}

void CMainFrame::Injuxin()
{
	//这是第一张图画的不能行走的区域
   aj[0].x0 = 0;
   aj[0].y0 = 0;
   aj[0].x1 = 150;
   aj[0].y1 = 100;

   aj[1].x0 = 240;
   aj[1].y0 = 0;
   aj[1].x1 = 600;
   aj[1].y1 = 100;
   
   aj[2].x0 = 0;
   aj[2].y0 = 345;
   aj[2].x1 = 600;
   aj[2].y1 = 440;

   aj[3].x0 = 330;
   aj[3].y0 = 160;
   aj[3].x1 = 600;
   aj[3].y1 = 310;
	//这是第二张图画的不能行走的区域
   aj[4].x0 = 80;
   aj[4].y0 = 110;
   aj[4].x1 = 200;
   aj[4].y1 = 210;

   aj[5].x0 = 450;
   aj[5].y0 = 130;
   aj[5].x1 = 570;
   aj[5].y1 = 170;
}
//这个函数用来设置room地图不可以走的地方
void CMainFrame::Inarrary1()
{
	int k = 0;
     for (k = 0; k <= 600; k++)
     {
		 for (int j = 0; j <= 440; j++)
		 {
		   arrary[k][j] = 1;
		 }
	 }
	 for (k = 30; k < 580; k++)
	 {
		 for (int j = 50; j < 420; j++)
		 {
		    arrary[k][j] = 0;
		 }
	 }
   for (int i = 4; i <= 5; i++)
   {
     for (int k = aj[i].x0; k <= aj[i].x1; k++)
		 for (int j = aj[i].y0; j <= aj[i].y1; j++)
		 {
		    arrary[k][j] = 1;
		 }
   }
}
// 这个函数用来实现和一个人物的对话
void CMainFrame::denble(int num)
{
	 int k = 14;
	 pBBuf->BltFast( 0 , 0 , pOPla[zai], CRect(0,0,640,480) , DDBLTFAST_WAIT);
	   if (num >= 20)
	   {
		  pBBuf->BltFast(whero.x1, whero.y1, pOPla[zhi], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
          pBBuf->BltFast(hero.x1, hero.y1, pOPla[hero.control], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 	 	
	   }
	   else
	   {
		 if ((num == 17) || (num == 19))
           k = 20;
	   	 pBBuf->BltFast( 0 , 0 , pOPla[zai], CRect(0,0,640,480) , DDBLTFAST_WAIT);
	     pBBuf->BltFast(0, 380, pOPla[num], CRect(0, 0, 640,100) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
	     pBBuf->BltFast(5, 385, pOPla[k], CRect(0, 0, 85,85) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY);
         pBBuf->BltFast(whero.x1, whero.y1, pOPla[zhi], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 
         pBBuf->BltFast(hero.x1, hero.y1, pOPla[hero.control], CRect(0,0,40,40) , DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY); 	 
	   }
	   pPSur->Flip(NULL, DDFLIP_WAIT); 
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	CFrameWnd::OnClose();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -