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

📄 mainfrm.cpp

📁 2D即时战略游戏VC源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{int l;
int treepos[310][2]={7,6,9,6,8,6,16,1,12,3,15,3,16,3,12,5,13,4,
                     15,5,16,6,10,6,10,7,11,7,12,7,13,7,16,7,18,7,
					 11,8,13,8,15,8,16,9,18,9,10,10,11,10,13,11,15,10,
					 17,10,18,10,19,10,12,12,15,12,17,12,21,14,

					 0,12,1,14,0,15,2,15,3,15,1,17,3,16,4,16,0,18,
                     1,18,2,18,4,18,3,21,4,20,5,20,0,22,2,21,3,21,5,22,
					 0,24,4,24,6,24,3,26,5,26,7,26,
					
					 0,38,2,40,0,41,2,42,0,43,3,43,0,45,2,45,5,45,7,45,
					 8,46,1,47,2,47,5,47,0,48,5,48,1,49,3,49,2,51,3,51,
					 4,51,0,53,4,53,1,56,3,55,4,56,0,57,1,58,2,59,3,59,
					 5,58,7,59,8,59,9,60,11,60,12,59,14,60,16,61,17,60,
					 8,61,9,62,10,61,13,61,15,62,17,62,18,63,9,63,12,63,
					 15,63,16,63,

					 54,52,55,53,57,53,58,53,60,52,61,58,
					 52,53,53,53,53,55,53,57,52,58,53,61,
					 54,59,55,58,56,58,58,57,59,59,62,59,
					 62,62,63,63,
					 
                     60,28,61,29,62,30,60,31,62,30,63,30,
					 56,32,57,32,59,32,61,32,62,32,55,33,
					 56,33,58,33,61,33,59,34,62,34,57,35,
					 58,35,59,35,62,35,63,35,59,36,61,36,
					 61,37,62,37,63,38,63,39,

					 32,0,35,0,36,0,37,0,39,0,41,0,45,0,46,0,
					 31,1,34,1,37,1,38,1,42,1,44,1,
					 30,2,33,2,35,2,38,2,43,2,42,2,46,2,
					 30,3,35,3,37,3,41,3,43,3,45,3,
					 33,4,36,4,38,4,39,4,
					 32,5,38,5,42,5,46,5,
					 29,6,31,6,34,6,37,6,46,6,
					 28,7,31,7,33,7,40,7,42,7,45,7,
					 28,8,32,8,32,8,42,8,46,8,48,8,
					 30,9,32,9,
					 31,10,
					 29,11,30,11,
					 29,13,30,13,
					 30,14,
					 30,15,31,15,
					 32,16,
					 33,18,
					 32,19,34,19,35,18,
					 33,20,34,20,35,20,
					 34,21,
					 32,22,35,22,37,22,
					 33,23,34,23,
					 32,24,36,24,37,24,
					 31,25,32,25,38,25,
					 31,26,36,26,
					 29,27,32,27,35,27,36,27,
                     29,28,34,28,
					 28,30,29,30,31,30,34,30,
					 28,32,33,32,
					 27,34,28,34,32,34,
                     27,36,33,36,
					 25,37,28,37,33,37,
					 25,38,30,38,
					 24,39,25,39,
					 23,40,24,40,
					 22,42,23,42,24,42,
					 22,43,24,43,
					 21,44,23,44,25,44,
					 22,45,25,45,
					 23,46,25,46,27,46,
					 25,47,27,47,29,47,

					 62,4,0,55,20,54,48,48,49,49,32,45,

                     56,1,56,3,55,4,57,6,58,8,59,9,61,9,62,8,63,7,55,0,57,5, 
                     8,53,10,53,11,53,37,31,39,31,
					 9,53,38,31,36,31,58,0,59,0,
						};

int hillpos[8][2]={10,12,0,28,32,8,26,39,21,56,25,60,32,62,55,59,};
int grid[16][2]={3,1,4,1,5,1,3,2,4,2,2,2,5,2,1,3,5,3,6,3,7,3,2,4,3,4,4,4,3,5,4,5};


for(int k=0;k<310;k++) 	
{if((k<270)||(k>290))
{table[treepos[k][0]+1][treepos[k][1]+1].whatin=TREE;
 //table[treepos[k][0]+2][treepos[k][1]+1].whatin=TREE;
table[treepos[k][0]+1][treepos[k][1]].bsthtop=TRUE;
table[treepos[k][0]+2][treepos[k][1]].bsthtop=TRUE;

table[treepos[k][0]+2][treepos[k][1]+1].bsthright=TRUE;
table[treepos[k][0]+1][treepos[k][1]+2].bsthbottom=TRUE;
table[treepos[k][0]+2][treepos[k][1]+2].bsthbottom=TRUE;


//table[treepos[k][0]+2][treepos[k][1]].bsthtop=TRUE;

  table[treepos[k][0]+1][treepos[k][1]+1].tree.mysurf=PicTree[0];//RANDOM THE TREE;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.left=0;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.top=0;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.right=38;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.bottom=54;
table[treepos[k][0]+1][treepos[k][1]+1].tree.nowpos.x=(treepos[k][0])*CS;
table[treepos[k][0]+1][treepos[k][1]+1].tree.nowpos.y=(treepos[k][1]-1)*CS+15;
}
else
{table[treepos[k][0]+1][treepos[k][1]+1].whatin=TREE;
 //table[treepos[k][0]+2][treepos[k][1]+1].whatin=TREE;
//table[treepos[k][0]+1][treepos[k][1]].bsthtop=TRUE;
//table[treepos[k][0]+2][treepos[k][1]].bsthtop=TRUE;

//table[treepos[k][0]+2][treepos[k][1]+1].bsthright=TRUE;
//table[treepos[k][0]+1][treepos[k][1]+2].bsthbottom=TRUE;
//table[treepos[k][0]+2][treepos[k][1]+2].bsthbottom=TRUE;


//table[treepos[k][0]+2][treepos[k][1]].bsthtop=TRUE;

table[treepos[k][0]+1][treepos[k][1]+1].tree.mysurf=PicTree[2];//RANDOM THE TREE;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.left=0;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.top=0;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.right=24;
table[treepos[k][0]+1][treepos[k][1]+1].tree.rcPic.bottom=27;
table[treepos[k][0]+1][treepos[k][1]+1].tree.nowpos.x=(treepos[k][0])*CS;
table[treepos[k][0]+1][treepos[k][1]+1].tree.nowpos.y=(treepos[k][1])*CS;
}
//table[treepos[k][0]+2][treepos[k][1]+1].tree.mysurf=PicTree[0];//RANDOM THE TREE;
//table[treepos[k][0]+2][treepos[k][1]+1].tree.rcPic.left=0;
//table[treepos[k][0]+2][treepos[k][1]+1].tree.rcPic.top=0;
//table[treepos[k][0]+2][treepos[k][1]+1].tree.rcPic.right=38;
//table[treepos[k][0]+2][treepos[k][1]+1].tree.rcPic.bottom=54;
//table[treepos[k][0]+2][treepos[k][1]+1].tree.nowpos.x=(treepos[k][0])*CS;
//table[treepos[k][0]+2][treepos[k][1]+1].tree.nowpos.y=(treepos[k][1]-1)*CS;

}


for(l=0;l<8;l++)
{for(int j=0;j<16;j++)
{if((j>2)&&(j<14))
  {table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].whatin=HILL;
   table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].bsthright=TRUE;
  }
else if(j>13)
   table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].bsthbottom=TRUE;

 else
 table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].bsthtop=TRUE;

if(l<7)
{table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.mysurf=PicHill[0];
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.left=0;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.top=0;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.right=180;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.bottom=110;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.nowpos.x=(hillpos[l][0])*CS;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.nowpos.y=(hillpos[l][1])*CS+10;
}
else 
{table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.mysurf=PicHill[1];
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.left=0;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.top=0;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.right=170;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.rcPic.bottom=78;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.nowpos.x=(hillpos[l][0])*CS;
table[hillpos[l][0]+grid[j][0]][hillpos[l][1]+grid[j][1]].tree.nowpos.y=(hillpos[l][1])*CS;
}

}
 table[hillpos[l][0]+3][hillpos[l][1]+2].bsthright=FALSE;
 
}
	
for(int m=0;m<13;m++)
 {for(int n=0;n<10;n++)
  {
	 //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,m*BS,n*BS,BS,BS,Floor[table[2*m+posite.L+1][2*n+posite.H+1].blocktype],0,0);
    JFBlt(lpDDSBack,m*BS,n*BS,BS,BS,Floor[table[2*m+posite.L+1][2*n+posite.H+1].blocktype],0,0,DDBLTFAST_NOCOLORKEY);
	//Blt(lpShape,i*BS,j*BS,BS,BS,PicShape,42+2,2);
}
} 

/*
for(int i=0;i<26;i++)
 {for(int j=0;j<20;j++)
  {
	
switch(table[i+posite.L+1][j+posite.H+1].whatin)
{case TREE:
 		JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*CS,
			table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*CS,
			   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(lpGround,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*CS,
			table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*CS,
			   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;

	
  }   
   

 
    }
  }*/
  
  for(l=0;l<66;l++)
     {table[0][l].blocktype=HILL;
      table[0][l].whatin=HILL;
      
      table[l][0].blocktype=HILL;
      table[l][0].whatin=HILL;
      
      table[65][l].blocktype=HILL;
      table[65][l].whatin=HILL;
      
      table[l][65].blocktype=HILL;
      table[l][65].whatin=HILL;
      } 


   
 



      
} 


void InitGame()
{//InitConnect();
    gwKeys=0;
    gbIsActive=FALSE; 
    bWeActive=FALSE;
    
  //  animEscnum=0;
    
   greenernum=2;
   treelost=0;
   treegot=0;
   treebasicnum=305;
   greenity=((float)treebasicnum)/50.0;
   activenum=0;


   firstbull=new bullet();
   firstexp=new Exp();
   firsttrack=new track();
   firstsoldier=new myarmy();
   firstbuild=new Building();
    firstbull->Prev=0;
    firstbull->Next=0;
    firstbull->life=0xFF;
    firstbull->getit=FALSE; 
    firstexp->Prev=0;
    firstexp->Next=0;
	firsttrack->Prev=0;
	firsttrack->Next=0;
//    firstexp->resttime=0xFF;   
    firstbuild->Prev=0;
    firstbuild->Next=0;
    firstbuild->life=0xFF;
    firstbuild->blood=0xFF;

	tankinfo.tanknum=NULL;
	tankinfo.blood=0;
	tankinfo.protect=0;
	tankinfo.attack=0;
	tankinfo.speed=0;
	tankinfo.view=0;
 
   
 ReadGameData(1);
  posite.L=0;//one unit as one block!!!!!!!!!
  posite.H=0;
 pnlxy.x=480;//for panel
 pnlxy.y=0;
 viewwidth=20;
 InitDib();
 CleanupSfx();
 
 InitSoundData();
 InitBuild();
 InitBackground(0);
 InitOperPan();
 InitRadar();
 CarInit();
 
 
 ViewRadar();
 ViewBackground(ALL);

}

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


 void ReadGameData(int dat)
{int i,j,rnd;

	for(i=0;i<66;i++)
  {for(j=0;j<66;j++)
     {
     table[i][j].displaystate=0;
	 table[i][j].bsthtop=FALSE;
	 table[i][j].bsthright=FALSE;
	 table[i][j].bsthbottom=FALSE;
	 table[i][j].whatin=NULL;
	 //table[i][j].tree=NULL;
	 table[i][j].CarOb=NULL;
	 table[i][j].BuildOb=NULL;
    }
 }
	for(i=0;i<32;i++)
  {for(j=0;j<32;j++)
     {rnd=randInt(0,FLOORNUM-1);
    table[i*2+1][j*2+1].blocktype=rnd;
	table[i*2+1][j*2+2].blocktype=rnd;
	table[i*2+2][j*2+1].blocktype=rnd;
	table[i*2+2][j*2+2].blocktype=rnd;
	}
  }

/*
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 d1,d2;
int l=0,d1=0;
 int mm,nn,mo,no; 
 int delta=0;
 if(panelview==FALSE)delta=3;
 myarmy *Ob;
 Building *B;
 switch(direction)
 {case UP:
		mo=0;
		no=0;
		mm=20+delta*2;
		nn=2;
		//for demo
//		d1=12;
//		d2=15;
	
		//Blt(lpDDSBack,0,BS,(10+delta)*BS,480-BS,lpDDSBack,0,0);
	
        Blt(lpGround,0,BS,(10+delta)*BS,480-BS,lpGround,0,0);
		//Blt(lpDDSBack,0,0,480,480-BS,lpGround,0,0);
		//Blt(lpShape,0,BS,480,480-BS,lpShape,0,0);
		
     
		break;
 case DOWN:
		mo=0;
		no=18;
		mm=20+delta*2;
		nn=20;
//		d1=0;
//		d2=12;
		//Blt(lpDDSBack,0,0,(10+delta)*BS,480-BS,lpDDSBack,0,BS);
		Blt(lpGround,0,0,(10+delta)*BS,480-BS,lpGround,0,BS);
	//	Blt(lpDDSBack,0,0,480,480-BS,lpGround,0,BS);
      //  Blt(lpShape,0,0,480,480-BS,lpShape,0,BS);
     
		break;
 case RIGHT:
		mo=18+delta*2;
		no=0;
		mm=20+delta*2;
		nn=20;
		//Blt(lpDDSBack,0,0,480+delta*BS-BS,480,lpDDSBack,BS,0);
        Blt(lpGround,0,0,480+delta*BS-BS,480,lpGround,BS,0);
	//	Blt(lpDDSBack,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=2;
		nn=20;
		//Blt(lpDDSBack,BS,0,(10+delta)*BS-BS,480,lpDDSBack,0,0);
       	Blt(lpGround,BS,0,(10+delta)*BS-BS,480,lpGround,0,0);
	//	Blt(lpDDSBack,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=20;
		mm=20+delta*2;
		break;
 }
  //Blt(lpGround,0,0,480,480,lpDDSBack,0,0);
   

    for(int n=no/2;n<nn/2;n++)
      {for(int m=mo/2;m<mm/2;m++)
	{Blt(lpGround,m*BS,n*BS,BS,BS,Floor[table[m*2+posite.L+1][n*2+posite.H+1].blocktype],0,0);
     //Blt(lpDDSBack,m*BS,n*BS,BS,BS,Floor[table[m*2+posite.L+1][n*2+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);

	}
	}
	
     Ob=firstsoldier;
 do  {
 
 if(Ob->Next==NULL){if(Ob!=firstsoldier)Ob->Draw();break;}
 Ob=Ob->Next;
 if(Ob->Prev!=firstsoldier)
     Ob->Prev->Draw();
 }while(Ob); 	
  
    for(j=no;j<nn;j++)
      {for(i=mo;i<mm;i++)
	{if((table[i+posite.L+1][j+posite.H+1].whatin==TREE)
	    ||((table[i+posite.L+1][j+posite.H+1].whatin==HILL)))
		   
		{
		
	/*	JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*CS,
			table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*CS,
			   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(lpGround,table[i+posite.L+1][j+posite.H+1].tree.nowpos.x-posite.L*CS,
			table[i+posite.L+1][j+posite.H+1].tree.nowpos.y-posite.H*CS,
			   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);
		 

		} 
   
	


	if(direction==DOWN)
	{if(table[i+posite.L+1][j+posite.H+1].bsthtop==TRUE)
	{//if(table[i+posite.L+1][j+posite.H+2].tree.rcPic.bottom==54)
	   //l=9;
	
			/*JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H+2].tree.nowpos.x-posite.L*CS,
				table[i+posite.L+1][j+posite.H+2].tree.nowpos.y-posite.H*CS,
			   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);
				*/
			JFBlt(lpGround,table[i+posite.L+1][j+posite.H+2].tree.nowpos.x-posite.L*CS,
			table[i+posite.L+1][j+posite.H+2].tree.nowpos.y-posite.H*CS,
			   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);
    }
	

	if(table[i+posite.L+1][j+posite.H+1].bsthbottom==TRUE)
	{
	
			/*JFBlt(lpDDSBack,table[i+posite.L+1][j+posite.H].tree.nowpos.x-posite.L*CS,
				table[i+posite.L+1][j+posite.H].tree.nowpos.y-posite.H*CS,
			   table[i+posite.L+1][j+posite.H].tree.rcPic.right-table[i+posite.L+1][j+posite.H].tree.rcPic.left,
			   table[i+posite.L+1][j+posite.H].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H].tree.rcPic.top,
			   table[i+posite.L+1][j+posite.H].tree.mysurf,
				table[i+posite.L+1][j+posite.H].tree.rcPic.left,table[i+posite.L+1][j+posite.H].tree.rcPic.top,
				DDBLTFAST_SRCCOLORKEY);

  */
			JFBlt(lpGround,table[i+posite.L+1][j+posite.H].tree.nowpos.x-posite.L*CS,

⌨️ 快捷键说明

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