assets.ino 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <SPI.h>
  2. #include <GD.h>
  3. static void playsample(Asset &a)
  4. {
  5. while (a.available()) {
  6. byte b;
  7. a.read(&b, 1);
  8. GD.wr(SAMPLE_L + 1, b);
  9. GD.wr(SAMPLE_R + 1, b);
  10. delayMicroseconds(80);
  11. }
  12. }
  13. static void say(const char *word)
  14. {
  15. Asset a;
  16. a.open("voice", word, NULL);
  17. playsample(a);
  18. }
  19. void setup()
  20. {
  21. // Serial.begin(1000000); // JCB
  22. GD.begin();
  23. // Say "Gameduino ready"
  24. say("game");
  25. say("duino");
  26. delay(100);
  27. say("ready");
  28. // Load the pickups starting at sprite 0.
  29. // First copy pickups/pal into RAM_SPRPAL, then
  30. // pickups/img into RAM_SPRIMG.
  31. Asset a;
  32. a.open("pickups", "pal", NULL);
  33. a.load(RAM_SPRPAL);
  34. a.open("pickups", "img", NULL);
  35. a.load(RAM_SPRIMG);
  36. }
  37. void loop()
  38. {
  39. // Scatter sprites across the screen
  40. for (int i = 0; i < 256; i++)
  41. GD.sprite(i, random(400), random(300), random(47), 0, 0);
  42. // Play a random instrument from the 12 in the drumkit
  43. static const char *drums[12] = {
  44. "bassdrum2",
  45. "bassdrum4",
  46. "clap",
  47. "conga2",
  48. "conga3",
  49. "cowbell1",
  50. "cymbal1",
  51. "cymbal3",
  52. "hihat1",
  53. "hihat2",
  54. "snaredrum2",
  55. "snaredrum3"
  56. };
  57. Asset drum;
  58. drum.open("drumkit", drums[random(12)], NULL);
  59. playsample(drum);
  60. // Say "game over"
  61. say("game");
  62. say("over");
  63. }