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)
joyx=100;
else if(Joypad.readButton(CH_SWITCH_4)==0)
joyx=-100;
if(Joypad.readButton(CH_SWITCH_1)==0)
joyy=-100;
else if(Joypad.readButton(CH_SWITCH_3)==0)
joyy=100;
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)
{
joyx=0;
joyy=0;
}
}
else
{
joyx = map(Joypad.readJoystickX(), -280, 300, 100, -100);
joyy = map(Joypad.readJoystickY(), -300, 230, -100, 100);
}
默认是右边拨动开关拨到上面是按键控制,否则摇杆控制,玩家可以更改切换选择方式。
Joypad.motor(0);//关闭
Joypad.motor(X);//0-255震动可调
digitalWrite(speak,LOW);//关闭
digitalWrite(speak,HIGH);//打开
步骤五:编译代码,成功后选择对应的板卡和COM端口下载。下载完毕后就可以进行体验了,可以在右上角看到你的分数。玩家可扩展用重力感应控制。 |