stm32f103指南者——实例小游戏俄罗斯方块

编程入门 行业动态 更新时间:2024-10-08 18:31:33

stm32f103指南者——实例<a href=https://www.elefans.com/category/jswz/34/1769974.html style=小游戏俄罗斯方块"/>

stm32f103指南者——实例小游戏俄罗斯方块

stm32f103指南者——实例俄罗斯方块

一、stmf103指南者简介

  • 型号:STM32F103VET6
    • STM32表示32bit的MCU
    • F表示基础型
    • V表示100pin(即有100个引脚)
    • FLASH大小E表示521KB

二、开发心得

  • (为什么我要把心得放在第二块的位置,因为我真的觉得有些老师讲得真的就是喜欢站在自己的角度,来分析问题,然后觉得这些问题这么简单你们都不会亚。说什么,哎呀,你们学过C语言,模电数电学过吧,那你们去做个游戏吧…)
  • 作为一个学习者分享一下我自己的经历
    • 不要有畏难心理:编程只是技术,就像流水线上的工人。文件这么多都是厂商封装好的。如果想要编程做项目,浅浅理解一下stm32的机制完全足够了。
    • 初学可以找个例程来分析一下,看懂别人的程序真的对于知识的理解更加深刻。

三、主程序

#include "stm32f10x.h"
#include "./usart/bsp_usart.h"	
#include "./lcd/bsp_ili9341_lcd.h"
#include "./lcd/bsp_xpt2046_lcd.h"
#include "./flash/bsp_spi_flash.h"
#include "./led/bsp_led.h" 
#include "palette.h"
#include <string.h>
#include "bsp_TiMbase.h" int main(void)
{		/*函数名都已经表示好意思了,前面的*///LCD 初始化ILI9341_Init();  //触摸屏初始化XPT2046_Init();//从FLASH里获取校正参数,若FLASH无参数,则使用模式3进行校正Calibrate_or_Get_TouchParaWithFlash(6,0);BASIC_TIM_Init();  //	USART_Config();  LED_GPIO_Config();/*在这之前都是系统配置文件,初学者我们就不用动它了,大多数一些配置和define定义如果熟悉stm32的朋友可以试着去修改一下~下面是用户自己的初始化~~~*///绘制触游戏界面Palette_Init(LCD_SCAN_MODE);while ( 1 ){Drop();  //下落函数}}

四、主要思路

  • 界面数字化

    uint8_t shape_place_state[20][12] =  //地图数字化 1表示墙壁 2表示不动的方块 3表示正在下落的方块 此处为初始化界面
    {{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,0,0,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1,1,1}
    }; 
    
  • 游戏界面初始化

    void Palette_Init(uint8_t LCD_Mode)
    {uint8_t i;ADCx_Init();  //模数转化初始化,咱也不懂~ILI9341_GramScan ( LCD_Mode );score = 0;/* 整屏清为白色 */LCD_SetBackColor(CL_WHITE);ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);	Touch_Button_Init(); //初始按键设计 Square_Init();  //框架设计Tetris_Init();  //初始方格设计TIM_ITConfig(BASIC_TIM,TIM_IT_Update,ENABLE);  //中断部分/* 描绘按钮 */for(i=0;i<BUTTON_NUM;i++){button[i].draw_btn(&button[i]);}}
    
  • 俄罗斯方块设计

    • 因为某种原因随机数很不好用,会出现各种奇怪的情况,目前我也不知道怎么解决。
    void State_Init(){ //第一个下落方格的初始化和方块到达底部方块的重新生成char dis[20];srand(ADC_ConvertedValue);//随着ADC变化,产生不一样种子。shape_num = seed;/*sprintf(dis,"%d",shape_num);//打印LCD_SetFont(&Font8x16);LCD_SetColors(CL_BLACK,CL_WHITE);ILI9341_DispString_EN_CH(18,30,dis);*///shape_num = seed;switch(shape_num){case SHAPE_1:shape_place_state[0][6]=3;shape_place_state[0][5]=3;shape_place_state[0][7]=3;shape_place_state[1][6]=3;break;case SHAPE_2:shape_place_state[0][6]=3;shape_place_state[1][6]=3;shape_place_state[1][7]=3;shape_place_state[2][6]=3;break;case SHAPE_3:shape_place_state[0][6]=3;shape_place_state[1][6]=3;shape_place_state[1][5]=3;shape_place_state[1][7]=3;break;case SHAPE_4:shape_place_state[0][6]=3;shape_place_state[1][6]=3;shape_place_state[1][5]=3;shape_place_state[2][6]=3;break;case SHAPE_5:shape_place_state[0][6]=3;shape_place_state[0][7]=3;shape_place_state[1][6]=3;shape_place_state[1][5]=3;break;case SHAPE_6:shape_place_state[0][5]=3;shape_place_state[1][5]=3;shape_place_state[1][6]=3;shape_place_state[2][6]=3;break;case SHAPE_7:shape_place_state[0][6]=3;shape_place_state[0][5]=3;shape_place_state[1][6]=3;shape_place_state[1][7]=3;break;case SHAPE_8:shape_place_state[0][6]=3;shape_place_state[1][6]=3;shape_place_state[1][5]=3;shape_place_state[2][5]=3;break;case SHAPE_9:shape_place_state[0][6]=3;shape_place_state[0][7]=3;shape_place_state[0][5]=3;shape_place_state[0][4]=3;break;case SHAPE_10:shape_place_state[0][6]=3;shape_place_state[1][6]=3;shape_place_state[2][6]=3;shape_place_state[3][6]=3;break;case SHAPE_11:shape_place_state[0][6]=3;shape_place_state[0][5]=3;shape_place_state[1][5]=3;shape_place_state[1][6]=3;break;case SHAPE_12:shape_place_state[0][5]=3;shape_place_state[1][5]=3;shape_place_state[2][5]=3;shape_place_state[2][6]=3;break;case SHAPE_13:shape_place_state[0][5]=3;shape_place_state[1][5]=3;shape_place_state[0][7]=3;shape_place_state[0][6]=3;break;case SHAPE_14:shape_place_state[0][6]=3;shape_place_state[0][5]=3;shape_place_state[2][6]=3;shape_place_state[1][6]=3;break;case SHAPE_15:shape_place_state[0][7]=3;shape_place_state[1][5]=3;shape_place_state[1][7]=3;shape_place_state[1][6]=3;break;case SHAPE_16:shape_place_state[0][6]=3;shape_place_state[1][6]=3;shape_place_state[2][6]=3;shape_place_state[2][5]=3;break;case SHAPE_17:shape_place_state[0][5]=3;shape_place_state[1][5]=3;shape_place_state[1][7]=3;shape_place_state[1][6]=3;break;case SHAPE_18:shape_place_state[0][6]=3;shape_place_state[0][5]=3;shape_place_state[1][5]=3;shape_place_state[2][5]=3;break;case SHAPE_19:shape_place_state[0][6]=3;shape_place_state[0][5]=3;shape_place_state[0][7]=3;shape_place_state[1][7]=3;break;}}
    

附上这张图大家就应该明白了吧(红框是旋转的时候必须为空的格子)~

  • 给方块上色(每次更新shape_place_state[i] [j]时)

    void Create_Shape()  //刷新界面重塑界面上色
    {uint8_t i;uint8_t j;//LCD_SetColors(CL_GREEN,CL_WHITE);for(i=0;i<19;i++){for(j=1;j<11;j++){if(shape_place_state[i][j]==3){ //正在下落的方块LCD_SetColors(CL_GREEN,CL_WHITE);//(前景色,背景色)ILI9341_DrawRectangle(COLOR_BLOCK_WIDTH+(j-1)*15,15*i,15,15,1);  //画方格(x,y,方格的长,方格的宽,mode) mode=1实心=0空心}else if(shape_place_state[i][j]==0){//空白区域LCD_SetColors(CL_WHITE,CL_WHITE);ILI9341_DrawRectangle(COLOR_BLOCK_WIDTH+(j-1)*15,15*i,15,15,1);}else if(shape_place_state[i][j]==2){//落下后的方块LCD_SetColors(CL_RED,CL_WHITE);ILI9341_DrawRectangle(COLOR_BLOCK_WIDTH+(j-1)*15,15*i,15,15,1);}}}}
    
  • 主要循环函数

    void Drop(){//游戏不停运行的下落程序uint8_t i;uint8_t j;uint8_t c,x,y,flag=0;uint8_t count=0;uint8_t c_place[4][2] = {{0,0},{0,0},{0,0},{0,0}};//放置正在下落方块的参数(x,y)char disbuff[20];Delay(0xfffff);//可以调节下落的速度,里面是毫秒,越大速度越慢seed++;if(seed==19)seed = 0;if (die == 0 && MODE==1){for(i=0;i<19;i++){for(j=1;j<11;j++){if(shape_place_state[i][j]==3){c_place[count][0]=i;c_place[count][1]=j;count++;if(shape_place_state[i+1][j]==1 || shape_place_state[i+1][j]==2){flag += STOP;}else{flag += CONTINUE;}}}}for(c=0;c<count;c++){x = c_place[c][0];y = c_place[c][1];if(flag==CONTINUE){shape_place_state[x][y] = 0;}else{shape_place_state[x][y] = 2;//到达最底行judgeAlive(); //判断存活情况State_Init();//重新生成新的方块status = shape_num;/*sprintf(dis,"%d",shape_num);//打印成绩LCD_SetFont(&Font8x16);LCD_SetColors(CL_BLACK,CL_WHITE);ILI9341_DispString_EN_CH(18,30,dis);
    */if(die==1){LCD_SetColors(CL_RED,CL_WHITE);LCD_SetFont(&Font24x32);ILI9341_DispString_EN_CH(12,120,"Game over");TIM_ITConfig(BASIC_TIM,TIM_IT_Update,DISABLE);  //不使能中断,即不是能5个按键while(XPT2046_TouchDetect() != TOUCH_PRESSED);//按任意位置重新初始化die = 0;}judgeRemove(); //判断可否移除}}if(flag == CONTINUE){for(c=0;c<4;c++){shape_place_state[c_place[c][0]+1][c_place[c][1]] = 3;}}Create_Shape();}}
    
  • 按钮位置功能设计

    void Touch_Button_Init(void)
    {/*方向键*/button[0].start_x = BUTTON_START_X;     button[0].start_y = 320-COLOR_BLOCK_HEIGHT;button[0].end_x = BUTTON_START_X + COLOR_BLOCK_WIDTH ;button[0].end_y = 320;button[0].para = LEFT;button[0].touch_flag = 0;  button[0].draw_btn = Draw_Direction_Button;   button[0].btn_command = Command_Control_Direction ;  button[1].start_x = BUTTON_START_X + COLOR_BLOCK_WIDTH ;button[1].start_y = 320-COLOR_BLOCK_HEIGHT;button[1].end_x = 240-COLOR_BLOCK_WIDTH ;button[1].end_y = 320;button[1].para = SWITCH;button[1].touch_flag = 0;  button[1].draw_btn = Draw_Direction_Button;button[1].btn_command = Command_Control_Direction ;button[2].start_x = 240-COLOR_BLOCK_WIDTH;button[2].start_y = 320-COLOR_BLOCK_HEIGHT;button[2].end_x = 240;button[2].end_y = 320;button[2].para = RIGHT;button[2].touch_flag = 0;  button[2].draw_btn = Draw_Direction_Button;button[2].btn_command = Command_Control_Direction ;//下面是开始或暂停键  button[3].start_x = 240-COLOR_BLOCK_WIDTH;button[3].start_y = 0;button[3].end_x = 240 ;button[3].end_y = COLOR_BLOCK_HEIGHT;button[3].para = 0;button[3].touch_flag = 0;  button[3].draw_btn = Draw_Mode_Button ;button[3].btn_command = Command_Change_Mode;}
    
  • 暂停继续按键设计

    static void Draw_Mode_Button(void *btn)
    {Touch_Button *ptr = (Touch_Button *)btn;uint16_t RGB;if(ptr->touch_flag == 0){LCD_SetColors(CL_BUTTON_GREY,CL_WHITE);ILI9341_DrawRectangle(	ptr->start_x,ptr->start_y,ptr->end_x - ptr->start_x,ptr->end_y - ptr->start_y,1);RGB = CL_BUTTON_GREY;}else  /*按键按下*/{LCD_SetColors(CL_WHITE,CL_WHITE);ILI9341_DrawRectangle(ptr->start_x,ptr->start_y,ptr->end_x - ptr->start_x,ptr->end_y - ptr->start_y,1);RGB = CL_WHITE;} LCD_SetColors(CL_BLUE4,CL_WHITE);ILI9341_DrawRectangle(ptr->start_x,ptr->start_y,ptr->end_x - ptr->start_x,ptr->end_y - ptr->start_y,0);LCD_SetColors(CL_BLACK,RGB);LCD_SetFont(&Font8x16);if(MODE){ILI9341_DispString_EN_CH( ptr->start_x + (ptr->end_x - ptr->start_x - 16*2)/2,ptr->start_y+ ((ptr->end_y - ptr->start_y-16)/2),	"暂停");}else{ILI9341_DispString_EN_CH( ptr->start_x + (ptr->end_x - ptr->start_x - 16*2)/2,ptr->start_y+ ((ptr->end_y - ptr->start_y-16)/2),	"继续");}
    }
    
  • 方向键设计

    static void Draw_Direction_Button(void *btn)
    {Touch_Button *ptr = (Touch_Button *)btn;uint16_t RGB;if(ptr->touch_flag == 0){LCD_SetColors(CL_BUTTON_GREY,CL_WHITE);ILI9341_DrawRectangle(	ptr->start_x,ptr->start_y,ptr->end_x - ptr->start_x,ptr->end_y - ptr->start_y,1);RGB = CL_BUTTON_GREY;}else  /*按键按下*/{LCD_SetColors(CL_WHITE,CL_WHITE);ILI9341_DrawRectangle(ptr->start_x,ptr->start_y,ptr->end_x - ptr->start_x,ptr->end_y - ptr->start_y,1);RGB = CL_WHITE;} LCD_SetColors(CL_BLUE4,CL_WHITE);ILI9341_DrawRectangle(ptr->start_x,ptr->start_y,ptr->end_x - ptr->start_x,ptr->end_y - ptr->start_y,0);LCD_SetColors(CL_BLACK,RGB);LCD_SetFont(&Font8x16);/*根据按键方向写字*/switch(ptr->para){case LEFT:      LCD_SetColors(CL_BLACK,RGB);ILI9341_DispString_EN_CH( ptr->start_x + (ptr->end_x - ptr->start_x - 16)/2,
    //																ptr->start_y+15,ptr->start_y+ ((ptr->end_y - ptr->start_y-16)/2),	"左");break;   case SWITCH:LCD_SetColors(CL_BLACK,RGB);ILI9341_DispString_EN_CH( ptr->start_x + (ptr->end_x - ptr->start_x - 16)/2,
    //																ptr->start_y+15,ptr->start_y+ ((ptr->end_y - ptr->start_y-16)/2),	"旋转");break;case RIGHT:LCD_SetColors(CL_BLACK,RGB);ILI9341_DispString_EN_CH( ptr->start_x + (ptr->end_x - ptr->start_x - 16)/2,
    //																ptr->start_y+15,ptr->start_y+ ((ptr->end_y - ptr->start_y-16)/2),	"右");break;}}
    
  • 运动方向及改变形状(这里旋转的定位算法是我觉得最得意的)

    static void Command_Control_Direction(void *btn)
    {uint8_t i,j,cnt=0,x,y,flag=0;uint8_t minx,miny;uint8_t c_place[4][2]={0,0,0,0,0,0,0,0};Touch_Button *ptr = (Touch_Button *)btn;for(i=0;i<19;i++){for(j=1;j<11;j++){if(shape_place_state[i][j]==3){c_place[cnt][0] = i;c_place[cnt][1] = j;cnt++;}}if(cnt==4){break;}}for(i=0;i<4;i++){x = c_place[i][0];y = c_place[i][1];if(shape_place_state[x][y-1]==1||shape_place_state[x][y-1]==2){flag=1;//flag=1表示不能左移移动break;}else if(shape_place_state[x][y+1]==1||shape_place_state[x][y+1]==2){flag=2;//不能右移break;}else{flag=0;}}if(ptr->para==LEFT && flag!=1){for(i=0;i<4;i++){shape_place_state[c_place[i][0]][c_place[i][1]]=0;}for(i=0;i<4;i++){shape_place_state[c_place[i][0]][c_place[i][1]-1] = 3;}}if(ptr->para==RIGHT && flag!=2){for(i=0;i<4;i++){shape_place_state[c_place[i][0]][c_place[i][1]]=0;}for(i=0;i<4;i++){shape_place_state[c_place[i][0]][c_place[i][1]+1] = 3;}}if(ptr->para==SWITCH){ //方块的旋转minx = minValue(c_place[0][0],c_place[1][0],c_place[2][0],c_place[3][0]);miny = minValue(c_place[0][1],c_place[1][1],c_place[2][1],c_place[3][1]);switch(status){case SHAPE_1:if(shape_place_state[minx+1][miny]==0 && shape_place_state[minx+1][miny+2]==0){status = SHAPE_2;shape_place_state[minx][miny]=0;shape_place_state[minx-1][miny+1]= 3;}break;case SHAPE_2:if(shape_place_state[minx][miny+1]==0 && shape_place_state[minx+2][miny+1]==0){status = SHAPE_3;shape_place_state[minx+2][miny]=0;shape_place_state[minx+1][miny-1]= 3;}break;case SHAPE_3:if(shape_place_state[minx][miny]==0 && shape_place_state[minx][miny+2]==0){status = SHAPE_4;shape_place_state[minx+1][miny+2]=0;shape_place_state[minx+2][miny+1]= 3;}break;case SHAPE_4:if(shape_place_state[minx][miny]==0 && shape_place_state[minx+2][miny]==0){status = SHAPE_1;shape_place_state[minx][miny+1]=0;shape_place_state[minx+1][miny+2]= 3;}break;case SHAPE_5:if(shape_place_state[minx][miny]==0 && shape_place_state[minx-1][miny]==0&& shape_place_state[minx-1][miny+1]==0 && shape_place_state[minx-1][miny+2]==0	){status = SHAPE_6;shape_place_state[minx+1][miny]=0;shape_place_state[minx][miny+2]=0;shape_place_state[minx][miny]= 3;shape_place_state[minx-1][miny]= 3;}break;case SHAPE_6:if(shape_place_state[minx][miny+1]==0 && shape_place_state[minx][miny+2]==0&& shape_place_state[minx+1][miny+2]==0 && shape_place_state[minx+2][miny]==0	){status = SHAPE_5;shape_place_state[minx][miny]=0;shape_place_state[minx+1][miny]=0;shape_place_state[minx+2][miny]= 3;shape_place_state[minx+1][miny+2]= 3;}break;case SHAPE_7:if(shape_place_state[minx-1][miny]==0 && shape_place_state[minx-1][miny+1]==0&& shape_place_state[minx][miny+2]==0 && shape_place_state[minx-1][miny+2]==0	){status = SHAPE_8;shape_place_state[minx][miny]=0;shape_place_state[minx+1][miny+2]=0;shape_place_state[minx][miny+2]= 3;shape_place_state[minx-1][miny+2]= 3;}break;case SHAPE_8:if(shape_place_state[minx][miny]==0 && shape_place_state[minx][miny-1]==0&& shape_place_state[minx+1][miny-1]==0 && shape_place_state[minx+2][miny+1]==0	){status = SHAPE_7;shape_place_state[minx][miny+1]=0;shape_place_state[minx+1][miny+1]=0;shape_place_state[minx+1][miny-1]= 3;shape_place_state[minx+2][miny+1]= 3;}break;case SHAPE_9:if(shape_place_state[minx+1][miny]==0 && shape_place_state[minx+1][miny+1]==0&& shape_place_state[minx-1][miny+1]==0 && shape_place_state[minx-1][miny+2]==0	&&shape_place_state[minx-1][miny+3]==0 && shape_place_state[minx-2][miny+1]==0&& shape_place_state[minx-2][miny+2]==0 && shape_place_state[minx-2][miny+3]==0	){status = SHAPE_10;shape_place_state[minx][miny]=0;shape_place_state[minx][miny+2]=0;shape_place_state[minx][miny+3]= 0;shape_place_state[minx+1][miny+1]= 3;shape_place_state[minx-1][miny+1]= 3;shape_place_state[minx-2][miny+1]= 3;}break;case SHAPE_10:if(shape_place_state[minx][miny+1]==0 && shape_place_state[minx][miny+2]==0&& shape_place_state[minx+1][miny+1]==0 && shape_place_state[minx+1][miny+2]==0	&&shape_place_state[minx+2][miny+1]==0 && shape_place_state[minx+2][miny+2]==0&& shape_place_state[minx+2][miny-1]==0 && shape_place_state[minx+3][miny-1]==0	){status = SHAPE_9;shape_place_state[minx][miny]=0;shape_place_state[minx+1][miny]=0;shape_place_state[minx+3][miny]= 0;shape_place_state[minx+2][miny-1]= 3;shape_place_state[minx+2][miny+1]= 3;shape_place_state[minx+2][miny+2]= 3;}break;case SHAPE_12:if(shape_place_state[minx][miny+1]==0 && shape_place_state[minx][miny+2]==0&& shape_place_state[minx+1][miny+1]==0 && shape_place_state[minx+1][miny+2]==0	){status = SHAPE_13;shape_place_state[minx+2][miny]=0;shape_place_state[minx+2][miny+1]=0;shape_place_state[minx][miny+1]= 3;shape_place_state[minx][miny+2]= 3;}break;case SHAPE_13:if(shape_place_state[minx+1][miny+1]==0 && shape_place_state[minx+1][miny+2]==0&& shape_place_state[minx+2][miny+1]==0 && shape_place_state[minx+2][miny+2]==0	){status = SHAPE_14;shape_place_state[minx][miny]=0;shape_place_state[minx+1][miny]=0;shape_place_state[minx+1][miny+2]= 3;shape_place_state[minx+2][miny+2]= 3;}break;case SHAPE_14:if(shape_place_state[minx+1][miny]==0 && shape_place_state[minx+1][miny-1]==0&& shape_place_state[minx+2][miny-1]==0 && shape_place_state[minx+2][miny]==0	){status = SHAPE_15;shape_place_state[minx][miny]=0;shape_place_state[minx+2][miny+1]=0;shape_place_state[minx+1][miny]= 3;shape_place_state[minx+1][miny-1]= 3;}break;case SHAPE_15:if(shape_place_state[minx][miny]==0 && shape_place_state[minx][miny+1]==0&& shape_place_state[minx-1][miny]==0 && shape_place_state[minx-1][miny+1]==0	){status = SHAPE_12;shape_place_state[minx][miny+2]=0;shape_place_state[minx+1][miny+2]=0;shape_place_state[minx][miny]= 3;shape_place_state[minx-1][miny]= 3;}break;case SHAPE_16:if(shape_place_state[minx][miny]==0 && shape_place_state[minx][miny-1]==0&& shape_place_state[minx+1][miny-1]==0 && shape_place_state[minx+1][miny]==0	){status = SHAPE_17;shape_place_state[minx][miny+1]=0;shape_place_state[minx+1][miny+1]=0;shape_place_state[minx+1][miny-1]= 3;shape_place_state[minx+2][miny-1]= 3;}break;case SHAPE_17:if(shape_place_state[minx][miny+1]==0 && shape_place_state[minx][miny+2]==0&& shape_place_state[minx-1][miny+1]==0 && shape_place_state[minx-1][miny+2]==0	){status = SHAPE_18;shape_place_state[minx+1][miny+1]=0;shape_place_state[minx+1][miny+2]=0;shape_place_state[minx-1][miny]= 3;shape_place_state[minx-1][miny+1]= 3;}break;case SHAPE_18:if(shape_place_state[minx+1][miny+1]==0 && shape_place_state[minx+1][miny+2]==0&& shape_place_state[minx+2][miny+1]==0 && shape_place_state[minx+2][miny+2]==0	){status = SHAPE_19;shape_place_state[minx+1][miny]=0;shape_place_state[minx+2][miny]=0;shape_place_state[minx+1][miny+2]= 3;shape_place_state[minx][miny+2]= 3;}break;case SHAPE_19:if(shape_place_state[minx+1][miny]==0 && shape_place_state[minx+1][miny+1]==0&& shape_place_state[minx+2][miny]==0 && shape_place_state[minx+2][miny+1]==0	){status = SHAPE_16;shape_place_state[minx][miny]=0;shape_place_state[minx][miny+1]=0;shape_place_state[minx+2][miny+ 1]= 3;shape_place_state[minx+2][miny+2]= 3;}break;}}Create_Shape();
    }
    
      && shape_place_state[minx+2][miny+1]==0 && shape_place_state[minx+2][miny+2]==0	){status = SHAPE_19;shape_place_state[minx+1][miny]=0;shape_place_state[minx+2][miny]=0;shape_place_state[minx+1][miny+2]= 3;shape_place_state[minx][miny+2]= 3;}break;case SHAPE_19:if(shape_place_state[minx+1][miny]==0 && shape_place_state[minx+1][miny+1]==0&& shape_place_state[minx+2][miny]==0 && shape_place_state[minx+2][miny+1]==0	){status = SHAPE_16;shape_place_state[minx][miny]=0;shape_place_state[minx][miny+1]=0;shape_place_state[minx+2][miny+ 1]= 3;shape_place_state[minx+2][miny+2]= 3;}break;}
    

    }
    Create_Shape();
    }

五、成果展示


更多推荐

stm32f103指南者——实例小游戏俄罗斯方块

本文发布于:2024-03-07 21:43:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1718980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小游戏   俄罗斯方块   实例   指南

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!