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

📄 mainfrm.cpp

📁 2D即时战略游戏VC源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			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);
    }
    }


	if(direction==UP)
	{if(table[i+posite.L+1][j+posite.H+1].bsthbottom==TRUE)
		{//if(table[i+posite.L+1][j+posite.H+2].tree.rcPic.bottom==54)
		//l=21;
		//else l=12;    

	/*		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,
			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);
		}
	
	if(table[i+posite.L+1][j+posite.H+1].whatin==TREE)
	    
	{if(table[i+posite.L+1][j+posite.H+1].tree.rcPic.bottom==54)
	   {l=24;d1=9;}
	//else {l=15;d1=12;}
		
	/*	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+d1,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.right-table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,
			   l,//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+d1,
				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+d1,
			   table[i+posite.L+1][j+posite.H+1].tree.rcPic.right-table[i+posite.L+1][j+posite.H+1].tree.rcPic.left,
			   l,//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+d1,
			   DDBLTFAST_SRCCOLORKEY);
		 

		}
 
	  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;
		else l=24;//for hill    

			/*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,
			   l,//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+1].tree.rcPic.left,
			   l,//table[i+posite.L+1][j+posite.H+2].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+1].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+1].tree.rcPic.top,
			   DDBLTFAST_SRCCOLORKEY);
		}
	
    

	}
   

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

   

	}
 

 B=firstbuild;
 do {

  if(B->Next==NULL){if(B!=firstbuild)B->Draw();break;}
  B=B->Next;
  if(B->Prev!=firstbuild)
	    B->Prev->Draw();
 }while(B);


 
UpdateFrame(); 
}    




void ViewRadar(void)
{Blt(lpDDPP,RADARx,RADARy,RADARWIDTH,RADARHEIGHT,RadarBack,0,0);
 ViewRect(0);
 
 }

 
 
void InitRadar()
{RECT des,src;
 int i,j;
 Building *B;
 
src.left=0,src.top=0;src.right=BS;src.bottom=BS;

for(i=0;i<BACKGROUNDWIDTH/2;i++)
 {for(j=0;j<BACKGROUNDHEIGHT/2;j++)
  {Blt(lpDDPP,RADARx+4*i,RADARy+4*j,4,4,PicBlack,0,0);
   des.left=i*4;des.top=j*4;des.right=(i+1)*4;des.bottom=(j+1)*4;
   RadarBack->Blt(&des,Floor[table[i*2+1][j*2+1].blocktype],&src,DDBLT_ALPHASRC,NULL);
  }
 }




 B=firstbuild;
 do {  
  B=B->Next;
  if(B!=NULL)
  {  src=B->rcPic;  
     des.left=B->nowpos.x/12;des.top=B->nowpos.y/12;
	 des.right=B->nowpos.x/12+(B->rcPic.right-B->rcPic.left)/12;
     des.bottom=B->nowpos.y/12+(B->rcPic.bottom-B->rcPic.top)/12;
     RadarBack->Blt(&des,B->mysurf,&src,DDBLT_KEYSRC,NULL);
  }
 }while(B);

for(i=0;i<BACKGROUNDWIDTH;i++)
 {for(j=0;j<BACKGROUNDHEIGHT;j++)
  {
	
switch(table[i+posite.L+1][j+posite.H+1].whatin)
{case TREE:
case HILL:
     if(table[i+posite.L+1][j+posite.H+1].bsthright==FALSE)
     {src=table[i+posite.L+1][j+posite.H+1].tree.rcPic;  
     des.left=table[i+posite.L+1][j+posite.H+1].tree.nowpos.x/12;
	 des.top=table[i+posite.L+1][j+posite.H+1].tree.nowpos.y/12;
	 des.right=des.left+(table[i+posite.L+1][j+posite.H+1].tree.rcPic.right-table[i+posite.L+1][j+posite.H+1].tree.rcPic.left)/12;
	 des.bottom=des.top+(table[i+posite.L+1][j+posite.H+1].tree.rcPic.bottom-table[i+posite.L+1][j+posite.H+1].tree.rcPic.top)/12;
     RadarBack->Blt(&des,table[i+posite.L+1][j+posite.H+1].tree.mysurf,&src,DDBLT_KEYSRC,NULL);
	 }
     break;

	
  }   
   

 
    }
  }
  


//ViewRadar();
}  
 
 

POINT MoveMetal(POINT first,POINT last,int speed)
{int errorterm=0;                                     
 int L=last.x-first.x;
 int H=last.y-first.y;
 if((last.x==first.x)&&(last.y==first.y))return first;
 if((H<L)&&(H>=0))
   {   first.x+=speed;
         first.y+=speed*H/L;
	}
                       
 else  if((H>=L)&&(L>0))
   { first.y+=speed;
     first.x+=speed*L/H;
	}
 
else  if((H>-L)&&(L<=0))
   {first.y+=speed;
    first.x+=speed*L/H;
	} 
else  if((H<=-L)&&(H>0))
   {  first.x-=speed;
      first.y-=speed*H/L;
 } 
 else if((H>L)&&(H<=0))
   {  first.x-=speed;
    	     first.y-=speed*H/L;
  } 
    
 else   if((H<=L)&&(L<0))
   {  first.y-=speed;
        first.x-=speed*L/H;
     }             
 else if((-H>L)&&(L>=0))
   {  first.y-=speed;
  	  first.x-=speed*L/H;
   }
         
  else if((-H<=L)&&(L>0))
   {    first.x+=speed;
   	     first.y+=speed*H/L;
    }
    return first;   
 }    


POINT GetCellAsigned(POINT mouse)
{ float l,h;
  if(mouse.y==480)mouse.y=479;
  l=(float)mouse.x/CS;
  h=(float)mouse.y/CS;
  int mouseonscrL=(int)mouse.x/CS;
  int mouseonscrH=(int)mouse.y/CS;
  if(mouseonscrL>l)mouseonscrL-=1; 
  if(mouseonscrH>h)mouseonscrH-=1;
  
  POINT CellAsigned;
  CellAsigned.x=mouseonscrL+posite.L;
  CellAsigned.y=mouseonscrH+posite.H;
  return(CellAsigned);
}  
						  
						  
						  

POINT BackgroundToScreen(POINT cell)                                              
{
	POINT Scrposite;
	Scrposite.x=cell.x-posite.L*BS/2;
	Scrposite.y=cell.y-posite.H*BS/2;                                            
	return(Scrposite);
}              


												
void myarmy::Move()
{ int HALF;
   POINT objectplace=placetogo; 
   POINT beforeHL=nowHL;
   POINT goat=nowHL;
   bStop=FALSE;
      
   int errorterm=0;
  if(part!=0)
  {MoveOneUnit(this,befHL,nowHL);
    }
      
  else
  { if ((nowHL.x==placetogo.x)&&(nowHL.y==placetogo.y))
        
	    {firstdot=ZEROPOINT;
	    //maxl=ZEROPOINT;
	     state=STAY;
	     //firstHL=placetogo;
	     nowdir=0;
	     bStop=TRUE;
	     return;}  
   objectplace=Howtogo(nowHL,dect,objectplace,this,table); 
   if(objectplace.y==-99){
	   state=WAIT;
	   waittime=10;
	   return;}
   else if(objectplace.x==-1)
       {//maxl=ZEROPOINT;
	     nowdir=0;
//	     firstHL=placetogo;
		 state=STAY;
	     //bStop=TRUE;
	     return;}  
  else if(!((objectplace.x==placetogo.x)&&(objectplace.y==placetogo.y)))
	  {
	   if(MoveOneUnit(this,nowHL,objectplace))
	   {befHL=nowHL;
	   nowHL=objectplace;
	   //if(nowHL.y>maxl.y)maxl.y=nowHL.y;
	   //if(nowHL.x>maxl.x)maxl.x=nowHL.x;
	   }
	  }
	
  else {  
	
    if(((objectplace.x-goat.x)>(objectplace.y-goat.y))&&((objectplace.y-goat.y)>=0)
	 &&((objectplace.x-goat.x)!=0)) 
    {// dect=EAST;
    
       HALF=(placetogo.x-goat.x)/2;  
    
    { goat.x=goat.x+1;
		   
      errorterm=errorterm+(placetogo.y-goat.y);
      
      if(errorterm>HALF) 
	 {errorterm=errorterm-(placetogo.x-goat.x);
	 
	   goat.y=goat.y+1;
	  }
       if(MoveOneUnit(this,beforeHL,goat))
       {befHL=beforeHL;
       beforeHL=goat; 
       nowHL=goat;}
     }    
       //if(goat.y>maxl.y)maxl.y=goat.y;
       //if(goat.x>maxl.x)maxl.x=goat.x;
	   
	       
      
    } 
    
     else  if((objectplace.x-goat.x)<=(objectplace.y-goat.y)
					&&((objectplace.x-goat.x)>0))
					
	 
    {HALF=(objectplace.y-goat.y)/2;
    // dect=EASTSOUTH;
    {  goat.y=goat.y+1;
	   errorterm=errorterm+(objectplace.x-goat.x);
      
       if(errorterm>HALF) 
	 {errorterm=errorterm-(objectplace.y-goat.y);
	 
	   goat.x=goat.x+1;
	  }   
     if(MoveOneUnit(this,beforeHL,goat))
      
       {befHL=beforeHL;
      beforeHL=goat;
      nowHL=goat; }
    		  
       
   } 
   
   //if(goat.y>maxl.y)maxl.y=goat.y;
   //if(goat.x>maxl.x)maxl.x=goat.x;
   } 
   
   else  if((objectplace.x-goat.x)<(objectplace.y-goat.y)
					&&((objectplace.y-goat.y)<=0)
					&&(objectplace.x-goat.x)<0)
	 
    {HALF=-(objectplace.y-goat.y)/2;
     //dect=WEST;
   
	{  goat.x=goat.x-1;
		   
       errorterm=errorterm-(objectplace.y-goat.y);
      
       if(errorterm>HALF) 
	 {errorterm=errorterm+(objectplace.x-goat.x);
	 
	   goat.y=goat.y-1;
	  }   
      if(MoveOneUnit(this,beforeHL,goat)) 
      {befHL=beforeHL;
      beforeHL=goat; 
      nowHL=goat; }
       
		 
     }                       
     
   //if(goat.y>maxl.y)maxl.y=goat.y;
    //if(goat.x>maxl.x)maxl.x=goat.x;
	      
     } 
	   
	   
     else  if((objectplace.x-goat.x)>=(objectplace.y-goat.y)
					&&((objectplace.x-goat.x)<0))
	 
    {HALF=-(objectplace.x-goat.x)/2;
     //dect=WESTNORTH;
    
	  
      {goat.y=goat.y-1;
		   
       errorterm=errorterm-(objectplace.x-goat.x);
      
       if(errorterm>HALF) 
	 {errorterm=errorterm+(objectplace.y-goat.y);
	 
	   goat.x=goat.x-1;
	  }   
      if(MoveOneUnit(this,beforeHL,goat)) 
     {befHL=beforeHL;
      beforeHL=goat;
      nowHL=goat;     }
		
     }  
     
    //if(goat.y>maxl.y)maxl.y=goat.y;
    //if(goat.x>maxl.x)maxl.x=goat.x;
	   
     
     }  
     
     
     
  
     
     
     else  if((-objectplace.x+goat.x)<(objectplace.y-goat.y)
					&&((objectplace.y-goat.y)>0)
					&&((objectplace.x-goat.x)<=0))
	 
    {HALF=(objectplace.y-goat.y)/2;
  //   dect=SOUTH;
    
     { goat.y=goat.y+1;
		   
       errorterm=errorterm-(objectplace.x-goat.x);
      
       if(errorterm>HALF) 
	 {errorterm=errorterm-(objectplace.y-goat.y);
	 
	   goat.x=goat.x-1;
	  }   
      if(MoveOneUnit(this,beforeHL,goat))
      {befHL=beforeHL;
      beforeHL=goat;
      nowHL=goat; }    
		
     } 
     
     //if(goat.y>maxl.y)maxl.y=goat.y;
     //if(goat.x>maxl.x)maxl.x=goat.x;
	   
     
     }   
     
     
       else  if((-objectplace.x+goat.x)>=(objectplace.y-goat.y)
					&&((objectplace.y-goat.y)>0)
					&&((objectplace.x-goat.x)<0))
	 
    {HALF=-(objectplace.x-goat.x)/2;
    //  dect=WESTSOUTH;
    
     { goat.x=goat.x-1;
		   
       errorterm=errorterm+(objectplace.y-goat.y);
      
       if(errorterm>HALF) 
	 {errorterm=errorterm+(objectplace.x-goat.x);
	 
	   goat.y=goat.y+1;
	  }   
      if(MoveOneUnit(this,beforeHL,goat))
       {befHL=beforeHL;
       beforeHL=goat; 
       nowHL=goat;    }
	
     }  
     
     //if(goat.y>maxl.y)maxl.y=goat.y;
     //if(goat.x>maxl.x)maxl.x=goat.x;
	   
     
     } 
     
     
else  if((

⌨️ 快捷键说明

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