Joypad-Game-贪吃蛇
概述我们采用Microduino-Joypad-Game来实现贪吃蛇游戏。 材料清单
下载TFT库:https://github.com/wasdpkj/libraries/tree/master/_01_Microduino_TFT Joypad库:https://github.com/wasdpkj/libraries/tree/master/_08_Microduino_Shield_Joypad 调试
if(Joypad.readButton(CH_SWITCH_R))
{
if(Joypad.readButton(CH_SWITCH_2)==0)
Joy=3;
else if(Joypad.readButton(CH_SWITCH_4)==0)
Joy=2;
if(Joypad.readButton(CH_SWITCH_1)==0)
Joy=1;
else if(Joypad.readButton(CH_SWITCH_3)==0)
Joy=4;
else if(Joypad.readButton(CH_SWITCH_1)==1&&Joypad.readButton(CH_SWITCH_2)==1&&Joypad.readButton(CH_SWITCH_3)==1&&Joypad.readButton(CH_SWITCH_4)==1)
Joy=0;
}
else
{
if(x>280||x1>280)
Joy=2;//
else if(x<-280||x1<-280)
Joy=3;//
else if(y<-280||y1<-280)
Joy=1;
else if(y>280||y1>280)
Joy=4;
else
Joy=0;
}
默认是右边拨动开关拨到上面是按键控制,否则摇杆控制,玩家可以更改切换选择方式。
Joypad.motor(0);//关闭
Joypad.motor(X);//0-255震动可调
步骤五:编译代码,成功后选择对应的板卡和COM端口下载。下载完毕后就可以进行体验了。
|