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

📄 mainfrm.bak

📁 2D即时战略游戏源码.仿红色警戒之类的。不过有点粗糙
💻 BAK
📖 第 1 页 / 共 5 页
字号:
	       else   SetCursor( LoadCursor(NULL,IDC_UPARROW));}
	if((mouse.x<=1)&&(posite.L>=1))
				    {posite.L--;
				    
				     ViewRect(0);
					 ViewBackground(LEFT);}
	if((mouse.x>=638)&&((BACKGROUNDWIDTH-posite.L)>=11))
					{posite.L++;
					
					 ViewRect(0);
					 ViewBackground(RIGHT);} 
	if((mouse.y<=1)&&(posite.H>=1))
				   
				    {posite.H--;
				    
				    ViewRect(0);
				ViewBackground(UP);}      
	if((mouse.y>=478)&&((BACKGROUNDHEIGHT)-posite.H>=11))
				    { posite.H++;
				    
				    ViewRect(0);
					ViewBackground(DOWN);}                
					
					
				
					
	 break;
	 
	 
	case WM_RBUTTONDOWN:
	           
		       if(table[cell.x+1][cell.y+1].whatin==CAR)
		          {if(table[cell.x+1][cell.y+1].CarOb->type==WE)
		              
		            {  SetCursor(captaincur);
     
		            
		                        
		               soldier=firstsoldier;      
		               while(soldier->Next)
		               {soldier=soldier->Next;
		                   
		                 if(soldier->active==TRUE)
		                    {soldier->captain=table[cell.x+1][cell.y+1].CarOb;
		                   
		                    }
		                  
		                } 
           		     }
           		   }         
		         else if (((table[cell.x+1][cell.y+1].whatin==CAR)
		             ||(table[cell.x+1][cell.y+1].whatin==BUILD))
		             &&(table[cell.x+1][cell.y+1].displaystate==0))
		              { go(cell);   
		                soldier=firstsoldier;  
		                while(soldier->Next)
		                {soldier=soldier->Next;
		                 if(soldier->active==TRUE)
		                    {  if((abs(soldier->nowHL.x-cell.x)<=3) 
		                          &&(abs(soldier->nowHL.y-cell.y)<=3)
		                          &&(soldier->fighttime==0)) 
		                       {//soldier->fight=TRUE; 
           						
           						//soldier->state=FIGHTING;
           
		                       
		                        bull=firstbull;
                        		while(bull->Next)
            					 {bull=bull->Next;
            					 }
           						bull->Next=new bullet(soldier->nowHL,cell,1);
           						bull->Next->Prev=bull;
           						bull->Next->Next=NULL;
           						if(firstbull->Next==NULL)firstbull->Next=bull->Next;
           						soldier->fighttime=10;
		                        }
		              
		                     }
		                 }    
		                 
		                   
		                }   
		          
		          
			   //else  BackgroundEdit(GetCellAsigned(mouse));
	 break;             
			     
	 
	}                               
}		  
}                           
	   
void ViewRect(int way)
{
    int rectw=PANELWIDTH/BS*RADARBLOCK;
    int recth=PANELHEIGHT/BS*RADARBLOCK;
   POINT recttopleft;
   HPEN hpen,hpenold;
   recttopleft=RadarToScreen(rectnowpos); 
   Blt(lpDDPP,recttopleft.x,recttopleft.y,rectw,rectw,
				     RadarBack,rectnowpos.x*RADARBLOCK,rectnowpos.y*RADARBLOCK);     //wait for optimize
	 
	 
	 
	rectnowpos.x=posite.L;
    rectnowpos.y=posite.H;
   
    recttopleft=RadarToScreen(rectnowpos); 
	HDC ppDC;
	lpDDPP->GetDC(&ppDC);
    if (way==0) 
    	{hpen=CreatePen(PS_SOLID,1,RGB(255,255,255));		     
	    hpenold=SelectObject(ppDC,hpen); 
	    }
					     
	else if(way==2)
		{hpen=CreatePen(PS_SOLID,1,RGB(255,0,0));		     
	    hpenold=SelectObject(ppDC,hpen); 
	    }
	else          
			 			     
        	{hpen=CreatePen(PS_SOLID,1,RGB(255,255,255));		     
	    hpenold=SelectObject(ppDC,hpen); 
	    }
	
  			  MoveToEx(ppDC,recttopleft.x,recttopleft.y,NULL);           
			  LineTo(ppDC,recttopleft.x+rectw-1,recttopleft.y);
			  LineTo(ppDC,recttopleft.x+rectw-1,recttopleft.y+recth-1);          
			  LineTo(ppDC,recttopleft.x,recttopleft.y+recth-1);                                       
			  LineTo(ppDC,recttopleft.x,recttopleft.y);
			  
			  
			  
			  SelectObject(ppDC,hpenold);
			  DeleteObject(hpen);    
    			lpDDPP->ReleaseDC(ppDC);

  	  
	          			  
}                         

void ViewRadarRect(POINT mouse)
{ int rectw=PANELWIDTH/BS*RADARBLOCK;//(int)((float)PANELWIDTH/(BS*BACKGROUNDWIDTH)*RADARWIDTH);
  int recth=PANELHEIGHT/BS*RADARBLOCK;//(int)((float)PANELHEIGHT/(BS*BACKGROUNDHEIGHT)*RADARHEIGHT);
 
  POINT radarcell; 
   radarcell=ScreenToRadar(mouse);
   posite.L=radarcell.x-rectw/(RADARBLOCK*2);
   posite.H=radarcell.y-recth/(RADARBLOCK*2);
  if(mouse.x<(480+RADARx+rectw/2)){posite.L=0;}
 else if(mouse.x>(480+RADARx+RADARWIDTH-rectw/2-1))
      {
	   posite.L=BACKGROUNDWIDTH-PANELWIDTH/BS;
	}
			  
	 if(mouse.y<(RADARy+recth/2))
	  {posite.H=0;}
	 else if(mouse.y>(RADARy+RADARHEIGHT-recth/2-1))
	  {posite.H=BACKGROUNDHEIGHT-PANELHEIGHT/BS;
	    }
			  
		
		ViewRect(1);	  
		ViewBackground(ALL);  
}


POINT RadarToScreen(POINT r)
{POINT s;
 s.x=r.x*RADARBLOCK+RADARx;
 s.y=r.y*RADARBLOCK+RADARy;
 return(s);
 }
 
POINT ScreenToRadar(POINT s)
{POINT r;
 r.x=(s.x-RADARx-480)/RADARBLOCK; 
 r.y=(s.y-RADARy)/RADARBLOCK;
 return(r);
 }  


int  PASCAL WinMain(HINSTANCE hInst,HINSTANCE hPreInst,LPSTR lpszCmdLine,
					int nCmdShow)
					
{   HWND hWnd;
	MSG lpMsg;
	WNDCLASS wcApp; 
	HRESULT ddrval;
	DDSURFACEDESC       ddsd;
    DDSCAPS             ddscaps;
	nCmdShow=SW_SHOWMAXIMIZED; 

	
	// Clear the System Palette so that WinGStretchBlt runs at full speed.
//    ClearSystemPalette();
    operatecur=LoadCursor(hInst,MAKEINTRESOURCE(IDC_OPERATE));
    cross=LoadCursor(hInst,MAKEINTRESOURCE(IDC_ACROSS));
	selectcur=LoadCursor(hInst,MAKEINTRESOURCE(IDC_SELECT));
	captaincur=LoadCursor(hInst,MAKEINTRESOURCE(IDC_CAPTAIN));
	goatcur=LoadCursor(hInst,MAKEINTRESOURCE(IDC_GOAT));	  
	   
	
	if(!hPreInst){
		wcApp.lpszClassName=szAppName;
		wcApp.hInstance    =hInst;
		wcApp.lpfnWndProc=GameProc;
		wcApp.hCursor=operatecur;
		wcApp.hIcon=LoadIcon(NULL,IDI_APPLICATION);
		wcApp.style      =CS_BYTEALIGNWINDOW ;
		wcApp.lpszMenuName=NULL;
		wcApp.hbrBackground=GetStockObject(BLACK_BRUSH);
		wcApp.cbClsExtra=0;
		wcApp.cbWndExtra=0;
		if (!RegisterClass (&wcApp))
			return FALSE;
      }                 


   hWnd=CreateWindow(szAppName,"POWER",WS_POPUP|WS_CLIPCHILDREN,
				     0,0,640,480,
					(HWND)NULL,(HMENU)NULL,
					(HANDLE)hInst,(LPSTR)NULL);
					
   hWindow=hWnd;                                       
   ghWndMain=hWnd;
   ghinst=hInst;
   // ShowWindow(hOperPlan,SW_HIDE);
	ShowWindow(hWnd,nCmdShow);
	//SetFocus(hWnd);
	//SetCapture(hWnd);
	//UpdateWindow(hWnd); 
	

  
	  /*
     * create the main DirectDraw object
     */


    ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
    if( ddrval != DD_OK )
    {
        return initFail("DirectDrawCreat Fail");
    }

    // Get exclusive mode
    ddrval = lpDD->SetCooperativeLevel( hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN |DDSCL_NOWINDOWCHANGES );
    if( ddrval != DD_OK )
    {
        return initFail("SetCooperativeLevel Fail");
    }

    // Set the video mode to 640x480x16
    ddrval = lpDD->SetDisplayMode( 640, 480, 16);
    if( ddrval != DD_OK )
    {
        return initFail("SetDisplayMode Fail");
    }

    // Create the primary surface with 1 back buffer
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
                          DDSCAPS_FLIP |
                          DDSCAPS_COMPLEX;
    ddsd.dwBackBufferCount = 1;
    ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
    if( ddrval != DD_OK )
    {
        return initFail("Primary Surface Create Fail");
    }


	


    ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
    ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack);
    if( ddrval != DD_OK )
    {
        return initFail("Back Buffer Create Fail");
    }  


	ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS| DDSD_CKSRCOVERLAY;
    ddsd.ddsCaps.dwCaps =DDSCAPS_OVERLAY;
   // ddsd.dwWidth = 480;
   // ddsd.dwHeight = 480;

	
    ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpShape);
    if( ddrval != DD_OK )
    {
        return initFail("Shape Surface Create Fail");
    }
	DDSetColorKey(lpShape,RGB(255,255,255));
    /*ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpShape);
	  if( ddrval != DD_OK )
    {
        return initFail(hWnd);
    }*/
   
    // Create a Direct Draw Palette and associate it with the front buffer
//    lpDDPal = DDLoadPalette(lpDD, "bmp\\build0.bmp");

  //  if (lpDDPal)
    //    lpDDSPrimary->SetPalette( lpDDPal );

  
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
    ddsd.dwWidth = 480;
    ddsd.dwHeight = 480;

    if (lpDD->CreateSurface(&ddsd, &lpGround, NULL) != DD_OK)
        return NULL;

  /*  if (lpDD->CreateSurface(&ddsd, &lpShape, NULL) != DD_OK)
        return NULL;
    DDSetColorKey(lpShape,RGB(255,255,255));*/

    ddsd.dwWidth = 160;
    ddsd.dwHeight = 480;
     if (lpDD->CreateSurface(&ddsd, &lpDDPP, NULL) != DD_OK)
        return NULL;
   ddsd.dwWidth = RADARWIDTH;
    ddsd.dwHeight = RADARHEIGHT;
     if (lpDD->CreateSurface(&ddsd, &RadarBack, NULL) != DD_OK)
        return NULL;
 

      // Create a timer to flip the pages
    if( !SetTimer( hWnd, TIMER_ID, TIMER_RATE, NULL ) )
    {
        return initFail("Timer Create Fail");
    }










      ProgramState=SPLASH;
      while( 1 )
    {
		if(PeekMessage( &lpMsg, NULL, 0, 0, PM_NOREMOVE ) )
		{
			if( !GetMessage( &lpMsg, NULL, 0, 0 ) )
				{AppExit(hWnd); 
				return lpMsg.wParam;
				}
			TranslateMessage(&lpMsg); 
			DispatchMessage(&lpMsg);
		}
	 if(bActive){if(bMud) ReceiveMessages();
                 UpdateFrame();
	          }
	    
		else   WaitMessage();
	  }
    
		    
	
  
}



long FAR PASCAL GameProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)

{DWORD dwTid;
 DWORD dwRetCode;	 

	switch(message)
	{case WM_CREATE:
            bActive=TRUE;
			ProgramState=READY;
			SetCursor(operatecur);
            		
   
    /*         SetWindowPos(
  

            hWnd,	// handle of window
			HWND_TOPMOST,	// placement-order handle
			0,	// horizontal position
			0,	// vertical position
			640,	// width
			480,	// height
			SWP_NOREDRAW 	// window-positioning flags
			);*/

		//	SetFocus(hWnd);
		   	break; 
	 
		case WM_PAINT:
		     BeginPaint(hWnd,&ps);
		//	 if((ProgramState==GETSELECT)||(ProgramState==SPLASH))
		//		 BltSplash();
			 EndPaint(hWnd,&ps); 
		     
			break; 
			
			
			
		
	    case WM_TIMER: 
	            if(ProgramState==PLAYING)
		         { 
		           OnFight();
		          

		          } 
		       
		       
		           
		           
		      
			break;	
	
       	case WM_KEYDOWN:
		    
		    if(groupselect==FALSE)
			{switch(wParam){
				case VK_UP:
					if(Hack==TRUE)
							HackMove(VK_UP);	    
				    else if(posite.H>=1)
				   
				    {posite.H--;
				    
				    
				    ViewRect(0);
					ViewBackground(UP);}
					break;
				case VK_DOWN:
				    if(Hack==TRUE) 
				            HackMove(VK_DOWN);	    
				    else if((BACKGROUNDHEIGHT)-posite.H>=11)
				    {				    
				    posite.H++;
				    
				    
				    ViewRect(0);
					ViewBackground(DOWN);}
					break;
				case VK_LEFT:
				     if(Hack==TRUE)
				         {  ArrowKey=VK_LEFT;
							HackMove(VK_LEFT);
						  }		    
				    else if(posite.L>=1)
				    {posite.L=posite.L-1;
				    
				    ViewRect(0);
					ViewBackground(LEFT);}
					break;
				case VK_RIGHT:
				     if(Hack==TRUE)
				          { ArrowKey=VK_RIGHT;
							HackMove(VK_RIGHT);	    
							}
				    else if((BACKGROUNDWIDTH-posite.L)>=11)
				    {posite.L=posite.L+1;
				    
				    ViewRect(0);
					ViewBackground(RIGHT);}
					
					
					
					break;  
				case VK_F5:
					gwKeys=VK_F5;
					break;
                case VK_F6:
					gwKeys=VK_F6;
					break;
               					
				case 'H':
					  if(Hack==FALSE)Hack=TRUE;
					  else Hack=FALSE;
					  
					  break;
					  
					  
				case VK_CONTROL:
					  HackMove(VK_CONTROL);
					  break;
				
				 case VK_RETURN:
		           if( (ProgramState ==GETSELECT))
				     {
					// get connection settings from user
                    
					Guid=DoWizard(pv);
						//ghThread = CreateThread(NULL, 0, DoWizard, 0, 0, &dwTid);
					}
                    break;
	  
				case VK_SPACE:
					 //MixSound();
					 //WaveMix("6.wav");
					 
				     break;   
			
			    case VK_F1:
			         Gold+=200;
			         break;
	
			
				       
				   // menuselect=ShowMenu(hWnd);
			        //gamestate=MENU;
			     
			        //MenuProc(hWnd);
			    
		    
				
				 
				    break;
			    case 'a':
			         
			         
			        // tank[CarNum].Next=new myarmy;
			        // CarNum++;
			         
			    
			    	 break;

			

                case VK_ESCAPE: 
				
				 //   GameActive=FALSE;
				    KillTimer(hWnd,MyTimer);
				  //  if(gamestate==PLAYING)
				      EndPlay();
                     PostMessage(hWnd,WM_DESTROY,NULL,NULL);


	             break;		
				 
				case VK_TAB:
					break;
				     
					

⌨️ 快捷键说明

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