Difference between revisions of "Joypad-Game-Snake"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{| style="width: 800px;" |- | ==Outline== We adopt Microduino-Joypad-Game to play the game of Snake. ==Bill of Material== *Microduino Equipment {|class="wikitable" |- |Modul...")
 
 
(One intermediate revision by one other user not shown)
Line 19: Line 19:
 
[[File: Microduino-Joypad-snake.jpg|600px|center|thumb]]
 
[[File: Microduino-Joypad-snake.jpg|600px|center|thumb]]
 
==Download==
 
==Download==
TFT library:https://github.com/wasdpkj/libraries/tree/master/_01_Microduino_TFT
+
TFT library: https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Libraries/_01_Microduino_TFT_ST7735
 +
Joypad lib: https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Libraries/_08_Microduino_Shield_Joypad
  
Joypad library:https://github.com/wasdpkj/libraries/tree/master/_08_Microduino_Shield_Joypad
+
Code:  
 
 
Code:
 
 
[https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Joypad/Microduino_JoyPad_Game Microduino_JoyPad_Game]
 
[https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Joypad/Microduino_JoyPad_Game Microduino_JoyPad_Game]
  
Line 70: Line 69:
 
</source>
 
</source>
  
*You can change color in “colour.h”.   
+
*You can change color in "colour.h".   
  
 
Step 5: Compile the code and select the right board and COM port for download after successful compiling.   
 
Step 5: Compile the code and select the right board and COM port for download after successful compiling.   
 
*Experience: 
 
*Experience: 
**The initialized picture will remind you “Please move to start”. You can move to the right or press the key of “2” to enter the game.   
+
**The initialized picture will remind you "Please move to start". You can move to the right or press the key of "2" to enter the game.   
 
**It will show the score after the game is over.   
 
**It will show the score after the game is over.   
 
|}
 
|}

Latest revision as of 08:45, 13 September 2016

Outline

We adopt Microduino-Joypad-Game to play the game of Snake.

Bill of Material

  • Microduino Equipment
Module Number Function
Microduino-Core 1 Core
Microduino-USBTTL 1 Program download
Microduino-Joypad 1

Download

TFT library: https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Libraries/_01_Microduino_TFT_ST7735 Joypad lib: https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Libraries/_08_Microduino_Shield_Joypad

Code: Microduino_JoyPad_Game

Debuging

  • Step 4: Open program example.
    • Switch the code of the joystick and the button control:
    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;
  }

Button control is the default setting by turning the right switches to the top. Users can change the way of switch.

  • Vibration motor control:
Joypad.motor(0);//Close 
Joypad.motor(X);//0-255 The vibration is adjustable.
  • You can change color in "colour.h".

Step 5: Compile the code and select the right board and COM port for download after successful compiling.

  • Experience: 
    • The initialized picture will remind you "Please move to start". You can move to the right or press the key of "2" to enter the game.
    • It will show the score after the game is over.