Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #include <string.h>
  2. #include "system.h"
  3. #include "tinygl.h"
  4. #include "task.h"
  5. #include "navswitch.h"
  6. #include "eeprom.h"
  7. #include "uint8toa.h"
  8. #include "../fonts/font3x5_1.h"
  9. #include "pacer.h"
  10. #include <avr/io.h>
  11. #include "tweeter.h"
  12. #include "mmelody.h"
  13. #include "button.h"
  14. #include "pio.h"
  15. #include <stdbool.h>
  16. #include "ir_serial.h"
  17. #include "ir.h"
  18. #include "move.h"
  19.  
  20. #define PACER_RATE 500
  21. #define MESSAGE_RATE 20
  22.  
  23. //Ready pending bool
  24. static _Bool ready;
  25.  
  26. //Initialise the ready bool to false
  27. static void ready_screen_init(void)
  28. {
  29. ready = false;
  30. }
  31.  
  32. //Task: ready is now true
  33. static void ready_screen_task(void)
  34. {
  35. ready = true;
  36. }
  37.  
  38. //Initialising tinygl to scroll and rotate
  39. static void tinygl_task_init(void)
  40. {
  41. tinygl_font_set(&font3x5_1);
  42. tinygl_text_speed_set(MESSAGE_RATE);
  43. tinygl_text_mode_set(TINYGL_TEXT_MODE_SCROLL);
  44. tinygl_text_dir_set (TINYGL_TEXT_DIR_ROTATE);
  45. }
  46.  
  47. //IR error message
  48. static void show_err (uint8_t err)
  49. {
  50. char buffer[3];
  51.  
  52. buffer[0] = 'E';
  53. buffer[1] = err + '0';
  54. buffer[2] = 0;
  55. tinygl_text (buffer);
  56. }
  57.  
  58. //Ready-state loop; shows message READY? while sending and checking for
  59. //1's transmitted via serial ir
  60. static void ready_loop (void)
  61. {
  62. tinygl_clear();
  63. tinygl_text("READY?");
  64. ir_serial_transmit (1);
  65. while (1) {
  66. uint8_t data;
  67. pacer_wait();
  68. tinygl_update();
  69. ir_serial_ret_t ret;
  70. ret = ir_serial_receive (&data);
  71. if (ret == IR_SERIAL_OK) {
  72. if (data == 1) {
  73. ir_serial_transmit (1);
  74. return;
  75. }
  76. } else if (ret < 0) {
  77. show_err (-ret);
  78. }
  79. }
  80. }
  81.  
  82. //The game function
  83. static void game (void)
  84. {
  85. move();
  86. }
  87.  
  88.  
  89. int main (void)
  90. {
  91. //Initiation
  92. ready_screen_init();
  93. button_init();
  94. system_init();
  95. ir_serial_init();
  96. pacer_init (PACER_RATE);
  97. tinygl_init(PACER_RATE);
  98. tinygl_task_init();
  99. //Intro screen
  100. tinygl_text("SUPER DODGEBALL 9000");
  101.  
  102. while(1)
  103. {
  104. pacer_wait();
  105. tinygl_update();
  106. button_update();
  107. //Break out of Intro screen and into the Ready loop
  108. if (button_push_event_p(BUTTON1) && !ready) {
  109. ready_screen_task();
  110. ready_loop();
  111. //When both players are ready, start the game
  112. tinygl_clear();
  113. tinygl_text("GAME START!");
  114. game();
  115. }
  116. }
  117. return 0;
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement