assets.pde 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. GD.begin();
  22. // Say "Gameduino ready"
  23. say("game");
  24. say("duino");
  25. delay(100);
  26. say("ready");
  27. // Load the pickups starting at sprite 0.
  28. // First copy pickups/pal into RAM_SPRPAL, then
  29. // pickups/img into RAM_SPRIMG.
  30. Asset a;
  31. a.open("pickups", "pal", NULL);
  32. a.load(RAM_SPRPAL);
  33. a.open("pickups", "img", NULL);
  34. a.load(RAM_SPRIMG);
  35. }
  36. void loop()
  37. {
  38. // Scatter sprites across the screen
  39. for (int i = 0; i < 256; i++)
  40. GD.sprite(i, random(400), random(300), random(47), 0, 0);
  41. // Play a random instrument from the 12 in the drumkit
  42. static const char *drums[12] = {
  43. "bassdrum2",
  44. "bassdrum4",
  45. "clap",
  46. "conga2",
  47. "conga3",
  48. "cowbell1",
  49. "cymbal1",
  50. "cymbal3",
  51. "hihat1",
  52. "hihat2",
  53. "snaredrum2",
  54. "snaredrum3"
  55. };
  56. Asset drum;
  57. drum.open("drumkit", drums[random(12)], NULL);
  58. playsample(drum);
  59. // Say "game over"
  60. say("game");
  61. say("over");
  62. }