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

📄 mainfrm.bak

📁 2D即时战略游戏源码.仿红色警戒之类的。不过有点粗糙
💻 BAK
📖 第 1 页 / 共 5 页
字号:
				}   
			}	            
			
		     
				break;          
		case WM_LBUTTONDOWN:
			    mouse.x=LOWORD(lParam);
			    mouse.y=HIWORD(lParam);//+19;//"19" is for the title bar.
			    cellasigned=GetCellAsigned(mouse);
			   
			    MouseProc(mouse,WM_LBUTTONDOWN);
			    
			  	    
			 break;
	 
		case WM_RBUTTONDOWN:
			    mouse.x=LOWORD(lParam);
			    mouse.y=HIWORD(lParam);
			    MouseProc(mouse,WM_RBUTTONDOWN);//+19;//"19" is for the title bar.
			  
			     break; 
		case WM_RBUTTONUP:
			    mouse.x=LOWORD(lParam);
			    mouse.y=HIWORD(lParam);
			    MouseProc(mouse,WM_RBUTTONUP);//+19;//"19" is for the title bar.
			  
			     break;	     
		case WM_MOUSEMOVE:
			 mouse.x=LOWORD(lParam);
			 mouse.y=HIWORD(lParam);
			 if(wParam==MK_LBUTTON)
			   MouseProc(mouse,WM_MOUSEMOVE&&MK_LBUTTON); 
			 else 
			   MouseProc(mouse,WM_MOUSEMOVE);
				
				break;     
				
		case WM_LBUTTONUP:
			    mouse.x=LOWORD(lParam);
			    mouse.y=HIWORD(lParam);
			    MouseProc(mouse,WM_LBUTTONUP);
			    break;

         case UM_LAUNCH:
       
        // start the game in rest mode
        ProgramState = MUD;
        //LaunchGame();
        return 1;

    case UM_ABORT:
        return 1;
		
       	
		case WM_DESTROY:

			finiObjects();
			CleanupInput();
			hWnd=NULL;
			hWindow=hWnd;                                       
			ghWndMain=hWnd;
			bActive=FALSE;
			PostQuitMessage(0);
			break;
		default:
		//	if(lParam!=KF_ALTDOWN)
			  return(DefWindowProc(hWnd,message,wParam,lParam));
			
	 }

   
	return(0);
}                      




void go(POINT cell)    //when mouse L-button down
{ int Lx,Ly; 
 
  soldier=firstsoldier;
   while(soldier->Next)  
    {soldier=soldier->Next;   
     if((soldier->active==TRUE)&&(soldier->bStop==FALSE))
      {soldier->captain=NULL;
       soldier->placeready=cell;
       } 
     else if((soldier->active==TRUE)&&(soldier->bStop==TRUE))
       { soldier->captain=NULL;
        soldier->bStop=FALSE;
		 soldier->state=WALK;
         soldier->placetogo=cell;
         soldier->placeready=cell;
         soldier->maxl.x=0;
         soldier->maxl.y=0;
     
       }  
     
   }  
  
}   


myarmy::myarmy()
{}
bullet::bullet()
{}
Exp::Exp()
{}
Building::Building()
{}

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


   myarmy *s;
   firstsoldier->Prev=0;
   soldier=new myarmy(2,5,WE,TANK);
   soldier->Prev=firstsoldier;
   firstsoldier->Next=soldier;
   WeTankNum++;
   
   s=new myarmy(23,23,ENEMY,TANK);
   s->Prev=soldier;
   soldier->Next=s;
   soldier=s;
   EnemyTankNum++;
   
   s=new myarmy(23,19,ENEMY,TANK);
   s->Prev=soldier;
   soldier->Next=s;
   soldier=s;      
   EnemyTankNum++;
   
   s=new myarmy(2,2,WE,FIXCAR);
   s->Prev=soldier;
   soldier->Next=s;
   soldier=s;
   WeTankNum++;
   
  
   s=new myarmy(3,5,WE,TANK);
   s->Prev=soldier;
   soldier->Next=s;
   soldier=s;
   WeTankNum++;
   
   
   s=new myarmy(5,5,WE,TANK);  
   s->Prev=soldier;
   soldier->Next=s;
   soldier=s;
   soldier->Next=NULL;            
   WeTankNum++;
   
  /* 
   build=new Building(25,25,ENEMY,TANKFACTORY);
   build->Prev=firstbuild;
   firstbuild->Next=build;
   
   
   build->Next=new Building(3,3,WE,TANKFACTORY);
   build->Next->Prev=build;
   build=build->Next;
   build->Next=NULL;
   */
  
  
}  


myarmy::myarmy(int x,int y,int tanktype,int tankID)
{nowHL.x=x;
 nowHL.y=y;
 befHL=nowHL;
 nextHL=nowHL;
 type=tanktype;
 family=tankID;
   if(tanktype<ENEMY)
       {view=TRUE; 
        blood=100;
        protect=80;
		mysurf=Enemy[0];
        }
     else  
       {view=FALSE;
       blood=150;
       protect=50;
	   mysurf=Myarmy[0];
       } 
       
      
     dead=FALSE; 
     captain=NULL;
     
//     killenemy=0;
      
     rcPic.left=0;
	 rcPic.top=0;
	 rcPic.right=40;
	 rcPic.bottom=40;


	 nowpos.x=nowHL.x*BS;
	 nowpos.y=nowHL.y*BS;
	 lastpos=nowpos;
	 nextpos=lastpos;

     damage=0;
     state=STAY; 
     bAround=FALSE;
	 around=0;
     attack=12;
     station=nowHL;
     waittime=0; 
     fixtime=0;
     bCallFix=FALSE;
     speed=2;
     fight=FALSE;
     fighttime=0;
     
     nowdir=SOUTH;
	 dect=0;
     bStop=TRUE;
     active=FALSE;
     placetogo=nowHL; 
     placeready=placetogo;
     
     part=0;
      
     maxl.x=0;
     maxl.y=0;

	 table[x+1][y+1].whatin=CAR;
     table[x+1][y+1].CarOb=this;
	 table[x+1][y+1].tree.mysurf=mysurf;
	 table[x+1][y+1].tree.rcPic=rcPic;
	 table[x+1][y+1].tree.nowpos=nowpos;

 
     
    if(tanktype<ENEMY)
     {	FlashBlock(); 
        Draw();
      //  FlashRadar(1);
	 	  
	
	 	
	}
		  	 	   
	if(tankID==FIXCAR)
          { protect=90;
            attack=4;
            blood=192;
            fixcar.tanknum=this; 
            fixcar.bFIX=FALSE;
            fixcar.bCALL=FALSE;
            fixcar.fixlevel=50;
          }
    
} 




void myarmy::Free()
{this->Prev->Next=this->Next;
 if(this->Next)
    this->Next->Prev=this->Prev;
 delete this;
} 
 


void OnFight()
{ soldier=firstsoldier;
 do   {
 soldier=soldier->Next;
 if(soldier==NULL)break;
 if(soldier->Prev!=firstsoldier)
     soldier->Prev->DoMyThings();
 }while(soldier);
 soldier=firstsoldier;    
  
 /* bull=firstbull;
  do{
    bull=bull->Next;
	bull->Prev->DoMyThings();
  }while(bull);
	 
	exp=firstexp;
  do {exp=exp->Next; 
	  exp->Prev->DoMyThings();
	  }	while(exp);
 
 build=firstbuild;
do {build=build->Next;
    build->Prev->DoMyThings();
  }while(build);
	 
*/  
}


				
				
				
				
				
void myarmy::FlashBlock(void)
{int j=-3;
 int i=-2;
 int flash=0;
 int viewshape; 
 int d=0;
 
  
 
  for(int k=1;k<37;k++)
    
	{ viewshape=0;
	  if(k==1||k==2||k==3){i++;viewshape=6;}
	  
	  else if(k==4){i=-2;j=-2;viewshape=2;}
	  else if(k==5||k==6||k==7){i++;}
	  else if(k==8){i++;viewshape=3;}
	  else if(k==9){i=-3;j=-1;viewshape=9;}
	  else if(k==10||k==11||k==12||k==13||k==14){i++;}
	  else if(k==15){i++;viewshape=7;}
	  else if(k==16){i=-3;j=0;viewshape=9;}
	  else if(k==17||k==18){i++;}
	  else if(k==19){i=1;j=0;}
	  else if(k==20){i++;}
	  else if(k==21){i++;viewshape=7;}
	  else if(k==22){i=-3;j=1;viewshape=9;}
	  else if(k==23||k==24||k==25||k==26||k==27){i++;}
	  else if(k==28){i++;viewshape=7;}
	  else if(k==29){i=-2;j=2;viewshape=5;}
	  else if(k==30||k==31||k==32){i++;}
	  else if(k==33){i++;viewshape=4;}
	  else if(k==34){i=-1;j=3;viewshape=8;}
	  else if(k==35||k==36){i++;viewshape=8;}
	
	

	    
  if(((nowHL.x+i)>=0)&&((nowHL.x+i)<32)
	   &&((nowHL.y+j)>=0)&&((nowHL.y+j)<32)) 
   {int x=(nowHL.x+i-posite.L)*BS;
   	int y=(nowHL.y+j-posite.H)*BS;   
  		  
	  if(viewshape!=0)
	  {  
	      if(table[nowHL.x+i+1][nowHL.y+j+1].displaystate!=0)
		  {  table[nowHL.x+i+1][nowHL.y+j+1].displaystate=viewshape;                     //for pics[shape[]]
	    
			  Blt(lpDDPP,RADARx+(nowHL.x+i-posite.L)*4,RADARy+(nowHL.y+j-posite.H)*4,BS,BS,
			        RadarBack,(nowHL.x+i-posite.L)*4,(nowHL.y+j-posite.H)*4);
           	                    
				 if((nowHL.x+i+1-posite.L>=0)&&(nowHL.x+i+1-posite.L<=11)
 		    		&&(nowHL.y+j+1-posite.H>=0)&&(nowHL.y+j+1-posite.H<=11))
				 	  Blt(lpShape,x,y,BS,BS,PicShape,(viewshape)*42+2,2);
					 
				 
		  }
		 	    	 
	  
	  }
	  
   	  
  else 
		  
  { 
	  
	  
	  table[nowHL.x+i+1][nowHL.y+j+1].displaystate=0;
	  Blt(lpDDPP,RADARx+(nowHL.x+i-posite.L)*4,RADARy+(nowHL.y+j-posite.H)*4,4,4,
			        RadarBack,(nowHL.x+i-posite.L)*4,(nowHL.y+j-posite.H)*4);
           	                    
				 if((nowHL.x+i-posite.L>=0)&&(nowHL.x+i-posite.L<=11)
 		    		&&(nowHL.y+j-posite.H>=0)&&(nowHL.y+j-posite.H<=11))
				 	    Blt(lpShape,x,y,BS,BS,PicShape,1,1);
					
				 

    }
   }
  }
	
     if((flash==1)&&(((nowHL.x-posite.L>=8)&&(nowHL.x-posite.L<=14))
                  ||((nowHL.x-posite.L<=3)&&(nowHL.x-posite.L>=-3))
       			||((nowHL.y-posite.H>=8)&&(nowHL.y-posite.H<=14))
         		||((nowHL.y-posite.H<=3)&&(nowHL.x-posite.L>=-3))))
               ViewRect(1);
		      
   
 
} 
 

 
 
 
 
 
void CarSelect(POINT cell)
{POINT lefttop,XY; 
 BOOL success=FALSE; 
 RECT rect;
 int recttemp;
 int num=0;
 
 /*    
 
 if((cell.x==-1)&&(cell.y==-1))
    {if((grouprect.right-grouprect.left)<0){recttemp=grouprect.right;
    										grouprect.right=grouprect.left;
    										grouprect.left=recttemp;}	
     if((grouprect.bottom-grouprect.top)<0){recttemp=grouprect.bottom;
                                            grouprect.bottom=grouprect.top;
                                            grouprect.top=recttemp;}
    
    
    lefttop.x=grouprect.left;
 	lefttop.y=grouprect.top;
 	lefttop=GetCellAsigned(lefttop);
 	rect.left=lefttop.x;
 	rect.top=lefttop.y;
 
 	lefttop.x=grouprect.right;
 	lefttop.y=grouprect.bottom;
 	lefttop=GetCellAsigned(lefttop);
 	rect.right=lefttop.x;
 	rect.bottom=lefttop.y;
    
    if(rect.right-rect.left==0)
       rect.right++; 
    if(rect.bottom-rect.top==0)
       rect.bottom++;
   BOOL bHave=FALSE;   
   soldier=firstsoldier;
    while(soldier->Next)
       { soldier=soldier->Next;  
       if(PtInRect(&rect,soldier->nowHL)&&(soldier->dead==FALSE))
          {bHave=TRUE;
           break;
          }  
       
       }    
             
  soldier=firstsoldier;           
  while(soldier->Next)
  {soldier=soldier->Next;
  success=FALSE;
    
      
      if(PtInRect(&rect,soldier->nowHL)&&(soldier->dead==FALSE))
         
    {	num++;
        
      
     if(num<=6)
     {  success=TRUE;
	    tankinfo.tanknum=soldier;
	      XY.x=(soldier->nowHL.x-posite.L)*BS;
          XY.y=(soldier->nowHL.y-posite.H)*BS;
  
      	
      	soldier->active=TRUE;
	  	soldier->waittime=0;
	  	if(soldier->bStop==TRUE)
	  	{if(soldier->type<ENEMY)
	  	   	Rect(Screen,XY,BS,1);   
	    else Rect(Screen,XY,BS,2);
	    // if(soldier->type<ENEMY)
	  	   	//Rect(FrontDC,XY,BS,1);   
	    //	else Rect(FrontDC,XY,BS,2);
	  
		  
	    }     
	  	
	 
	 }  
   }	 
	 	 	   
   if(((!PtInRect(&rect,soldier->nowHL))||(success==FALSE))
 		
 		&&(soldier->active==TRUE)&&(bHave==TRUE)
 		&&(soldier->nowHL.x-posite.L>=0)&&(soldier->nowHL.y-posite.H>=0)      
       &&(soldier->nowHL.x-posite.L<12)&&(soldier->nowHL.y-posite.H<12))
  
     {    XY.x=(soldier->nowHL.x-posite.L)*BS;
         XY.y=(soldier->nowHL.y-posite.H)*BS;
  
	 soldier->Draw();
   	 
      soldier->active=FALSE;                        
    }                            
		 
 

  
   
 }
    
 
} 
    
    
else  */

{if(table[cell.x+1][cell.y+1].whatin==CAR)
       {table[cell.x+1][cell.y+1].CarOb->active=TRUE;
		table[cell.x+1][cell.y+1].CarOb->Draw();
        }
            
 
                   
soldier=firstsoldier;                  
while(soldier->Next)
 {soldier=soldier->Next; 
  
   if((soldier->active==TRUE)&&(!((soldier->nowHL.x==cell.x)&&(soldier->nowHL.y==cell.y)))
 			&&(soldier->nowHL.x-posite.L>=0)&&(soldier->nowHL.y-posite.H>=0)      
       &&(soldier->nowHL.x-posite.L<10)&&(soldier->nowHL.y-posite.H<10))
      {XY.x=soldier->nowpos.x-posite.L*BS;
       XY.y=soldier->nowpos.y-posite.H*BS;
  
	   soldier->active=FALSE;
    

⌨️ 快捷键说明

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