Space invaders with a nRF2401A wireless joypad
Dependencies: Gameduino mbed nRF2401A
Fork of Gameduino_Invaders_game by
main.cpp
00001 #include "mbed.h" 00002 #include "GD.h" 00003 #include "shield.h" 00004 GDClass GD(ARD_MOSI, ARD_MISO, ARD_SCK, ARD_D9, USBTX, USBRX) ; 00005 00006 /*--------------------------------------------------------- 00007 A Space Invaders clone for Gameduino 00008 00009 http://www.artlum.com/gameduino/gameduino.html#invaders 00010 00011 Version 0.9 alpha - Still seme things to add 00012 but I'm out of memory! 00013 00014 Edit "joystick.cpp" if you have a custom joystick. 00015 ---------------------------------------------------------*/ 00016 00017 #include "game.h" 00018 #include "arduino.h" 00019 00020 #include "nRF2401A.h" 00021 00022 #define WIRELESS 00023 nRF2401A wireless_joypad(p10, p11, p12, p13, p14);//ce, cs, dr1, clk1, data 00024 uint8_t wireless_dpad = 0; 00025 uint8_t wireless_buttons = 0; 00026 DigitalOut debug(LED1); 00027 00028 void nRF2401A_rx (void *arg) 00029 { 00030 wireless_dpad = wireless_joypad.readMsg_byte( 0 ); 00031 wireless_buttons = wireless_joypad.readMsg_byte( 1 ); 00032 debug = !debug; 00033 } 00034 00035 void setup() { 00036 GD.begin(); 00037 #ifdef WIRELESS 00038 wait(0.005); 00039 wireless_joypad.setAddress(0x0, 0x0, 0x53, 0x53, 0x53, 3 << 3); 00040 00041 wireless_joypad.flushControlPacket(); 00042 wireless_joypad.attachRXHandler(&nRF2401A_rx, 0); 00043 #endif 00044 makeGraphics(); 00045 Coprocessor::reset(samplePlaybackBuffer); 00046 randomSeed(GD.rd(FRAME)); 00047 resetGameSounds(); 00048 initGame(); 00049 } 00050 00051 void loop() { 00052 GD.waitvblank(); 00053 updateGame(); 00054 updateGameSounds(); 00055 00056 // Debugging/info 00057 if (0) { 00058 joystick.dump(0,33); // Show the joystick state 00059 int yline = Coprocessor::yline(); 00060 showNumber(yline,0,31); 00061 } 00062 // Screenshot when you press the select button 00063 if (0 and joystick.isPressed(Joystick::buttonSelect)) { 00064 sendScreenshot(); 00065 } 00066 } 00067 00068 00069 int main() { 00070 setup(); 00071 while (1) { 00072 loop(); 00073 } 00074 }
Generated on Fri Jul 15 2022 06:07:12 by 1.7.2