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

📄 mainfrm.bak

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

 
 
}    




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

 
 
void InitRadar()
{RECT des,src;

src.left=0,src.top=0;src.right=BS;src.bottom=BS;

for(int i=0;i<BACKGROUNDWIDTH;i++)
 {for(int j=0;j<BACKGROUNDHEIGHT;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+1][j+1].blocktype],&src,DDBLT_ALPHADEST,NULL);
  }
 }

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/BS;
  h=(float)mouse.y/BS;
  int mouseonscrL=(int)mouse.x/BS;
  int mouseonscrH=(int)mouse.y/BS;
  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;
	Scrposite.y=cell.y-posite.H*BS;                                            
	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(befHL,nowHL);
    }
      
  else
  { if ((nowHL.x==placetogo.x)&&(nowHL.y==placetogo.y))
        
	    {maxl=ZEROPOINT;
	     
	     //firstHL=placetogo;
	     nowdir=NULL;
	     bStop=TRUE;
	     return;}  
   objectplace=Howtogo(nowHL,dect,objectplace,soldier,table); 
   if(objectplace.y==-99){waittime=10;return;}
   if(objectplace.x==-1)
       {maxl=ZEROPOINT;
	     nowdir=NULL;
//	     firstHL=placetogo;
	     bStop=TRUE;
	     return;}  
  else if(!((objectplace.x==placetogo.x)&&(objectplace.y==placetogo.y)))
	  {
	   if(MoveOneUnit(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(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(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(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(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(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(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=NORTH;
    
     { 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(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=EASTNORTH;
    
	
     { 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(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;
	   
  }  
  
  
 }          
 }         
 
}   
    
	

BOOL MoveOneUnit(POINT now,POINT goat)
{soldier->part++;
 if(soldier->part>=8)soldier->part=0;
 soldier->nowdir=DecideDect(now,goat);
 soldier->lastpos=soldier->nowpos;
 soldier->nowpos.x=soldier->lastpos.x+(goat.x-now.x)*BS/6;
 soldier->nowpos.y=soldier->lastpos.y+(goat.y-now.y)*BS/6;
 //table[nowHL.x+1][nowHL.y+1].tree.mysurf=soldier->mysurf;
 soldier->Draw();

	
return TRUE;
}




int DecideDect(POINT firstpace,POINT secondpace)
{ int dect=0;

  int Lx=secondpace.x-firstpace.x;
  int Ly=secondpace.y-firstpace.y;
  if(Ly==0&&Lx>0)dect=EAST;
  if(Ly==0&&Lx<0)dect=WEST;
  if(Lx==0&&Ly>0)dect=SOUTH;    
  if(Lx==0&&Ly<0)dect=NORTH;
  if(Lx>0&&Ly>0)dect=EASTSOUTH;
  if(Lx>0&&Ly<0)dect=EASTNORTH;
  if(Lx<0&&Ly>0)dect=WESTSOUTH;
  if(Lx<0&&Ly<0)dect=WESTNORTH;  
  
  return(dect);
 } 
			
			

	   
void MouseProc(POINT mouse,int state)
{ 
  
  POINT cell;
  
 // mouse.x--;
  //mouse.y--;
  if(mouse.x<PANELWIDTH) 
  	cell=GetCellAsigned(mouse);
  	
if(ProgramState==PLAYING)
{switch(state)
      {case WM_LBUTTONDOWN:
	    if(mouse.x<PANELWIDTH)
	       {  
	       
		  
		  
		      }       
		else if((mouse.x>(480+RADARx))&&(mouse.x<(480+RADARx+RADARWIDTH))
			 &&(mouse.y>(RADARy))&&(mouse.y<(RADARy+RADARHEIGHT)))
			 {  ViewRadarRect(mouse);
			 			  
			 }       
		else if((mouse.x>=540)&&(mouse.x<576)
			 &&(mouse.y>400)&&(mouse.y<425))	 
			 { command=GREATPOWER;
			 }  
			 
		else if((mouse.x>580)&&(mouse.x<620)&&(mouse.y<425)&&(mouse.y>400))
		         {
                    tankinfo.tanknum->bCallFix=TRUE;
                    buttonCall=TRUE;
		         }
		       	 
			    
		 break;  
		 
	case WM_MOUSEMOVE&&MK_LBUTTON:
	      if(mouse.x<PANELWIDTH)
	         {SetCursor(selectcur);
     
	          GroupSelect(mouse);
	          groupselect=TRUE;
	          }
		 break;
		 
	case WM_LBUTTONUP:
		   if(groupselect==TRUE)
		     {cell.x=-1;cell.y=-1;//for group
		      CarSelect(cell); 
		      mouse.x=-99;//for GroupSelect
		      GroupSelect(mouse);
		      groupselect=FALSE;
		      
		      if(table[cell.x+1][cell.y+1].whatin<HILL)
		                       SetCursor(LoadCursor(NULL,IDC_UPARROW));
		      
		      }
		 else if(mouse.x<PANELWIDTH)
		  {
		   if((table[cell.x+1][cell.y+1].whatin>=CAR)
		     &&(table[cell.x+1][cell.y+1].displaystate==0))
		          {SetCursor(selectcur);
                   
		              CarSelect(cell);    
					  
		           
		          } 
		   else if(table[cell.x+1][cell.y+1].whatin<HILL)
		   
		      {  SetCursor(goatcur);
		     
		         go(cell);  
     
			    } 
			    
		  }  
		  else if(buttonCall==TRUE)
		            {//WinGBitBlt(OperPlanDC,100,400,39,25,WinGDC,pics[122].x,pics[122].y);
                     buttonCall=FALSE;
                     }
		         
		         
		         
		         
		 
		 
		 
		 break;     
		 
	case WM_RBUTTONUP:
		   if(table[cell.x+1][cell.y+1].whatin>=HILL)
		                       SetCursor(selectcur);
		     
		  
		  break;
	case WM_MOUSEMOVE:          
	
	if(mouse.x>PANELWIDTH)
	{
     SetCursor(operatecur);
     }
	  
	else { 
	    cell=GetCellAsigned(mouse);
	    if(table[cell.x+1][cell.y+1].whatin==HILL)
		    { 
		      SetCursor(cross);}
		      
	    else if((table[cell.x+1][cell.y+1].whatin>=CAR)
	            &&(table[cell.x+1][cell.y+1].displaystate==0))
			 {SetCursor(selectcur);}  
		     
	

⌨️ 快捷键说明

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