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

📄 ball_game.c

📁 在Vxworks下UGL工具编写的弹球游戏
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
    	ClearScreen(gc);                     
	i=0;
	textOrigin = UGL_FONT_TEXT_UPPER_LEFT;
    	uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin);
    	uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize=24", &fontDef);
        
        if ((fontBanner = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL)
	   {
        	printf("Font not found. Exiting.\n");
            
           }
      
    	uglForegroundColorSet(gc, colorTable[GREEN].uglColor);
    	uglBackgroundColorSet(gc, colorTable[BLUE].uglColor);
     
    	uglFontSet(gc, fontBanner);
    
    	uglTextDraw(gc, 230, 250, -1, text6);
    	uglTextDraw(gc, 230, 300, -1, text7);
        if (pageIndex == 0)
		    {
		    uglPageVisibleSet(devId, page[1]);
		    uglPageDrawSet(devId, page[0]);
		    pageIndex = 1;
		    }
		else
		    {
		    uglPageVisibleSet(devId, page[0]);
		    uglPageDrawSet(devId, page[1]);
		    pageIndex = 0;
		    } 
    	while(1)
    	{	semTake(ASemId,WAIT_FOREVER);
    	 	i+=1;
    	 	if(i=1)
    		{
    			uglGcDestroy (gc);
			uglFontDestroy(fontBanner);
    			uglDeinitialize();
    		}
        }
    }
   
int ballmoving(void)
{ 
  	int x, y;
	
	
	int m[28] = {198,229,167,198,229,260,105,136,167,198,229,260,291,322,105,136,167,198,229,260,291,322,167,198,229,260,198,229};
        int n[28] = {47,47,78,78,78,78,109,109,109,109,109,109,109,109,140,140,140,140,140,140,140,140,171,171,171,171,202,202};
	UGL_RECT rect;
        
	rect.left =0;
	rect.top = 0;
	rect.right =4*displayWidth /7;
	rect.bottom = 5*displayHeight/6;
	
	start=100;
	g = 200;
  	xinc = 0; 
  	yinc = 0;
  	ginc=0;
	while (1)
	    {
	    	semTake(ASemId,WAIT_FOREVER);
	    	
	    	pageIndex = 0;
	    	
	    	page[0] = UGL_PAGE_ZERO_ID;
		page[1] = uglPageCreate(devId);
		uglPageDrawSet(devId, page[1]);
		
		uglBackgroundColorSet(gc, colorTable [BLUE].uglColor);  
    		uglForegroundColorSet(gc, colorTable [BLUE].uglColor);
    		uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID);
    		uglLineWidthSet(gc, 1);
    		uglRectangle(gc, 0, 0, displayWidth - 1, displayHeight - 1);
		
	    	uglBackgroundColorSet(gc, colorTable[WHITE].uglColor);
		uglForegroundColorSet(gc, colorTable[WHITE].uglColor);
		uglRectangle(gc, rect.left, rect.top,  rect.right, displayHeight-1);    	
	    	uglBackgroundColorSet(gc, colorTable[GREEN].uglColor);
	    	uglForegroundColorSet(gc, colorTable[GREEN].uglColor);
	    	uglRectangle(gc, rect.left + 15, rect.top + 15, rect.right - 15, 
			 	displayHeight- 16);
                for(l=0;l<28;l++) 
		{
			uglBackgroundColorSet(gc, colorTable[WHITE].uglColor);
	    		uglForegroundColorSet(gc, colorTable[BLACK].uglColor);
	    		uglRectangle(gc, m[l], n[l], m[l]+a,n[l]+a);
			
		}    
	    	uglBackgroundColorSet(gc, colorTable[YELLOW].uglColor);
	    	uglForegroundColorSet(gc, colorTable[BLUE].uglColor);
	    	uglEllipse(gc, x, y, x + 20, y + 20, 0, 0, 0, 0);
                
                
                uglBackgroundColorSet(gc, colorTable[RED].uglColor);
	    	uglForegroundColorSet(gc, colorTable[RED].uglColor);
	    	uglRectangle(gc,g,rect.bottom - 8,g+70,rect.bottom );  
	    	
	    	
	    	textOrigin = UGL_FONT_TEXT_UPPER_LEFT;
    		uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin);
    		uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize=24", &fontDef);
        
        	if ((fontBanner = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL)
	  	   {
        		printf("Font not found. Exiting.\n");
        		return(0);        
          	   }
      
    		uglForegroundColorSet(gc, colorTable[GREEN].uglColor);
    		uglBackgroundColorSet(gc, colorTable[BLUE].uglColor);
     
    		uglFontSet(gc, fontBanner);
    
    		uglTextDraw(gc, 480, 480, -1, text9);
    		uglTextDraw(gc, 500, 170, -1, text16);
    		uglTextDraw(gc, 500, 210, -1, text17);
    		if(life==2)
	    	{
	    		uglTextDraw(gc, 560, 300, -1, text13);
	    	}
	    	else if(life==1)
	    	{
	    		uglTextDraw(gc, 560, 300, -1, text14);
	    	}
	    	else if(life==0)
	    	{
	    		uglTextDraw(gc, 560, 300, -1, text15);
	    	}	
	    	
	    	if (pageIndex == 0)
		    {
		    uglPageVisibleSet(devId, page[1]);
		    uglPageDrawSet(devId, page[0]);
		    pageIndex = 1;
		    }
		else
		    {
		    uglPageVisibleSet(devId, page[0]);
		    uglPageDrawSet(devId, page[1]);
		    pageIndex = 0;
		    } 
	    	if(pausy==1)
                	pause();             
		if((y + 20 >=rect.bottom-8 )&&(((x>=rect.left + 15)&&(x+12<=g))||((x>=g+70)&&(x+20<=rect.right - 15)))||(g<rect.left + 15)||(g+70>rect.right - 15))
    		{
    			if(life!=0)
			{
    				keeping();
    			}
    			else
    			goto END;
    		}
    		if(start!=1&&start!=2&&start!=0)
		{
			x = g+25;
			
	                y = rect.bottom-28;
		}
    		if(start==1)
		{
			xinc=-1;
			yinc=-1;
			start=0;
		}
		else if(start==2)
		{
			xinc=1;
			yinc=-1;
			start=0;
		}	  	                
	    	if (x + 20 >= rect.right - 15)
		{
			xinc = -1;
		}
	    	else if (x <= rect.left + 15)
		{
			xinc = 1;
		}

	    	if (y + 20 >= rect.bottom-8 )
		{
			yinc = -1;
		}
	    	else if (y <= rect.top + 15)
		{
			yinc = 1;
		}
		for(l=0;l<28;l++) 
		{
			if((x>=(m[l]+a-1))&&(x<=(m[l]+a+1))&&
				(y+10<=(n[l]+a+1))&&(y+10>=(n[l]-1)))
			{
				xinc = 1;
				m[l]=1000;
				n[l]=1000;
			}
			
		}
		for(l=0;l<28;l++) 
		{
			if((x+20>=(m[l]-1))&&(x+20<=(m[l]+1))&&
				(y+10<=(n[l]+a+1))&&(y+10>=(n[l]-1)))
			{		
				xinc = -1;
				m[l]=1000;
				n[l]=1000;
			}
		}
                for(l=0;l<28;l++) 
		{
			if((x+10>=(m[l]-1))&&(x+10<=(m[l]+1+a))&&
				(y+20<=(n[l]+a+1))&&(y+20>=(n[l]-1)))
			{	yinc = -1;
				m[l]=1000;
				n[l]=1000; 
			}
		}
		for(l=0;l<28;l++) 
		{
			if((x+10>=(m[l]-1))&&(x+10<=(m[l]+a+1))&&
				(y<=(n[l]+a+1))&&(y>=(n[l]+a-1)))
			{	yinc = 1;
				m[l]=1000;
				n[l]=1000; 
			}
		}
		if ((retVal == 1)&&(g>=rect.left + 15+20))
		{
			ginc = -20;
		
		}
	    	else if ((retVal == 2)&&(g+70<=rect.right - 15-20))
		{
			ginc = 20;
		
		}
		else if (retVal == 0)
		{
			ginc = 0;
		
		}
		
			
	        x += xinc;
	    	y += yinc;
	    	g += ginc;
                retVal = 0;
	}  
	END:
		textOrigin = UGL_FONT_TEXT_UPPER_LEFT;
    		uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin);
    		uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize=24", &fontDef);
        
        	if ((fontBanner = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL)
	   	{
        		printf("Font not found. Exiting.\n");
        		return(0);        
          	}
        	uglForegroundColorSet(gc, colorTable[LIGHTMAGENTA].uglColor);
    		uglBackgroundColorSet(gc, colorTable[GREEN].uglColor);
     
    		uglFontSet(gc, fontBanner);
    
    		uglTextDraw(gc, 110, 250, -1, text11);
    		uglTextDraw(gc, 90, 300, -1, text12);
    		if (pageIndex == 0)
		    {
		    uglPageVisibleSet(devId, page[1]);
		    uglPageDrawSet(devId, page[0]);
		    pageIndex = 1;
		    }
		else
		    {
		    uglPageVisibleSet(devId, page[0]);
		    uglPageDrawSet(devId, page[1]);
		    pageIndex = 0;
		    }	   
    		    	
    		while(1)
    		{	semTake(ASemId,WAIT_FOREVER);
    		
    			if(replay ==2)
    			{	
    				Quit();    
    				break;              /*退出游戏*/
            		}
        
    			else if(replay == 1)
   			{	
   				uglOSTaskCreate("ready", (UGL_FPTR)ready, 110, 
		    		0, 10240,0,0,0,0,0);	
		       	 	break;              /*重新开始游戏*/
        		}  
 		}
		
 }	




void keeping(void)
{
		keep=100;
		life--;
        	textOrigin = UGL_FONT_TEXT_UPPER_LEFT;
    		uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin);
    		uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize=24", &fontDef);
        
        	if ((fontBanner = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL)
	   	{
        		printf("Font not found. Exiting.\n");
        		return(0);        
           	}
        	uglForegroundColorSet(gc, colorTable[LIGHTMAGENTA].uglColor);
    		uglBackgroundColorSet(gc, colorTable[GREEN].uglColor);
     
    		uglFontSet(gc, fontBanner);
    
    		uglTextDraw(gc, 150, 250, -1, text1);
    		uglTextDraw(gc, 140, 300, -1, text5);
    		if (pageIndex == 0)
		    {
		    uglPageVisibleSet(devId, page[1]);
		    uglPageDrawSet(devId, page[0]);
		    pageIndex = 1;
		    }
		else
		    {
		    uglPageVisibleSet(devId, page[0]);
		    uglPageDrawSet(devId, page[1]);
		    pageIndex = 0;
		    }	 
    		    	
    		while(1)
    		{	semTake(ASemId,WAIT_FOREVER);
    				
        
    			if(keep == 1)
   			{	
   					
		       	 	break;              
        		}  
 		}
 		xinc=0;
 		yinc=0;
 		start=100;
 		g=200;
}         
	
        	
        	
        	
        	

         	
 

⌨️ 快捷键说明

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