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

📄 frame.cpp

📁 RPG小游戏
💻 CPP
📖 第 1 页 / 共 5 页
字号:
palette[0].peRed     = 0;
palette[0].peGreen   = 0;
palette[0].peBlue    = 0;
palette[0].peFlags   = PC_NOCOLLAPSE;

palette[255].peRed   = 255;
palette[255].peGreen = 255;
palette[255].peBlue  = 255;
palette[255].peFlags = PC_NOCOLLAPSE;

// create the palette object
if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | 
                                DDPCAPS_INITIALIZE, 
                                palette,&lpddpal, NULL)))
return(0);

// finally attach the palette to the primary surface
if (FAILED(lpddsprimary->SetPalette(lpddpal)))
   return(0);

// set clipper up on back buffer since that's where well clip
RECT screen_rect= {0,0,SCREEN_WIDTH-1,SCREEN_HEIGHT-1};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);

// load the 8-bit image
if (!Load_Bitmap_File(&bitmap[0],"resource\\hot.bmp"))
   return(0);

if (!Load_Bitmap_File(&bitmap[1],"resource\\alley8.bmp"))
   return(0);






// load it's palette into directdraw
if (FAILED(lpddpal->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap[0].palette)))
   return(0);



// clean the surfaces
DDraw_Fill_Surface(lpddsprimary,0);
DDraw_Fill_Surface(lpddsback,0);
UCHAR *image_buffer;


int i;

for(int j=0;j<2;j++)
{
	if(j==2)i=3;
	else i=j;
	DDRAW_INIT_STRUCT(ddsd);
	
	// create the buffer to hold the background
	lpddsbackground[i] = DDraw_Create_Surface(SCREEN_WIDTH,SCREEN_HEIGHT,0,-1);

	// copy the background bitmap image to the background surface 

	// lock the surface
	lpddsbackground[i]->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);

	// get video pointer to primary surfce
	image_buffer = (UCHAR *)ddsd.lpSurface;       

	// test if memory is linear
	if (ddsd.lPitch == SCREEN_WIDTH)
	{
		// copy memory from double buffer to primary buffer
		  memcpy((void *)image_buffer, (void *)bitmap[i].buffer, SCREEN_WIDTH*SCREEN_HEIGHT);
	   } // end if
	else
	   { // non-linear

	   // make copy of source and destination addresses
		   UCHAR *dest_ptr = image_buffer;
		  UCHAR *src_ptr  = bitmap[i].buffer;

	   // memory is non-linear, copy line by line
		   for (int y=0; y < SCREEN_HEIGHT; y++)
	       {
	       // copy line
			       memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH);

		   // advance pointers to next line
		      dest_ptr+=ddsd.lPitch;
		      src_ptr +=SCREEN_WIDTH;
	      } // end for

   } // end else

	// now unlock the primary surface
	if (FAILED(lpddsbackground[i]->Unlock(NULL)))
		return(0);

	// unload the bitmap file, we no longer need it
	Unload_Bitmap_File(&bitmap[i]);
}



		if (!Load_Bitmap_File(&start_pic,"resource\\hot.bmp"))
			return(0);
		start_picture=DDraw_Create_Surface(SCREEN_WIDTH,SCREEN_HEIGHT,0,-1);
		Scan_Image_Bitmap(&start_pic,start_picture,0,0);
	
	



	if (!Load_Bitmap_File(&bitmap[0],"resource\\yd.bmp"))
		return(0);
	lpddsotherpeople[0]=DDraw_Create_Surface(73,137,0,0);
		Scan_Image_Bitmap(&bitmap[0],lpddsotherpeople[0],0,0);
	Unload_Bitmap_File(&bitmap[0]);
		
	if (!Load_Bitmap_File(&bitmap[0],"resource\\hyt.bmp"))
		return(0);
    houyitou=DDraw_Create_Surface(100,130,0,0);
	Scan_Image_Bitmap(&bitmap[0],houyitou,0,0);
	Unload_Bitmap_File(&bitmap[0]);
	if (!Load_Bitmap_File(&bitmap[0],"resource\\ydt.bmp"))
			return(0);
	yuditou=DDraw_Create_Surface(101,130,0,0);
	Scan_Image_Bitmap(&bitmap[0],yuditou,0,0);
	Unload_Bitmap_File(&bitmap[0]);

		


	talkbar=DDraw_Create_Surface(898,93,0,0);
	if (!Load_Bitmap_File(&bitmap[3],"resource\\talkbar1.bmp"))
			return(0);
	Scan_Image_Bitmap(&bitmap[3],talkbar,0,0);
		Unload_Bitmap_File(&bitmap[3]);





if (!Load_Bitmap_File(&bitmap[0],"resource\\houyi.bmp"))
   return(0);


for(int x=0;x<4;x++)
	for (int y = 0; y < 5; y++)
    {
	
		HouYi.lpdds[x][y] = DDraw_Create_Surface(120,120,0,0);

		Scan_Image_Bitmap(&bitmap[0],               
                      HouYi.lpdds[x][y], 
                      y, 2*x);                 

    }


Unload_Bitmap_File(&bitmap[0]);

	if (!Load_Bitmap_File(&bitmap[3],"resource\\nvren.bmp"))
	    	return(0);
			for(i=0;i<4;i++)
				for(int j =0;j<3;j++)
				{
	              	changer.lpdds1[i][j] = DDraw_Create_Surface(71,95,0,0);
					Scan_Image_Bitmap(&bitmap[3],                
						 changer.lpdds1[i][j],
							j, i); 
				}
				changer.set_WH(71,95);

        if (!Load_Bitmap_File(&bitmap[2],"resource\\nvrentou.bmp"))
				return(0);
		lpddsotherpeople[1]=DDraw_Create_Surface(104,105,0,0);
		Scan_Image_Bitmap(&bitmap[2],lpddsotherpeople[1],0,0);
			Unload_Bitmap_File(&bitmap[2]);



return(1);

} 

/////////////////////////////////////////////////////////////

int Game_Shutdown(void *parms = NULL, int num_parms = 0)
{
// this is called after the game is exited and the main event
// loop while is exited, do all you cleanup and shutdown here

// kill all the surfaces


// first the palette
if (lpddpal)
   {
   lpddpal->Release();
   lpddpal = NULL;
   } // end if

// now the primary surface
if (lpddsprimary)
   {
   lpddsprimary->Release();
   lpddsprimary = NULL;
   } // end if

// now blow away the IDirectDraw4 interface
if (lpdd)
   {
   lpdd->Release();
   lpdd = NULL;
   } // end if

// return success or failure or your own return code here
return(1);

} // end Game_Shutdown

// WINMAIN ////////////////////////////////////////////////

int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create
HWND	   hwnd;	 // generic window handle
MSG		   msg;		 // generic message
//HDC        hdc;      // graphics device context

// first fill in the window class stucture
winclass.cbSize         = sizeof(WNDCLASSEX);
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL;
winclass.lpszClassName	= WINDOW_CLASS_NAME;
winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

// save hinstance in global
hinstance_app = hinstance;

// register the window class
if (!RegisterClassEx(&winclass))
	return(0);

// create the window
if (!(hwnd = CreateWindowEx(NULL,                  // extended style
                            WINDOW_CLASS_NAME,     // class
						    "RPG_GAME_PROJECT", // title
						    WS_POPUP | WS_VISIBLE,
					 	    0,0,	  // initial x,y
						    SCREEN_WIDTH,SCREEN_HEIGHT,  // initial width, height
						    NULL,	  // handle to parent 
						    NULL,	  // handle to menu
						    hinstance,// instance of this application
						    NULL)))	// extra creation parms
return(0);

// save main window handle
main_window_handle = hwnd;

// initialize game here
Game_Init();

// enter main event loop
while(TRUE)
	{
    // test if there is a message in queue, if so get it
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	   { 
	   // test if this is a quit
       if (msg.message == WM_QUIT)
           break;
	
	   // translate any accelerator keys
	   TranslateMessage(&msg);

	   // send the message to the window proc
	   DispatchMessage(&msg);
	   } // end if
    
       // main game processing goes here
       Game_Main();
       
	} // end while

Game_Shutdown();


return(msg.wParam);

} // end WinMain

///////////////////////////////////////////////////////////


bool bump(int x,int y,int** Rec)
{
         
	if(x<=0||x+35>=1024) return false;
	if(y<=0||y+55>=768)  return false;
	for(int i=0;Rec[i][0];i++)
      		if((x>=Rec[i][0]&&x<=Rec[i][1])||(x>=Rec[i][0]-55&&x<=Rec[i][1]-55))
              		if(y>=Rec[i][2]&&y<=Rec[i][3]-95)    return false;                                      
		return true;		
}

int tiangong()
{
/*
	lpddsbackground[0] 玉帝头
	lpddsbackground[2] 后羿头
	lpddsotherpeople[0]  玉帝

*/	
		// copy background to back buffer
		if (FAILED(lpddpal->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap[1].palette)))
			return(0);

		DDraw_Draw_Surface(lpddsbackground[1],0,0, SCREEN_WIDTH,SCREEN_HEIGHT, lpddsback,0);    
				
		//	if(KEYDOWN(VK_LEFT))
		
		if(!mark)
		{
			lpddsbackground[0]->Release();
		
			mark=1;
		}
		if(mark==1)
		{
			if(mark_1==0)
			{
				DDraw_Draw_Surface(yuditou,20,630,101,130,lpddsback,1);
				DDraw_Draw_Surface(talkbar,110,645,898,93,lpddsback,1);
				Draw_Text_GDI("后羿,你来求见朕有何急事,速速上殿报来。",150,690,255,lpddsback);
				if(count++>60||KEYDOWN(VK_SPACE))
				{
					mark_1=1;
					count=0;
					Sleep(300);
				}

			}
			
			
			if(mark_1==1)
			{
				DDraw_Draw_Surface(houyitou,20,630,100,130,lpddsback,1);
				DDraw_Draw_Surface(talkbar,110,645,898,93,lpddsback,1);
				Draw_Text_GDI("臣领旨!",150,690,255,lpddsback);
				if(count++>60||KEYDOWN(VK_SPACE))
				{
					mark=2;
					count=0;
					mark_1=0;
					Sleep(50);
				}

			}
			
		}
		
		if(mark==2)
		{
			

			if(!mark_1)
			{
				int **mapinfo=(int **)malloc(4*4);
				for(int i=0;i<4;i++)
					mapinfo[i]=(int *)malloc(4*4);	
				mapinfo[0][0]=1;
				mapinfo[0][1]=250;
				mapinfo[0][2]=1;
				mapinfo[0][3]=200;
				mapinfo[1][0]=250;
				mapinfo[1][1]=773;
				mapinfo[1][2]=1;
				mapinfo[1][3]=300;
				mapinfo[2][0]=773;
				mapinfo[2][1]=1023;
				mapinfo[2][2]=1;
				mapinfo[2][3]=200;
				mapinfo[3][0]=0; 
				HouYi.DrawPeople(mapinfo);
				for( i=0;i<4;i++)
					free(mapinfo[i]);
				free(mapinfo);
				if(HouYi.get_x()>375&&HouYi.get_x()<661&&HouYi.get_y()>200&&HouYi.get_y()<250)
					mark_1=1;
			}
			if(mark_1==1)
			{
				if(cy<90)
					cy+=5;
				DDraw_Draw_Surface(lpddsotherpeople[0],cx,cy,73,137, lpddsback,1);
				DDraw_Draw_Surface(HouYi.lpdds[2][2],HouYi.get_x(),HouYi.get_y(),120,120,lpddsback,1);
				if(cy>=90)
				{
					mark=3;
					mark_1=0;
					count++;
				}
			}
		}
		if(mark==3)
		{
			static char*a[10];
			static int i=0;
			count++;
		
			a[0]="禀报玉帝,臣得报,妖孽无视天威,肆虐民间,百姓深受其苦。臣愿请缨,下凡为民除此一害,望玉帝恩准!";
			a[1]="朕也闻得此事。既然你有此意愿,朕就成全你。后羿听命:";
			a[2]="臣在!";
			a[3]="朕命你下凡前去剿灭妖孽,速速前往,不得有误。";
			a[4]="臣领命!";
			a[5]="";
			a[6]="aj";
			//DDraw_Draw_Surface(lpddsbackground[1],0,0,SCREEN_WIDTH,SCREEN_HEIGHT,lpddsback,1);
			if(count<=50)
			{
				DDraw_Draw_Surface(houyitou,20,630,100,130,lpddsback,1);
				if(count==50)
					i++;
			}
			else
				DDraw_Draw_Surface(yuditou,20,630,101,130,lpddsback,1);

			if(count==100)
			{
				count=0;
				i++;
			}
			DDraw_Draw_Surface(lpddsotherpeople[0],cx,cy,73,137, lpddsback,1);
			DDraw_Draw_Surface(HouYi.lpdds[2][2],HouYi.get_x(),HouYi.get_y(),120,120,lpddsback,1);
			DDraw_Draw_Surface(talkbar,110,645,898,93,lpddsback,1);
			Draw_Text_GDI(a[i],150,690,255,lpddsback);		
			if(i==5)
			{

⌨️ 快捷键说明

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