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

📄 game_main.c

📁 智原mp3 SDK 开发包 与巨力 有mp3 wma ogg decoder
💻 C
字号:
/******************
 *  mp3_main.c
 *****************/

#include <string.h>
#include "api.h"
#include "lcd.h"
#include "common.h"
#include "ap_common.h"
#include "display.h" 
#include "gameblock.h"
#include "prefer.h"
#include "ui_main.h"
#include "res_show.h"
#include "res.h"
#include "game_sub_menu.h"
#include "game_display.h"
#include "ui_message.h"


attribute next;
attribute active;
INT8 g_game_speed=2;

INT8 allblock[HIGH+1][WIDTH];
INT8 flytype_ran=0;
INT8 color_ran=0;
INT8 sharp_ran=0;
BOOLEAN need_draw=TRUE;
INT8 stop=0;
INT8 reflash_high=0;

BOOLEAN menu_stop=TRUE;

INT16  get_score=0;
extern INT8U _buf[256];

INT8 get_fly_ran()
{	
	INT8 i; //flytype 7 种
	INT8 random[42] ={4,2,3,6,0,1,0,1,4,0,6,1,1,3,1,4,4,6,2,4,2,3,6,4,2,2,4,2,0,5,2,6,6,1,4,6,2,0,2,1,5,6};
	
	//Print("fly");
     	if(flytype_ran > 41) 
	 	flytype_ran=0;
	i=random[flytype_ran++];
    	
    	return i;
}

INT8 get_color_ran()
{	
	INT8 i; //color 5 种
	INT8 random1[40] ={3,4,1,0,4,3,1,1,3,1,4,0,4,1,1,4,4,4,1,2,3,0,4,2,1,4,4,0,0,2,4,0,4,0,3,2,4,0,0,3};
	//Print("color");
     	if(color_ran > 39) 
	 	color_ran=0;
	i= random1[color_ran++]+1;
    	return i;
}

INT8 get_sharp_ran()
{

	INT8 i;//sharp 4 种
	INT8 random2[40] ={1,1,3,1,1,2,2,3,0,1,0,1,0,1,1,3,1,2,2,3,2,2,2,0,2,1,2,0,2,1,0,2,0,0,2,1,0,1,3,3};

     	if(sharp_ran > 39) 
	 	sharp_ran=0;
	i=random2[sharp_ran++];
    	return i;
}

//*******************************************************************************
//* Description : 
//*               set=0, 清屏,清除前面对应的方块显示
//*               set=1, 正常显示
//*               set=2, 正常显示,同时填充对应的数组,以标记相应屏幕已被填充
//*               set=3, 左移测试
//*               set=4, 右移测试
//*               set=5, 变形测试
//* Arguments   :
//*
//* Returns     :
//*
//* Notes       :
//*
//********************************************************************************

INT8 display(attribute *p, INT8 set)
{
   	INT8 i,x,y,temp;
  
	INT8 sharp_dot[7][32]=
	{
	{0,0,1,0,2,0,1,1,     0,0,0,1,0,2,1,1,    0,1,1,1,1,0,2,1,    0,1,1,0,1,1,1,2},
	{0,0,1,0,1,1,2,1,     0,1,0,2,1,0,1,1,    0,0,1,0,1,1,2,1,    0,1,0,2,1,0,1,1},
	{0,1,1,0,1,1,2,0,     0,0,0,1,1,1,1,2,    0,1,1,1,1,0,2,0,    0,0,0,1,1,1,1,2},
	{0,0,1,0,2,0,3,0,     0,0,0,1,0,2,0,3,    0,0,1,0,2,0,3,0,    0,0,0,1,0,2,0,3},
	{0,0,1,0,0,1,1,1,     0,0,1,0,0,1,1,1,    0,0,1,0,0,1,1,1,    0,0,1,0,0,1,1,1},
	{0,0,1,0,2,0,2,1,     0,0,0,1,0,2,1,0,    0,0,0,1,1,1,2,1,    0,2,1,0,1,1,1,2},
	{0,0,0,1,1,0,2,0,     0,0,0,1,0,2,1,2,    0,1,1,1,2,1,2,0,    0,0,1,0,1,1,1,2}
	};
    	
    	if(set>0)
    		temp=1;
    	else 
    		temp=0;
    		
    	if(set == 6)
    	{
    		
    		for(i=0;i<4;i++)
    		{
    			x=(sharp_dot [p-> flytype][(p->sharp)*8+i*2] + p->x);
			y=(sharp_dot [p-> flytype][(p->sharp)*8+i*2+1]+p->y);	
    			bResShowPic(FIRSTBLK, 8*x,   8*y );
    		}
    		return 1;	
    	}	
	
    	for(i=0;i<4;i++)
    	{	
		x=(sharp_dot [p-> flytype][(p->sharp)*8+i*2] + p->x);
		y=(sharp_dot [p-> flytype][(p->sharp)*8+i*2+1]+p->y);	
		if(set==3)	//左移
		{
	   		if((x==0) ||      (allblock[y][x-1] != 0) ) return 0;
	   		else continue;
		}

		if(set==4)	//右移
		{
	   		if(( x==(WIDTH-1) ) || (allblock[y][x+1] != 0) )
	   			return 0;
	   		else 
	   			continue;
		}

		if(set==5)	//变形
		{
	   		if((allblock[y][x] != 0) || (x>WIDTH-1 )) 
	   			return 0;
	   		else 
	   			continue;
		}

		if(y<HIGH)
		{	
			if((x>=NEXTOBJ_X) && (temp==0) ) 
				bResShowPic( WHITE_BLOCK,   8*x,   8*y );
			else 
				bResShowPic( (FIRSTBLK+(p-> color)*temp),   8*x,   8*y );
		//上面这个是可以的
		}
		
		if(((allblock[y-1][x] != 0) || (y==0) ) && (x<WIDTH+1)) 
		{
			stop=1;

		}
		if(set==2) allblock[y][x]=(0+(p-> color)*temp);

    	}
	return 1;
}



//********************************************************************************
//* Description : 
//*
//* Arguments   :
//*
//* Returns     :
//*
//* Notes       :
//*
//********************************************************************************

void block_stop()
{	
	
	INT8 i,j,m,n;
	INT8 disappear_n=0;
	BOOLEAN LineFilled;// -xhl
	display(&active,2);
	//Print("stop");
	stop=0;

	for (i=0;i<HIGH;i++)
	{
		LineFilled=TRUE;
		for(j=0;j<WIDTH;j++)
		{
			 
			 if (allblock[i][j]!=0) 
			 	reflash_high=i;// -xhl
			 else 
			 {
			 	LineFilled = FALSE; 
			 }// 有空没有填满则不加分不消失(覆盖)方块
		}
		if (LineFilled)
		{
		        disappear_n++;
		        need_draw=TRUE;
			  for (m=i;m<HIGH;m++)
			  	for (n=0;n<WIDTH;n++)
			 		 allblock[m][n]=allblock[m+1][n];// 填满一行消失一行
			  if (i==0) 
			  	i=0xff;
			  else 
			  	i--;
		}
	}
		
	reflash_high+=disappear_n;// -xhl
		
	for (i=1; i <= disappear_n; i++)
	{
		 get_score+=i;
		 if(i>2) 
		 	get_score--;
	}

	active=next;		//得到新的方块
	active.x=WIDTH/2;
	active.y=ACTIVE_STARTY;

	//display(&next,0);

	next.flytype=get_fly_ran();//生成新的方块
	next.color=get_color_ran();
	next.sharp=get_sharp_ran();
	next.x=NEXTOBJ_X;
	next.y=NEXTOBJ_Y;
}




//********************************************************************************
//* Description : 俄罗斯方块游戏
//
//*
//* Arguments   :
//*
//* Returns     :
//*
//* Notes       :
//*
//********************************************************************************

BOOLEAN need_draw_backgroud=TRUE,playGame=FALSE;
INT8 countTime;
INT8 temp_score='0';
INT8 buf[9];
INT8 drop_time=0; 

 
void game_block_init(void)
{
	int i,j;
	i=j=0;
	
	temp_score='0';
	g_game_speed=tUserPreference.game_speed;
	countTime=5-g_game_speed;
	drop_time=0;
	need_draw_backgroud=TRUE;
	need_draw_backgroud = FALSE;
	
	bResShowPic(LEFT,0,0);	
	bResShowPic(RIGHT,80,0);
	
	if(menu_stop)
	{
   	      menu_stop = FALSE;
   	     // playGame=0;	
	      //初始化所有的方块为空
	      for (i=0;i<HIGH+1;i++)
	      		for(j=0;j<WIDTH;j++)
	      			allblock[i][j]=0;
	      
	      
	      stop=0;
	      get_score=0;
	      reflash_high=0;//HIGH;  
	      active.flytype=2;//get_fly_ran();
	      active.color=4;//get_color_ran();
	      active.sharp=3;//get_sharp_ran();
	      active.x=WIDTH/2;
	      active.y=ACTIVE_STARTY-1;
	      
	      next.flytype=1;//get_fly_ran();
	      next.color=2;//get_color_ran();
	      next.sharp=2;//get_sharp_ran();
	      next.x=NEXTOBJ_X;
	      next.y=NEXTOBJ_Y;
     	}
     	else
	{
	   	display(&active,1);
	    	
	    	for (i=0;i<HIGH;i++)
	    	  	for(j=0;j<WIDTH;j++)
	    	   		if (allblock[i][j]!=0) 
				{
					reflash_high=i; 
					break;
				}
       	
       	}	
	need_draw=TRUE;
}


void game_block(UINT8 key)
{

    	int i,j;

        //显示背景
        if(need_draw_backgroud)
        {
	      	need_draw_backgroud = FALSE;
	        bResShowPic(LEFT,0,0);
      
        }

        //显示方块, 全部刷新一遍
        if(need_draw)
        {
		need_draw = FALSE;
	          
	        bResShowPic(RIGHT,80,0);
		my_sprintf(_buf, "%01d%01d%01d%01d",(INT16U)((get_score % 10000) / 1000,(INT16U)((get_score % 1000) / 100)), (INT16U)((get_score % 100) / 10),(INT16U)((get_score % 10)));	   
		vshow_score(_buf);
		vshow_speed();							
            	for (i=0;i<=reflash_high;i++)// HIGH
                 	for(j=0;j<WIDTH;j++)
                  		bResShowPic(FIRSTBLK+allblock[i][j], j*8,i*8);		
        }

	
	if(!need_draw) 
		display(&active,1);// -xhl
				
	bg_color = COLOR_WHITE;
	gfx_set_bg(COLOR_WHITE);
	gfx_bg_rectangle(87, 80, 35, 40);	
	//fg_color = COLOR_UNSELECT;	
	display(&next,1);
	
        switch(key)
        {
		case KEY_AB_REPEAT://DOWN					
			if(stop==1)
			{
			      drop_time=0;
			      block_stop();
			}
					        		        			
			display(&active,0);

			active.y--;
			display(&active,1);
			if((allblock[ACTIVE_STARTY-1][WIDTH/2] != 0) || (allblock[ACTIVE_STARTY-1][WIDTH/2+1] != 0))
			{		
				playGame=1;
				ui_show_message(GAMEOVER);
				menu_stop = 1;
				screen_map(SCREEN_GAME);
			}						
			drop_time = (9 - g_game_speed);

			break;
		 
		case KEY_PREV://KEY_VOL_UP://LEFT		 
		        
		        display(&active, 6);
		        
		        if(display(&active, 3) == 0 )
			      break;			        
			active.x--;    	
			//bResShowPic(LEFT128,0,0);	
			display(&active,1);  	
		        stop=0;
		        drop_time=0; 
		        break;


		case KEY_NEXT://KEY_VOL_DN://RIGHT
			display(&active, 6);
		        if(display(&active, 4) == 0) 
				  break;		        
			active.x++;		
			display(&active,1);	  		        
	    	        stop=0;
		        drop_time=0;		        			        	        
		        break;
		        
		case KEY_PLAY://CHANGE
			//delay(10);
		        if(active.sharp==3)
				active.sharp=0;
		        else 
				active.sharp++;

		        if(display(&active, 5) == 0)
		        {
			        if(active.sharp==0) 
					active.sharp=3;
			        else 
					active.sharp--;
			        break;
		        }

		        if(active.sharp==0)
				active.sharp=3;
		        else
				active.sharp--;

		        display(&active,0);

		        if(active.sharp==3)
				active.sharp=0;
		        else 
				active.sharp++;

		        stop=0;
		        drop_time=0;

		        break;

		case KEY_MENU:	
			playGame = 0;
			game_sub_menu();	
			return;
								        
		default:
		        
		        break;
        } //switch(key)
}


⌨️ 快捷键说明

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