IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> stm32f103指南者——实例小游戏俄罗斯方块 -> 正文阅读

[嵌入式]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();
    }

五、成果展示

在这里插入图片描述
在这里插入图片描述



  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2022-07-17 16:39:38  更:2022-07-17 16:42:30 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/18 14:08:21-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码