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

📄 fangkuai.c

📁 51单片机游戏程序包括图纸
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "t6963c.h"
#include "typedef.h"
#include "key.h"

#define X_START 5
#define Y_START 0
#define MIN_SLOW_SPEED  300
#define BX_START  30
#define BY_START  15
#define Nothing   100


//全局数据
code uchar Game_Char[]={0x27,0x41,0x4d,0x45};
code uchar Over_Char[]={0x2f,0x56,0x45,0x52};
				                            
static uchar xx,yy;         //方块的位置
static uint  Game_Score=0;
static uchar xdata Platform[14][21];    //游戏平台数据
static uchar This_shape;				//当前形状
static uchar Next_shape=0;
static uint  Game_Speed=MIN_SLOW_SPEED;	 //等级速度,正常情况,方块下降的速度
static uchar Game_Stop=1;
static uchar Game_Level=0;

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////方块形状的定义//////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
struct POINT{
              uchar x;
              uchar y;
             };

struct SHAPE{
               struct POINT point[4];
			   uchar next;	//下一个形状
			 } 


xdata shape[19]={ 
  
                   { 1,0,0,1,1,1,2,1,1  },
				   { 1,0,1,1,2,1,1,2,2  },
				   { 0,0,1,0,2,0,1,1,3  },
				   { 1,0,0,1,1,1,1,2,0  },
				    
				   { 1,0,2,0,1,1,1,2,5  },
				   { 0,0,1,0,2,0,2,1,6  },
				   { 2,0,2,1,2,2,1,2,7  },
				   { 0,0,0,1,1,1,2,1,4  },

				   { 1,0,2,0,2,1,2,2,9  },
				   { 2,0,0,1,1,1,2,1,10 },
				   { 1,0,1,1,1,2,2,2,11 },
				   { 0,0,1,0,2,0,0,1,8  },

				   { 0,0,0,1,1,1,1,2,13 },
				   { 1,0,2,0,0,1,1,1,12 },

				   { 2,0,1,1,2,1,1,2,15 },
				   { 0,0,1,0,1,1,2,1,14 },

				   { 1,0,1,1,1,2,1,3,17 },
				   { 0,1,1,1,2,1,3,1,16 },

				   { 1,0,2,0,1,1,2,1,18 }, 	
				   	 
				};   

////////////////////////////////////////////////////////////////////////////
//**************************************************************************
//= 函数原型:void Init_GamePlatform()
//= 功    能: 初始化游戏平台
//= 参    数: 无			
//= 返 回 值: 无
//= 函数性质:公有函数
//= 注    意:
//*************************************************************************** 
void Show_score(uchar);
void Init_GamePlatform()
{
  uchar i;
  uchar j;
  uchar N_Hanzi;
  
  Wr_line(1,33,13,64,1 );	//初始化游戏平台边界	画游戏区域
  Wr_line(1,33,14,64,1 );   //画上横线
  Wr_line(0,33,15,100,1);
  Wr_line(0,34,15,100,1);  //画左竖线
  Wr_line(1,33,115,64,1);  
  Wr_line(1,33,116,64,1);  //画下横线
  Wr_line(0,95,15,100,1);
  Wr_line(0,96,15,100,1);  //画右竖线
//--------------------------------------------------------
  for(i=1;i<13;i++)		//游戏平台数据清零
  {
    for(j=0;j<20;j++)
	  {
	    Platform[i][j]=0;
	  }
   }
   for(i=1;i<13;i++)
   {
      Platform[i][20]=1;   //游戏平台最下面一行的每一个方块位置为1,作为下边界
	}
   
   for(j=0;j<20;j++)		//游戏平台左右方块位置置1,作为左右边界
   {
      Platform[0][j]=1;
	  Platform[13][j]=1;
   }
//--------------------------------------------------------- 
  N_Hanzi=0;             
  for(j=3;j<=12;j=j+2)	   //输入“冯燕辉制作”汉字
  {
     hanzhi(1,j,N_Hanzi,1);
	 N_Hanzi++;   //指向下一个汉字
  }
  
  hanzhi(13,3,6,1);	 //输入“分”汉字
  hanzhi(13,8,8,1);   //输入“级”汉字

  Show_score(0);        //显示初始分数
  Show_num(13,11,Game_Level);	 //显示初始等级水平
  Game_Speed=MIN_SLOW_SPEED/(Game_Level+1);  //根据水平确定速度

//------------------------------------------------------------------
  Game_Score=0;
  xx=X_START ;
  yy=Y_START ;
}
////////////////////////Init_Game/////////////////////
void Init_Game()
{
  Game_Stop=1;
  Init_GamePlatform();
  hanzhi(7,3,9,1);	 //输入“按”汉字
  Show_num(7,6,7);	 //显示7
  hanzhi(7,8,10,1);	 //输入“开”汉字
  hanzhi(7,10,11,1);	 //输入“始”汉字
}
//**************************************************************************
//= 函数原型:void XiaoFengKuai(uchar x,uchar y,uchar mode)
//= 功    能: 显示一个小方块
//= 参    数: 小方块的横x,坚坐标y,mode=1:显示小方块,mode=0:删除小方块			
//= 返 回 值:
//= 函数性质:私有函数
//= 注    意:
//*************************************************************************** 
void XiaoFengKuai(uchar x,uchar y,bit mode)
{
   uchar x1=5*x+BX_START;	//将方块在平台的位置转化成LCD的点坐标(地址转换)
   uchar y1=5*y+BY_START;	  
   uchar i;

   if(mode==1)
   {

       for(i=0;i<5;i++)
       {
          Point(x1+i,y1,1); //画一条横线
       }


       	y1+=4;

        for(i=0;i<5;i++)
        {
           Point(x1+i,y1,1); //画第二条横线
         }

        for(i=0;i<5;i++)
        {
           Point(x1,y1-i,1); //画第1条坚线
         }

         x1+=4;

        for(i=0;i<5;i++)
        {
           Point(x1,y1-i,1); //画第2条坚线
         }

        y1-=4;
        for(i=0;i<5;i++)
        {
           Point(x1-i,y1+i,1); //画斜线
        }
   }

  else
  {
  	   for(i=0;i<5;i++)
        {
          Point(x1+i,y1,0); //画一条横线
      	}

       	y1+=4;
        for(i=0;i<5;i++)
         {
           Point(x1+i,y1,0); //画第二条横线
         }

         for(i=0;i<5;i++)
         {
            Point(x1,y1-i,0); //画第1条坚线
          }

         x1+=4;
        for(i=0;i<5;i++)
          {
             Point(x1,y1-i,0); //画第2条坚线
          }

        y1-=4;
        for(i=0;i<5;i++)
         {
           Point(x1-i,y1+i,0); //画斜线
         }
	}
}
//////////////////////////////////////////////////////////////////////////
////////////////左冲突检测//////////////////////////////////////////////
bit Left_Anti()
{
  uchar i;
  for(i=0;i<4;i++)
	{
	  if(Platform[xx+shape[This_shape].point[i].x-1][yy+shape[This_shape].point[i].y]==1) 
	    return 1;
	}
  return 0;
}	   

////////////////右冲突检测///////////////////////////////////////////
bit Right_Anti()
{
  uchar i;
  for(i=0;i<4;i++)
	{
	  if(Platform[xx+shape[This_shape].point[i].x+1][yy+shape[This_shape].point[i].y]==1)
	    return 1;
	}			   
  return 0;
  
}

////////////////////////////////////////下冲突检测//////////////////////////
bit Bottom_Anti()
{
   uchar i;
   for(i=0;i<4;i++)
	{
	  if(Platform[xx+shape[This_shape].point[i].x][yy+shape[This_shape].point[i].y+1]==1)
	    return 1;
    }
  return 0;			  
}
//////////////////////////////////改变形状时产生的冲突检测////////////////////
bit Change_Shape_Anti()
{
   uchar i;
   for(i=0;i<4;i++)
	{
	  if(Platform[xx+shape[shape[This_shape].next].point[i].x][yy+shape[shape[This_shape].next].point[i].y]==1)
	    return 1;	   //检测一个形状的冲突情况
    }
   return 0;
}
//////////////////////////////////产生一个随机数,返回一个随机数///////////////
uchar Random()
{
  static uchar m;
  m+=49;
  return (m%19);
}

//////////////计分函数,参数为 消行行数n///////////////////////////////////////

void Show_score(uchar n)
{
  Game_Score=Game_Score+10*n;

  if(Game_Score<10)
  {
     Show_num(13,6,Game_Score%10);		//显示个位
  }
  else if(Game_Score<100)
  {  
     Show_num(14,6,Game_Score%10);
	 Show_num(13,6,Game_Score/10%100);	//显示个位,十位
  }
  else if(Game_Score<1000)
  {
     Show_num(14,6,Game_Score%10);

⌨️ 快捷键说明

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