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

📄 function.lst

📁 51+3310做的俄罗斯方块
💻 LST
📖 第 1 页 / 共 3 页
字号:
 238   2                      LCD_write_Data(Blackground[line]);
 239   2              }
 240   1      }
 241          
C51 COMPILER V7.06   FUNCTION                                                              12/09/2008 01:11:01 PAGE 5   

 242          
 243          
 244          
 245          
 246          
 247          void LCD_DrawBlackGround()
 248          {
 249   1              uchar i,j,line;
 250   1              uint16 temp0,temp1,line0[6],line1[6],Mask=0x8000;
 251   1              LCD_write_CMD(0x22);//垂直模式
 252   1      //第一列的绘图
 253   1              LCD_set_XY(0,0);
 254   1              for(line=0; line<18; line++)
 255   1              {
 256   2                      LCD_write_Data(Blackground[line]);
 257   2              }
 258   1              for(j=0;j<16;j++)       
 259   1              {
 260   2                      for(i=0;i<6;i++)
 261   2                      {
 262   3                              if( Black_Ground[3*i]&Mask)
 263   3                              {temp0=0x0007;temp1=0x0005;}
 264   3                              else temp0=temp1=0;
 265   3                              if( Black_Ground[3*i+1]&Mask)
 266   3                              {temp0=temp0|0x0038;temp1=temp1|0x0028;}
 267   3                              else {temp0=temp0|0;temp1=temp1|0;}
 268   3                              if( Black_Ground[3*i+2]&Mask)
 269   3                              {temp0=temp0|0x01c0;temp1=temp1|0x0140;}
 270   3                              else {temp0=temp0|0;temp1=temp1|0;}     
 271   3                              line0[i]=temp0;
 272   3                              line1[i]=temp1;
 273   3                      }
 274   2                      line0[0]=(line0[1]<<9)|line0[0];
 275   2                      line0[1]=(line0[1]>>7)|(line0[2]<<2)|(line0[3]<<11);    
 276   2                      line0[2]=(line0[3]>>5)|(line0[4]<<4)|(line0[5]<<13);
 277   2                      
 278   2                      line1[0]=(line1[1]<<9)|line1[0];
 279   2                      line1[1]=(line1[1]>>7)|(line1[2]<<2)|(line1[3]<<11);    
 280   2                      line1[2]=(line1[3]>>5)|(line1[4]<<4)|(line1[5]<<13);
 281   2                      Mask=Mask>>1;
 282   2                      LCD_write_Data((uchar)line0[0]);
 283   2                      LCD_write_Data((uchar)(line0[0]>>8));
 284   2                      LCD_write_Data((uchar)line0[1]);
 285   2                      LCD_write_Data((uchar)(line0[1]>>8));
 286   2                      LCD_write_Data((uchar)line0[2]);
 287   2                      LCD_write_Data((uchar)(line0[2]>>8));
 288   2      
 289   2                      LCD_write_Data((uchar)line1[0]);
 290   2                      LCD_write_Data((uchar)(line1[0]>>8));
 291   2                      LCD_write_Data((uchar)line1[1]);
 292   2                      LCD_write_Data((uchar)(line1[1]>>8));
 293   2                      LCD_write_Data((uchar)line1[2]);
 294   2                      LCD_write_Data((uchar)(line1[2]>>8));
 295   2      
 296   2                      LCD_write_Data((uchar)line0[0]);
 297   2                      LCD_write_Data((uchar)(line0[0]>>8));
 298   2                      LCD_write_Data((uchar)line0[1]);
 299   2                      LCD_write_Data((uchar)(line0[1]>>8));
 300   2                      LCD_write_Data((uchar)line0[2]);
 301   2                      LCD_write_Data((uchar)(line0[2]>>8));           
 302   2              }       
 303   1      }
C51 COMPILER V7.06   FUNCTION                                                              12/09/2008 01:11:01 PAGE 6   

 304          
 305          void Load_Pic()
 306          {
 307   1              uint16 temp,pic;
 308   1              if(!NewBlock)         //方块没有触底和与其他方块接触以后就不重新载入方块
 309   1                      return;
 310   1              temp=rand();
 311   1              I1=(uchar)((temp>>8)%7);       ////预览中的方块图案
 312   1              J1=((uchar)temp%4);           //预览中的方块图案
 313   1              pic=Pic[I][J];           //在显示先前的方块之后,在确定方块下落完毕之后在是I=I1,J=J1
 314   1              Black_Ground[0]=((pic>>6)&0x03c0);
 315   1              Black_Ground[1]=((pic>>2)&0x03c0);
 316   1              Black_Ground[2]=((pic<<2)&0x03c0);
 317   1              Black_Ground[3]=((pic<<6)&0x03c0);
 318   1              NewBlock=0;
 319   1              Block_X=8;//记录最新方块初始位置
 320   1              Block_Y=0;//按Black_Ground数组字节顺序记录,不是按5510液晶坐标方向记录
 321   1      }
 322          
 323          
 324          uchar Attack_Block()      //接触到游戏背景中的方块
 325          {
 326   1              uchar i;           //已经假设向左,向右或向下移动过,但是在判定游戏是否结束的时候并没有先前移动
 327   1              for(i=15;i>0;i--)
 328   1              {
 329   2                      if(((~Black_Ground[i])&Map[i])!=Map[i])
 330   2                              return 1;             //移动1次方块和固定背景有接触
 331   2              }
 332   1              return 0;           //移动1次方块和固定背景无接触
 333   1      }
 334          
 335          uchar Attack_Frame()        //方块接触到游戏界面的边框(不包含底部)
 336          {                                               //已经假设向左,向右移动过
 337   1              if(horiz!=0)
 338   1              {horiz=0;return 1;}//接触到边框的时候格点对应的数据Map一个16位的变量对应15位或0位为1
 339   1              else return 0;//上面假设左移或者右移一位,则会对应有溢出或者借位对CY值1         
 340   1      }
 341          
 342          
 343          uchar Attack_Bottom()     //接触到底部(已经将设向下移动过一次)
 344          {//在方块刚出现挨着顶部的时候,左右的移动,同样Black_Ground[0]不为0,形成误判
 345   1              if(Draw_Block_To_BG_Flag==Down)//在设计如何方块下移移动的时候,将Black_Ground[16]的高字
 346   1                      if(Black_Ground[0]!=0)//和低字交换而Black_Ground[15]的数值循环到Black_Ground[0],
 347   1                              return 1; //只要检测到再次Black_Ground[0]不为0就知道上次下移是越界了
 348   1              return 0;
 349   1      }                                                
 350          
 351          
 352          void Transformer()
 353          {
 354   1              uint16 pic,i;
 355   1              J=(J+1)%4;    //循环求取当前方块4中模块中的后一种       
 356   1              Black_Ground[Block_Y]=0;
 357   1              Black_Ground[Block_Y+1]=0;
 358   1              Black_Ground[Block_Y+2]=0;
 359   1              Black_Ground[Block_Y+3]=0;//将当前模块从数组中清除,防止和新方块和现在的方块重叠
 360   1              pic=Pic[I][J];
 361   1              if(Block_X>=8)
 362   1              {       
 363   2                      Black_Ground[Block_Y]=_irol_((((pic>>6)&0x03c0)),Block_X-8);
 364   2                      Black_Ground[Block_Y+1]=_irol_((((pic>>2)&0x03c0)),Block_X-8);
 365   2                      Black_Ground[Block_Y+2]=_irol_((((pic<<2)&0x03c0)),Block_X-8);
C51 COMPILER V7.06   FUNCTION                                                              12/09/2008 01:11:01 PAGE 7   

 366   2                      Black_Ground[Block_Y+3]=_irol_((((pic<<6)&0x03c0)),Block_X-8);
 367   2                      for(i=0;i<4;i++)
 368   2                      {
 369   3                              horiz=horiz|(Black_Ground[Block_Y+i]&0x0001);
 370   3                              horiz=horiz<<1;
 371   3                      }
 372   2              }
 373   1              else
 374   1              {       
 375   2                      Black_Ground[Block_Y]=_iror_((((pic>>6)&0x03c0)),8-Block_X);
 376   2                      Black_Ground[Block_Y+1]=_iror_((((pic>>2)&0x03c0)),8-Block_X);
 377   2                      Black_Ground[Block_Y+2]=_iror_((((pic<<2)&0x03c0)),8-Block_X);
 378   2                      Black_Ground[Block_Y+3]=_iror_((((pic<<6)&0x03c0)),8-Block_X);
 379   2                      for(i=0;i<4;i++)
 380   2                      {
 381   3                              horiz=horiz|(Black_Ground[Block_Y+i]&0x8000);
 382   3                              horiz=horiz>>1;
 383   3                      }
 384   2              }
 385   1      }
 386          
 387          
 388          
 389          
 390          
 391          ///////////////////////////////////////////////////////////////////
 392          void Change()
 393          {
 394   1              uchar i;
 395   1              uint16 temp;
 396   1      ////////////////////////////////////////////////////
 397   1      //得到方块数点
 398   1              for(i=0;i<16;i++)
 399   1              {
 400   2                      Black_Ground[i]=(~Map[i])&Black_Ground[i];//Black_Ground数组中只有方块数点
 401   2              }
 402   1      //得到方块数点
 403   1      ///////////////////////////////////////////////////////
 404   1      
 405   1      //////////////////////////////////////////////////
 406   1              if(keyvalue==9)           //按键向左
 407   1              {       
 408   2                      for(i=0;i<4;i++)
 409   2                      {
 410   3                              Black_Ground[Block_Y+i]=_irol_(Black_Ground[Block_Y+i],1);
 411   3                              horiz=horiz|(Black_Ground[Block_Y+i]&0x0001);
 412   3                              horiz=horiz<<1;
 413   3                      }
 414   2                      Block_X++;      
 415   2                      if(Attack_Frame()|Attack_Block())//如果接触了左边框
 416   2                      {                                      //就不能向左移动 
 417   3                              for(i=0;i<4;i++)
 418   3                              {
 419   4                                      Black_Ground[Block_Y+i]=_iror_(Black_Ground[Block_Y+i],1);      
 420   4                              }
 421   3                              Block_X--;      
 422   3                      }       
 423   2              }               
 424   1              if(keyvalue==11)           //按键向右
 425   1              {
 426   2                      for(i=0;i<4;i++)
 427   2                      {
C51 COMPILER V7.06   FUNCTION                                                              12/09/2008 01:11:01 PAGE 8   

 428   3                              Black_Ground[Block_Y+i]=_iror_(Black_Ground[Block_Y+i],1);
 429   3                              horiz=horiz|(Black_Ground[Block_Y+i]&0x8000);
 430   3                              horiz=horiz>>1; 
 431   3                      }
 432   2                      Block_X--;
 433   2                      if(Attack_Frame()|Attack_Block())//如果接触了右边框
 434   2                      {                                      //就不能向右移动 
 435   3                              for(i=0;i<4;i++)
 436   3                              {
 437   4                                      Black_Ground[Block_Y+i]=_irol_(Black_Ground[Block_Y+i],1);      
 438   4                              }
 439   3                              Block_X++;
 440   3                      }               
 441   2              }
 442   1      ///////////////////////////////////////////////////////////////
 443   1      
 444   1      //////////////////////////////////////////////////////////////////
 445   1              if(keyvalue==14)           //如果按了变形按键
 446   1              {
 447   2                      Transformer();        //变换了方块
 448   2                      if(Attack_Frame()|Attack_Block()|Attack_Bottom())
 449   2                      {
 450   3                              J=(J+2)%4;//变回到原来的方块
 451   3                              Transformer();        //变换了方块
 452   3                      }               
 453   2              }
 454   1      /////////////////////////////////////////////////////////////////
 455   1      
 456   1      /////////////////////////////////////////////////////////////////
 457   1              if(keyvalue==8)           //如果按下了快速下落
 458   1                      {Quick_Down=1;}          //改变定时时间的初值
 459   1              if(Quick_Down==1)
 460   1                      keyvalue=10;
 461   1      /////////////////////////////////////////////////////////////////
 462   1      
 463   1      
 464   1      ///////////////////////////////////////////////////////////////
 465   1                              
 466   1              if((keyvalue==10)|(keyvalue1==2))           //按键向下或定时时间到
 467   1              {
 468   2                      temp=Black_Ground[15];
 469   2                      for(i=15;i>0;i--)
 470   2                      {
 471   3                              Black_Ground[i]=Black_Ground[i-1];              
 472   3                      }
 473   2                      Black_Ground[0]=temp;
 474   2                      Draw_Block_To_BG_Flag=Down;
 475   2                      Block_Y++;
 476   2                      if(Attack_Bottom()|Attack_Block())
 477   2                      {
 478   3                              temp=Black_Ground[0];
 479   3                              for(i=0;i<15;i++)
 480   3                              {
 481   4                                      Black_Ground[i]=Black_Ground[i+1];              

⌨️ 快捷键说明

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