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

📄 mainfrm.bak

📁 2D即时战略游戏源码.仿红色警戒之类的。不过有点粗糙
💻 BAK
📖 第 1 页 / 共 5 页
字号:

    // connect to the lobby
    hr = DPLobbyConnect();

    if ( hwndStatus )
    {
        // get rid of the connectino status window
        DestroyWindow(hwndStatus);
    }

    if (FAILED(hr))
    {
        initFail("IDS_DPLOBBY_ERROR_C");
        goto FAIL;
    }

    // create our player
    hr = DPlayCreatePlayer(
                            &gOurID,
#ifdef UNICODE
                            glpdplConnection->lpPlayerName->lpszShortName,
#else
                            glpdplConnection->lpPlayerName->lpszShortNameA,
#endif
                            NULL,
                            NULL,
                            0
                          );

    if (FAILED(hr))
    {
        initFail("IDS_DPLOBBY_ERROR_C");
        goto FAIL;
    }


    // cleanup
    hr = DPLobbyRelease();
    if (FAILED(hr))
    {
        initFail("IDS_DPLOBBY_ERROR_C");
        goto FAIL;
    }

    // we were lobbied
    return TRUE;

FAIL:
    // cleanup and exit
    DPLobbyRelease();
    //ExitGame();
    return FALSE;
}



void InitMessageBuffers(void)
{gHostMsg.byType=MSG_HOST;
 gBuildMsg.byType=MSG_BUILD;
 gFireMsg.byType=MSG_FIRE;
 gMoveMsg.byType=MSG_MOVE;
 gCallFixMsg.byType=MSG_CALLFIX;
 gTalkMsg.byType=MSG_TALK;
}

void InitMudGame(void)
{  HRESULT hr;

	// were we launched by a lobby ?
    if (LaunchedByLobby())
    {
        // start game
        PostMessage(WinMain, UM_LAUNCH, 0, 0);
        bMud = TRUE;
    }


    
    // initialize global message buffers
    InitMessageBuffers();

    // update window title
//    UpdateTitle();

    // get current session description (glpdpSD is initialized in here)
    hr = DPlayGetSessionDesc();
    if ((FAILED(hr)) || (!glpdpSD))
    {
        initFail("IDS_DPLAY_ERROR_GSD");
        return;
    }


}

/*
 * updateFrame
 * 
 * Decide what needs to be blitted next, wait for flip to complete,
 * then flip the buffers.
 */

void UpdateFrame( void )
{ 
   RECT rect;
   rect.left=rect.top=0;
   rect.right=rect.bottom=480;
   if(ProgramState!=PLAYING)
   {switch(ProgramState)
      {case SPLASH:
             BltSplash();
			 ProgramState=GETSELECT;
			 	  //InitInput
			InitInput(ghinst,ghWndMain);


		

			 break;
       case GETSELECT:
		    if(ProcessKeys()==MUD)
				ProgramState=MUD;
			else if(ProcessKeys()==ALONE)
				ProgramState=ALONE;
			//Flip();
			break;
       case ALONE:
            InitAloneGame();
			ProgramState=PLAYING;
			break;
       case MUD:
		   InitMudGame();
		   ProgramState=GETCONNECT;
            break;
        }
   return;
   }
		   

  
    // Blit the stuff for the next frame
 
   
 // JFBlt(lpDDSBack, 0, 0, 480,480,lpShape,0,0,
 //           DDBLTFAST_SRCCOLORKEY );
	    
  JFBlt(lpDDSBack, 480, 0, 160,480,lpDDPP,0,0,
           DDBLTFAST_NOCOLORKEY );

  //JFBlt(lpDDSBack, 0, 0, 160,160,lpDDSBack,160,160,
   //        DDBLTFAST_NOCOLORKEY );


// if(lpShape->UpdateOverlay(&rect,lpDDSPrimary,&rect,DDOVER_SHOW,NULL)!=DD_OK);  
  //  initFail("Overlay Fail");
  
  Flip(); 

} /* updateFrame */



/*
 * restoreAll
 *
 * restore all lost objects
 */
HRESULT restoreAll( void )
{int i;
    HRESULT     ddrval;

    ddrval = lpDDSPrimary->Restore();
    if( ddrval == DD_OK )
    {

		ddrval = lpDDSBack->Restore();
		if(ddrval!=DD_OK)return ddrval;

		ddrval=lpGround->Restore();
		if(ddrval!=DD_OK)return ddrval;

        for(i=0;i<FLOORNUM;i++)
		  {ddrval = Floor[i]->Restore();
			if(ddrval!=DD_OK)return ddrval;
		  }	
        for(i=0;i<BUILDNUM;i++)
		  {ddrval = Build[i]->Restore();
			if(ddrval!=DD_OK)return ddrval;
		  }	
        for(i=0;i<MYARMYNUM;i++)
		  {ddrval = Myarmy[i]->Restore();
			if(ddrval!=DD_OK)return ddrval;
		}	
        for(i=0;i<ENEMYNUM;i++)
		  {ddrval = Enemy[i]->Restore();
			if(ddrval!=DD_OK)return ddrval;
		}	
        for(i=0;i<EXPNUM;i++)
		  {ddrval = PicExp[i]->Restore();
			if(ddrval!=DD_OK)return ddrval;
		}	
         
        for(i=0;i<BULLETNUM;i++)
		  {ddrval =PicBullet[i]->Restore();
			if(ddrval!=DD_OK)return ddrval;
		}	
        ddrval = PicRect->Restore();
			if(ddrval!=DD_OK)return ddrval;
        ddrval = PicShape->Restore();
			if(ddrval!=DD_OK)return ddrval;
        ddrval = PicWhite->Restore();
			if(ddrval!=DD_OK)return ddrval;
        ddrval = PicBlack->Restore();
			if(ddrval!=DD_OK)return ddrval;
//        InitSurfaces();
           
        
    }
    return ddrval;

} /* restoreAll */





/*----------------------------------------------------------------------------*\
| AppExit()                                                                    |
|                                                                              |
| Description:                                                                 |
|   App is just about to exit, cleanup.                                        |
|                                                                              |
\*----------------------------------------------------------------------------*/
void AppExit(HWND Window)
{// ReleaseCapture();
  
} 


       

static BOOL InitDib()
{int i;
 char File[32];
 for (i=0;i<FLOORNUM;i++)
 {sprintf(File,"bmp\\tile%d.bmp",i);
    	
  Floor[i]=DDLoadBitmap(lpDD,File,0,0);
  DDSetColorKey(Floor[i],CLR_INVALID);
  if(Floor[i]==NULL)return initFail(NULL);
 }
 for (i=0;i<BUILDNUM;i++)
 {sprintf(File,"bmp\\build%d.bmp",i);
    	
  Build[i]=DDLoadBitmap(lpDD,File,0,0);
  DDSetColorKey(Build[i],CLR_INVALID);
  if(Build[i]==NULL)return initFail(NULL);
 }
  
 for (i=0;i<MYARMYNUM;i++)
 { sprintf(File,"bmp\\tank%d.bmp",i);
    	
  Myarmy[i]=DDLoadBitmap(lpDD,File,0,0);
   DDSetColorKey(Myarmy[i],CLR_INVALID);
  if(Myarmy[i]==NULL)return initFail(NULL);
 }
 
 for (i=0;i<ENEMYNUM;i++)
 { sprintf(File,"bmp\\tank%d.bmp",i);
    	
  Enemy[i]=DDLoadBitmap(lpDD,File,0,0);
   DDSetColorKey(Enemy[i],CLR_INVALID);
  if(Enemy[i]==NULL)return initFail(NULL);

 }
 for (i=0;i<EXPNUM;i++)
 { sprintf(File,"bmp\\exp%d.bmp",i);
    	
  PicExp[i]=DDLoadBitmap(lpDD,File,0,0);
   DDSetColorKey(PicExp[i],CLR_INVALID);
  if(PicExp[i]==NULL)return initFail(NULL);
 }
 for (i=0;i<BULLETNUM;i++)
 { sprintf(File,"bmp\\bullet%d.bmp",i);
    	
  PicBullet[i]=DDLoadBitmap(lpDD,File,0,0);
   DDSetColorKey(PicBullet[i],CLR_INVALID);
  if(PicBullet[i]==NULL)return initFail(NULL);
 }
 for (i=0;i<OTHERSNUM;i++)
 { sprintf(File,"bmp\\others%d.bmp",i);
    	
  Others[i]=DDLoadBitmap(lpDD,File,0,0);
   DDSetColorKey(Others[i],CLR_INVALID);
  if(Others[i]==NULL)return initFail(NULL);
 }
 
  PicRect=DDLoadBitmap(lpDD,"bmp\\rect.bmp",0,0);
   DDSetColorKey(PicRect,CLR_INVALID);
  if(PicRect==NULL)return initFail(NULL);

 PicShape=DDLoadBitmap(lpDD,"bmp\\shape.bmp",0,0);
   DDSetColorKey(PicShape,RGB(128,128,128));
  if(PicShape==NULL)return initFail(NULL);

   PicWhite=DDLoadBitmap(lpDD,"bmp\\white.bmp",0,0);
   DDSetColorKey(PicWhite,CLR_INVALID);
  if(PicWhite==NULL)return initFail(NULL);

   PicBlack=DDLoadBitmap(lpDD,"bmp\\Black.bmp",0,0);
   DDSetColorKey(PicBlack,CLR_INVALID);
  if(PicBlack==NULL)return initFail(NULL);

return TRUE;
}


 

void InitBackground(int state)
{for(int i=0;i<10;i++)
 {for(int j=0;j<10;j++)
  {
	 //Blt(lpDDSBack,i*40,j*40,40,40,others[0],0,0);//others[0] is black
     //Blt(lpGround,i*40,j*40,40,40,others[0],0,0);
    Blt(lpGround,i*BS,j*BS,BS,BS,Floor[table[i+posite.L+1][j+posite.H+1].blocktype],0,0);
    JFBlt(lpDDSBack,i*BS,j*BS,BS,BS,Floor[table[i+posite.L+1][j+posite.H+1].blocktype],0,0,DDBLTFAST_NOCOLORKEY);
	//Blt(lpShape,i*BS,j*BS,BS,BS,PicShape,42+2,2);
   
switch(table[i+posite.L+1][j+posite.H+1].whatin)
{case TREE:
case CAR:
case BUILD:
		JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*BS,
			table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.right-table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+1].tree.mysurf,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
	  break;
case STHTOP|TREE:
case STHTOP|CAR:
case STHTOP|BUILD:
	       JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*BS,
			   table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.right-table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+1].tree.mysurf,
				table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
    JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+2].tree.nowpos.x-posite.L*BS,
		     table[i+posite.L+1][j+posite.H+2].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.right-table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+2].tree.mysurf,
				table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
		 break;
case STHTOP:
       JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+2].tree.nowpos.x-posite.L*BS,
		   table[i+posite.L+1][j+posite.H+2].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.right-table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+2].tree.mysurf,
				table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
	
    break;
	  
	
  }   
   

 
    }
  }
  
  for(int k=0;k<34;k++)
     {table[0][k].blocktype=HILL;
      table[0][k].whatin=HILL;
      
      table[k][0].blocktype=HILL;
      table[k][0].whatin=HILL;
      
      table[33][k].blocktype=HILL;
      table[33][k].whatin=HILL;
      
      table[k][33].blocktype=HILL;
      table[k][33].whatin=HILL;
      } 
   
 



      
} 


void InitGame()
{//InitConnect();
 ReadGameData(1);
  posite.L=0;
  posite.H=0;

 InitDib();
 InitBackground(0);
 InitOperPan();
 InitRadar();
 CarInit();
  
}

void InitOperPan()
{Blt(lpDDPP,0,0,160,160,Others[0],0,0);
Blt(lpDDPP,0,160,160,160,Others[0],0,0);
Blt(lpDDPP,0,320,160,160,Others[0],0,0);
}


 void ReadGameData(int dat)
{int i,j;
	for(i=0;i<34;i++)
  {for(j=0;j<34;j++)
     {table[i][j].blocktype=randInt(0,2);
     table[i][j].displaystate=1;
	 table[i][j].whatin=NULL;
	 //table[i][j].tree=NULL;
	 table[i][j].CarOb=NULL;
	 table[i][j].BuildOb=NULL;
    }
 }
/*
for(i=0;i<5;i++)
{for(j=0;j<5;j++)
{table[5+i][5+j].blocktype=1;
     table[5+i][5+j].displaystate=0;
}
}	 
*/

}


 
void ViewBackground(int direction)           
{int i=0,j=0; 
 int mm,nn,mo,no; 
 switch(direction)
 {case UP:
		mo=0;
		no=0;
		mm=10;
		nn=1;
	
		Blt(lpDDSBack,0,BS,480,480-BS,lpDDSBack,0,0);
	
        Blt(lpGround,0,BS,480,480-BS,lpGround,0,0);
		//Blt(lpShape,0,BS,480,480-BS,lpShape,0,0);
		
     
		break;
 case DOWN:
		mo=0;
		no=9;
		mm=10;
		nn=10;
		Blt(lpDDSBack,0,0,480,480-BS,lpDDSBack,0,BS);
		Blt(lpGround,0,0,480,480-BS,lpGround,0,BS);
      //  Blt(lpShape,0,0,480,480-BS,lpShape,0,BS);
     
		break;
 case RIGHT:
		mo=9;
		no=0;
		mm=10;
		nn=10;
		Blt(lpDDSBack,0,0,480-BS,480,lpDDSBack,BS,0);
        Blt(lpGround,0,0,480-BS,480,lpGround,BS,0);
       // Blt(lpShape,0,0,480-BS,480,lpShape,BS,0);
     
		break;
 case LEFT:
		mo=0;
		no=0;
		mm=1;
		nn=10;
		Blt(lpDDSBack,BS,0,480-BS,480,lpDDSBack,0,0);
       	Blt(lpGround,BS,0,480-BS,480,lpGround,0,0);
        //Blt(lpShape,BS,0,480-BS,480,lpShape,0,0);
     
		break;
 case ALL:
		mo=no=0;
		nn=10;
		mm=10;
		break;
 }
  //Blt(lpGround,0,0,480,480,lpDDSBack,0,0);
   

    for(j=no;j<nn;j++)
      {for(i=mo;i<mm;i++)
	{Blt(lpGround,i*BS,j*BS,BS,BS,Floor[table[i+posite.L+1][j+posite.H+1].blocktype],0,0);
     Blt(lpDDSBack,i*BS,j*BS,BS,BS,Floor[table[i+posite.L+1][j+posite.H+1].blocktype],0,0);
     //Blt(lpShape,i*40,j*40,40,40,PicShape,/*table[i+posite.L+1][j+posite.H+1].displaystate**/42+2,2);

	switch(table[i+posite.L+1][j+posite.H+1].whatin)
	{	case TREE:
		case CAR:
		case BUILD:
		JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*BS,
			table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.right-table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+1].tree.mysurf,
				table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
		break;
		case STHTOP|TREE:
		case STHTOP|CAR:
		case STHTOP|BUILD:
	       JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*BS,
			   table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.right-table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+1].tree.mysurf,
				table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,table[i+posite.L+1][j+posite.H+1].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
			JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+2].tree.nowpos.x-posite.L*BS,
				table[i+posite.L+1][j+posite.H+2].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.right-table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+2].tree.mysurf,
				table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
		 break;
		case STHTOP:
			JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+2].tree.nowpos.x-posite.L*BS,
				table[i+posite.L+1][j+posite.H+2].tree.nowpos.y-posite.H*BS,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.right-table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H+2].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H+2].tree.mysurf,
				table[i+posite.L+1][j+posite.H+2].tree.rcPic.left,table[i+posite.L+1][j+posite.H+2].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);
	
		break;
	  
	
		} 
   

⌨️ 快捷键说明

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