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

📄 gameobject.h

📁 一个类似于街机的小游戏
💻 H
📖 第 1 页 / 共 5 页
字号:
						blue_mindx=blue_dx;
						blue_mindy=blue_dy;
					}
				}
			}///end for 过后就找到了最近的兰色飞机了?
			//////查询卫星中离导弹最近的
			for(int weixing=0;weixing<MAX_NUM_WEIXING;weixing++)
			{
				int weixing_dx,weixing_dy,weixing_length;
				if(Weixing_state[weixing]==ALIVE)
				{
					    weixing_dx=Weixing[weixing].x-Daodan[i].x+45;
				    	weixing_dy=Weixing[weixing].y-Daodan[i].y+40;

					    weixing_length=Fast_Distance_2D(weixing_dx,weixing_dy);

					if(weixing_length<weixing_min)
					{
						weixing_min=weixing_length;

						weixing_mindx=weixing_dx;
						weixing_mindy=weixing_dy;	
					}
				}
			}///end 过后就找到了卫星的
/////////////////与老王的距离/////////////////////////////////////////////////////
			if(Boss_state==ALIVE)
			{
				
				boss_mindx=Boss.x-Daodan[i].x+80;
				boss_mindy=Boss.y-Daodan[i].y+80;

				boss_min=Fast_Distance_2D(boss_mindx,boss_mindy);
			}
           
			if(yellow_min > blue_min)
			{
               length1=blue_min;
			   dx1=blue_mindx;
			   dy1=boss_mindy;
			}
			else 
			{
			   length1=yellow_min;
			   dx1=yellow_mindx;
			   dy1=yellow_mindy;
			}
            
			if(weixing_min < boss_min)
			{
               length2=weixing_min;
			   dx2=weixing_mindx;
			   dy2=weixing_mindy;
			}
			else
			{
				length2=boss_min;
				dx2=boss_mindx;
				dy2=blue_mindy;
			}

		    if(length1 > length2)
			{
				length=length2;
				dx=dx2;
				dy=dy2;
			}
			else
			{
				length=length1;
				dx=dx1;
				dy=dy1;
			}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////所得dx,dy和length为离导弹最近的那个敌人的改变矢量。。
			if(!length)
			{
				length=1;
			}
			dx=Rate * dx / length;
			dy=Rate * dy / length;

			

			Daodan[i].xv+=dx;
			Daodan[i].yv+=dy;
			
			length=Fast_Distance_2D(Daodan[i].xv,Daodan[i].yv);

			if(length > MAX_DAODAN_SPEED)
			{
			  Daodan[i].xv*=0.6;
			  Daodan[i].yv*=0.6;
			}
		///找到导弹的位置。。
			Daodan[i].x+=Daodan[i].xv;
			Daodan[i].y+=Daodan[i].yv;
///////////////////////////////////////////////////////////////////
			//求得导弹的位置。。下面是导弹应该取哪张图。
			if(Daodan[i].yv<0)
			{
                 if(Daodan[i].xv <0)
				 {
					 if(Daodan[i].yv > Daodan[i].xv)
					 {
						 Set_Animation_BOB(&Daodan[i],13);
					 }
					 else if(Daodan[i].yv < Daodan[i].xv)
					 {
						 Set_Animation_BOB(&Daodan[i],15);
					 }
					 else Set_Animation_BOB(&Daodan[i],14);
				 }
				 else if(Daodan[i].xv > 0)
				 {
					 if(Daodan[i].xv > (-Daodan[i].yv))
					 {
						 Set_Animation_BOB(&Daodan[i],3);
					 }
					 else if(Daodan[i].xv < (-Daodan[i].yv))
					 {
						 Set_Animation_BOB(&Daodan[i],1);
					 }
					 else Set_Animation_BOB(&Daodan[i],2);
				 }
				 else Set_Animation_BOB(&Daodan[i],0);
			}//end Daodan[i].yv < 0
			else if(Daodan[i].yv==0)
			{
				if(Daodan[i].xv>0)  Set_Animation_BOB(&Daodan[i],4);
				
				else  Set_Animation_BOB(&Daodan[i],12);
			}
            else if(Daodan[i].yv > 0)
			{
				if(Daodan[i].xv < 0)
				{
					if(Daodan[i].yv > (-Daodan[i].xv))
					{
						Set_Animation_BOB(&Daodan[i],9);
					}
					else if(Daodan[i].yv < (-Daodan[i].xv)) Set_Animation_BOB(&Daodan[i],11);
					
					else Set_Animation_BOB(&Daodan[i],10);
				}
				else if(Daodan[i].xv > 0)
				{
					if(Daodan[i].yv > Daodan[i].xv)
					{
						Set_Animation_BOB(&Daodan[i],7);
					}
					else if(Daodan[i].yv < Daodan[i].xv)
					{
						Set_Animation_BOB(&Daodan[i],5);
					}
					else Set_Animation_BOB(&Daodan[i],6);
				}
				else Set_Animation_BOB(&Daodan[i],8);
			}  
		}
	}
	
	return 1;
}//end Move_Daodan //这里就找到了最近的敌人和要渲染的位图。
///////////////////////////////////////////////////////////////////////////////////
///激活一个导弹
int Start_Daodan(int x,int y,int z,int xv,int yv)
{
	for(int i=0;i<MAX_NUM_DAODAN ;i++)
	{
		if(Daodan_state[i]==DEAD)
		{
			Daodan_state[i]=ALIVE;                    //将一个导弹激活

			Daodan[i].varsI[1]=0;                     //爆炸持续时间初始化

			Set_Animation_BOB(&Daodan[i],z);          //设置动画模式 

			Set_Pos_BOB(&Daodan[i],x,y);              //设置导弹的位置

			Set_Vel_BOB(&Daodan[i],xv,yv);            //设置导弹的速度

			Show_BOB(&Daodan[i]);                     //改为可见的。。
			
           break;
		}
	}

	return 1;
}
///////////////////////////////////////////////////////////////////////////
///检测导弹是否过界或者爆炸。。
int Check_Daodan()
{
	for(int i=0;i<MAX_NUM_DAODAN;i++)
	{
		if(Daodan_state[i]==ALIVE)
		{
			if(Daodan[i].x<152 || Daodan[i].x>640 || Daodan[i].y < 0 || Daodan[i].y>480) //超过边界
			{
				Hide_BOB(&Daodan[i]);

				Daodan_state[i]=DEAD;
			}
			
		    if(Daodan[i].curr_animation==16) //爆炸
			{
				if(++Daodan[i].varsI[1] > 3)
				{
					Hide_BOB(&Daodan[i]);

					Daodan_state[i]=DEAD;
				}
			}
		}
	}
	return 1;
}
int Delete_Daodan()
{
	for(int i=0;i<MAX_NUM_DAODAN;i++)
	{
		Destroy_BOB(&Daodan[i]);
	}
	return 1;
}
////////////////////////////////////////////////////////////////////////////
int Draw_Daodan()
{
	for(int i=0;i<MAX_NUM_DAODAN;i++)
	{
		if(Daodan_state[i]==ALIVE)
		{
			Draw_BOB(&Daodan[i],lpddsback);

			Animate_BOB(&Daodan[i]);
		}
	}
	return 1;
}
//////////////////////////////////////////////////////////////////////////////////////







///////////游戏初始化///////////////////////////////////////////////////////////////////////////////
int Game_Init()
{
                int VideoFrame=0;
	            Start_Clock();  //开始记时
                int index;   
                UCHAR *source_buffer=NULL;
			    UCHAR *dest_buffer=NULL;
	            int surface_lpitch;
				//////////////////////////用于左边的帮助栏
		        dest_rect.top=0;
				dest_rect.left=0;
			    dest_rect.bottom=480;
				dest_rect.right=160;
							
		  
			    //int surface_lpitch;
                srand(Start_Clock());  //开始记时
				
				
////////初始化输入系统///////////////////////////////////////////////////////////////////////////////
                DInput_Init();              
///初始化键盘设备////////////////////////////////////////////////////////////////////////////////////
                DInput_Init_Keyboard();
			   
                ShowCursor(FALSE);
 

				  while(++VideoFrame < VIDEOTIME )
				  {
                     Start_Clock();
                     DInput_Read_Keyboard();
 	                 if(keyboard_state[DIK_ESCAPE])
					 {	
							  
                       CloseClip();
		                 break;
					 }			   
                     Wait_Clock(33);
				  }
                 if(VideoFrame >= VIDEOTIME)
				  {
	                  CloseClip();
				  }
			   



                //初始化渲染DDraw
                DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);
/////////////////////////////////////////////////////////////////////////////////////////////////
				//创建左边帮助栏///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////

			 lpddhelp=DDraw_Create_Surface(160,480,DDSCAPS_SYSTEMMEMORY,-1);
				               				
			 if(!(Load_Bitmap_File(&bitmap8bit,"help.bmp")))
			 {
				  	MessageBox(main_window_handle,"daf","fdaf",MB_OK);
				      return 0;
			 }
				               					
		//	 lpddpal->SetEntries(0,0,256,bitmap8bit.palette);
			 DDRAW_INIT_STRUCT(ddsd);
			 lpddhelp->Lock(NULL,&ddsd,DDLOCK_WAIT||DDLOCK_SURFACEMEMORYPTR,NULL);
			 dest=(UCHAR *)ddsd.lpSurface;
				               				    	      
			 dest_buffer=dest;
			source_buffer=bitmap8bit.buffer;
			 for(index=0;index<480;index++)
			{
			  memcpy((void *)dest_buffer,(void *)source_buffer,160);
			  dest_buffer+=(int)ddsd.lPitch;
			  source_buffer+=160;
			}			              	
			Unload_Bitmap_File(&bitmap8bit);

			lpddhelp->Unlock(NULL);
                
				           
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////	
				
				 				 				
		 	lpddinstraction=DDraw_Create_Surface(640,480,DDSCAPS_VIDEOMEMORY,-1);
		    Load_Bitmap_File(&bitmap8bit,"instraction.bmp");
				 				 						 				 				 
			memcpy(menuinstraction,bitmap8bit.palette,256);
			 //lpddpal->SetEntries(0,0,256,bitmap8bit.palette);
				DDRAW_INIT_STRUCT(ddsd);
				lpddinstraction->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL); 
				dest=(UCHAR *)ddsd.lpSurface;
				surface_lpitch=(int)ddsd.lPitch;
				dest_buffer=dest;
				source_buffer=bitmap8bit.buffer;
				for(index=0;index<480;index++)
				{
				 memcpy((void *)dest_buffer,(void *)source_buffer,640);
				 dest_buffer+=surface_lpitch;
				 source_buffer+=640;
				}
		    	 Unload_Bitmap_File(&bitmap8bit);
				lpddinstraction->Unlock(NULL);
				 				 						 				 		
				 				 		
///////////////////////////////////////////////////////////////////////////////////////////////////								 				              

			
/////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////主菜单
			lpddmainmenu=DDraw_Create_Surface(640,480,DDSCAPS_VIDEOMEMORY,-1);
		    Load_Bitmap_File(&bitmap8bit,"mainmenu.bmp");
				 				 				 
			memcpy(mainmenupalette,bitmap8bit.palette,256);

		//	lpddpal->SetEntries(0,0,256,bitmap8bit.palette);
			DDRAW_INIT_STRUCT(ddsd);
			lpddmainmenu->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL); 
			dest=(UCHAR *)ddsd.lpSurface;
			surface_lpitch=(int)ddsd.lPitch;
			dest_buffer=dest;
			source_buffer=bitmap8bit.buffer;
			for(index=0;index<480;index++)
			{
				 memcpy((void *)dest_buffer,(void *)source_buffer,640);
				 dest_buffer+=surface_lpitch;
				 source_buffer+=640;
			}
			 Unload_Bitmap_File(&bitmap8bit);
			 
			lpddmainmenu->Unlock(NULL);
				 				 			
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////退出菜单

           	lpddmenuexit=DDraw_Create_Surface(640,480,DDSCAPS_VIDEOMEMORY,-1);
		    Load_Bitmap_File(&bitmap8bit,"menuexit.bmp");
				 				 				 
			memcpy(menuexitpalette,bitmap8bit.palette,256);

		//	lpddpal->SetEntries(0,0,256,bitmap8bit.palette);

			DDRAW_INIT_STRUCT(ddsd);
			lpddmenuexit->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL); 
			dest=(UCHAR *)ddsd.lpSurface;
			surface_lpitch=(int)ddsd.lPitch;
			dest_buffer=dest;
			source_buffer=bitmap8bit.buffer;
			for(index=0;index<480;index++)
			{
				 memcpy((void *)dest_buffer,(void *)source_buffer,640);
				 dest_buffer+=surface_lpitch;
				 source_buffer+=640;
			}
			 Unload_Bitmap_File(&bitmap8bit);
			lpddmenuexit->Unlock(NULL);
				 				 				 				
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////介绍菜单
		  
           	lpddmenuinst=DDraw_Create_Surface(640,480,DDSCAPS_VIDEOMEMORY,-1);
		    Load_Bitmap_File(&bitmap8bit,"menuinst.bmp");
				 				 				 
			memcpy(menuinstpalette,bitmap8bit.palette,256);

			lpddpal->SetEntries(0,0,256,bitmap8bit.palette);
			DDRAW_INIT_STRUCT(ddsd);
			lpddmenuinst->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL); 
			dest=(UCHAR *)ddsd.lpSurface;
			surface_lpitch=(int)ddsd.lPitch;
			dest_buffer=dest;
			source_buffer=bitmap8bit.buffer;
			for(index=0;index<480;index++)
			{
				 memcpy((void *)dest_buffer,(void *)source_buffer,640);
				 dest_buffer+=surface_lpitch;
				 source_buffer+=640;
			}
			 Unload_Bitmap_File(&bitmap8bit);
			lpddmenuinst->Unlock(NULL);
				 				 				 				
/////////////////////////////////////////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////////////////////////////////////////////////
/////这里进行所有游戏对象的初始化。。。。。
	          Init_Player();
			  Init_Blue();
              Init_Weixing();
			  Init_Baowu();
			  Init_Daodan();
			  Init_Myzidan();
			  Init_Yellow();
			  Init_Boss();
			  Init_Enemyzidan();
			  Init_Sorce();
			  Init_Blood();
			  			  
              return(1);

} // end Game_Init

////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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