本文主要是介绍MSP430 F5529 单片机 OLED 贪吃蛇 游戏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
做了一块MSP430 F5529转接板看起来漂亮一点,没有就直接用杜邦线接线。
https://blog.csdn.net/x1131230123/article/details/108772807
- Snake game. Each time the snake eats a piece of food, its tail grows longer, making the game
increasingly difficult. The user controls the direction of the snake’s head (up, down, left, or right), and
the snake’s body follows. Food is randomly generated, and if the snake hits a wall or its own tail, the
game ends. Keep score by how many turns or how much time the snake is alive。
1、
贪吃蛇游戏 OLED
功能:贪吃蛇游戏;可以上下左右;计算分数;20分一个档次提升贪吃蛇速度;
2、
最终效果:
3、
硬件:OLED和4个按键
OLED接线
// | P3.1|<- Data In (UCB0SOMI)
// | F5 P3.0|-> Data Out (UCB0SIMO) --D1(OLED)
// | P3.2|-> Serial Clock Out (UCB0CLK) --D0(OLED)
// | P2.0|->RES(OLED)
// | P2.2|->DC(OLED)
// | P8.1|->CS(OLED)
P6DIR &= ~( BIT3);P6OUT |= ( BIT3);P6REN |= ( BIT3);P6DIR &= ~( BIT4);P6OUT |= ( BIT4);P6REN |= ( BIT4);P7DIR &= ~( BIT0);P7OUT |= ( BIT0);P7REN |= ( BIT0);P3DIR &= ~( BIT6);P3OUT |= ( BIT6);P3REN |= ( BIT6);
4、
贪吃蛇运行过程:
//1 按键改变drection变量 从而改变方向
//2 按键驱动方向
//3 碰壁结束判断
//4 蛇头蛇尾显示
//5 改变蛇的坐标 蛇身体全部更新
//6 检查是否吃到了自己的身体
//7 检查是否吃到食物
//8 延时控制蛇身体移动速度
代码:
https://github.com/xddun/blog_code_search
这篇关于MSP430 F5529 单片机 OLED 贪吃蛇 游戏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!