《俄罗斯方块》(Tetris, 俄文:Тетрис)是一款由俄罗斯人阿列克谢·帕基特诺夫于1984年6月发明的休闲游戏。
该游戏曾经被多家公司代理过。经过多轮诉讼后,该游戏的代理权最终被任天堂获得。 [1] 任天堂对于俄罗斯方块来说意义重大,因为将它与GB搭配在一起后,获得了巨大的成功。
《俄罗斯方块》的基本规则是移动、旋转和摆放游戏自动输出的各种方块,使之排列成完整的一行或多行并且消除得分。
1.硬件平台
STM32开发板
3.5寸LCD屏(16位并口8080时序)
字库存储W25Q64(SPI)
4个按键
2.方块示例
本设计中方块种类共5种,根据方向的不同可分为19种可能性。
3.游戏效果图
1.游戏结束效果。当方块堆叠触碰到上顶端,则游戏结束。
2.正常游戏和方块颜色分配,下一个方块提示,积分统计,按键操作说明。
3.消行效果展示,得分获取。
软件设计中,消除一行得1分,消除两行得2分,消除3行得4分,消除4行得8分。
4.软件设计
1.单个方块绘制和清除一行处理
/*************绘制单个方块**************/
void Lcd_DrawDiamond(u16 x,u16 y,u16 c)
{
u16 i;
LcdWriteReg(0x2A);//设置x坐标
LcdWriteData((x>>8)&0xff);//x坐标高8位
LcdWriteData(x&0xff);//x坐标低8位
LcdWriteData(((x+8)>>8)&0xff);//x坐标高8位
LcdWriteData((x+8)&0xff);//x坐标低8位
LcdWriteReg(0x2B);//设置Y坐标
LcdWriteData((y>>8)&0xff);//Y坐标高8位
LcdWriteData(y&0xff);//Y坐标低8位
LcdWriteData(((y+8)>>8)&0xff);//Y坐标高8位
LcdWriteData((y+8)&0xff);//Y坐标低8位
LcdWriteReg(0x2C);//设置x坐标
for(i=0;i<9*9;i++)LcdWriteData(c);
}
/******************消除一行*******************/
void Lcd_ClearOneLineDisplay(u16 y,u16 c)
{
u16 i=0;
for(i=2;i;i+=10)>
2.绘制各个方块,设置方块颜色
/*每一个种类的颜色*/
/*
1 -- DARKBLUE --Drawshape_color[0]
2,3 -- BRRED --Drawshape_color[1]
4,5,6,7 -- BLUE --Drawshape_color[2]
8,9,10,11,12,13,14,15 -- GRAY --Drawshape_color[3]
16,17,18,19 --BLACK -- Drawshape_color[4]
*/
const u16 Drawshape_color[]={DARKBLUE,BRRED,BLUE,GRAY,BLACK};
/*******************绘制一个俄罗斯方块***************************
**形参:x,y -- 要显示的位置
** what --要绘制的方块序号(1~19)
** c --方块颜色
** stat --更新到二维数组中的状态(0表示清除,1表示写入状态)
*******************************************************************/
void Lcd_Drawshape(u16 x,u16 y,u8 what,u16 c,u8 stat)
{
switch (what)
{
case 1:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
}
break;
case 2:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+20,y,c);
Lcd_DrawDiamond(x+30,y,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+20,y,stat);
Lcd_Refreshbuff(x+30,y,stat);
}
break;
case 3:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x,y+20,c);
Lcd_DrawDiamond(x,y+30,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x,y+20,stat);
Lcd_Refreshbuff(x,y+30,stat);
}
break;
case 4:
{
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+20,y+10,c);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+20,y+10,stat);
}
break;
case 5:
{
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x,y+20,c);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x,y+20,stat);
}
break;
case 6:
{
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+10,y+20,c);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+10,y+20,stat);
}
break;
case 7:
{
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+20,y,c);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+20,y,stat);
}
break;
case 8:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x,y+20,c);
Lcd_DrawDiamond(x+10,y+20,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x,y+20,stat);
Lcd_Refreshbuff(x+10,y+20,stat);
}
break;
case 9:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+20,y,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+20,y,stat);
}
break;
case 10:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+10,y+20,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+10,y+20,stat);
}
break;
case 11:
{
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+20,y+10,c);
Lcd_DrawDiamond(x+20,y,c);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+20,y+10,stat);
Lcd_Refreshbuff(x+20,y,stat);
}
break;
case 12:
{
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+10,y+20,c);
Lcd_DrawDiamond(x,y+20,c);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+10,y+20,stat);
Lcd_Refreshbuff(x,y+20,stat);
}
break;
case 13:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+20,y,c);
Lcd_DrawDiamond(x+20,y+10,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+20,y,stat);
Lcd_Refreshbuff(x+20,y+10,stat);
}
break;
case 14:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x,y+20,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x,y+20,stat);
}
break;
case 15:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+20,y+10,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+20,y+10,stat);
}
break;
case 16:
{
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x,y+20,c);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x,y+20,stat);
}
break;
case 17:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+20,y+10,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x+10,y,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+20,y+10,stat);
}
break;
case 18:
{
Lcd_DrawDiamond(x,y,c);
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+10,y+20,c);
Lcd_Refreshbuff(x,y,stat);
Lcd_Refreshbuff(x,y+10,stat);
Lcd_Refreshbuff(x+10,y+10,stat);
Lcd_Refreshbuff(x+10,y+20,stat);
}
break;
case 19:
{
Lcd_DrawDiamond(x,y+10,c);
Lcd_DrawDiamond(x+10,y+10,c);
Lcd_DrawDiamond(x+10,y,c);
Lcd_DrawDiamond(x+20,y,c);
Lcd_Refreshbuff(x,y+10,stat);
上一篇:如何用一个ESP8266加上STM32单片机做一个小产品?
下一篇:简述温度传感器DS18B20原理内附STM32例程代码
推荐阅读最新更新时间:2024-11-17 01:06
设计资源 培训 开发板 精华推荐
- 使用 Analog Devices 的 LT1585CT-3.38 的参考设计
- 使用 Analog Devices 的 AD9525BCPZ 的参考设计
- k270改TP4056pad触控开关小键盘
- HC-05 蓝牙模块 原理图 PCB 及指令说明
- VLG-MC9S12ZVC: S12ZVC 16位混合信号MagniV MCU评估板
- NUCLEO-F439ZI,STM32 Nucleo-144开发板,带STM32F439ZIT6 MCU,支持Arduino、ST Zio和Morpho
- NCP3063SMINVGEVB:DFN 逆变器演示评估板
- 15 节锂离子电池控制器模拟前端参考设计
- LT6656BCDC-4.096、4.096V 低功率 ADC 电压基准的典型应用
- LT3755IMSE-2 降压模式 500mA LED 驱动器的典型应用电路,用于 20kHz PWM 调光