Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include "PongGame.h"
  2.  
  3. const int nrow = 8;
  4. const int ncol = 8;
  5.  
  6. PongGame pongGame(nrow, ncol);
  7. int* buffer = new int[nrow * ncol];
  8.  
  9. const int buttons[] = {9, 8, 13, 12, 7};
  10. int prev[] = {LOW, LOW, LOW, LOW, LOW};
  11.  
  12. void setup() {
  13. Serial.begin(9600);
  14. for (int i = 0; i < 5; i++) {
  15. pinMode(buttons[i], INPUT_PULLUP);
  16. }
  17. pongGame.start(millis());
  18. }
  19.  
  20. void drawScreen(int* buffer) {
  21. for (int irow = 0; irow < nrow; irow++) {
  22. for (int icol = 0; icol < ncol; icol++) {
  23.  
  24. // mvprintw(irow, icol, buffer[irow * ncol + icol] == 0 ? "." : "O");
  25. }
  26. }
  27. refresh();
  28. }
  29.  
  30. void processInput(unsigned long tick, int bIndex) { //You will need to change this
  31. switch (bIndex) {
  32. case 0:
  33. pongGame.movePad(Player::PLAYER_ONE, PadDirection::UP);
  34. break;
  35. case 1:
  36. pongGame.movePad(Player::PLAYER_ONE, PadDirection::DOWN);
  37. break;
  38. case 4:
  39. pongGame.reset();
  40. pongGame.start(tick);
  41. break;
  42. case 2:
  43. pongGame.movePad(Player::PLAYER_TWO, PadDirection::UP);
  44. break;
  45. case 3:
  46. pongGame.movePad(Player::PLAYER_TWO, PadDirection::DOWN);
  47. break;
  48. }
  49. }
  50.  
  51. void loop() {
  52. const unsigned long tick = millis();
  53. pongGame.update(tick);
  54.  
  55. for (int i = 0; i < 5; i++) {
  56. int read_data = digitalRead(buttons[i]);
  57. if ((prev[i] != read_data) & (prev[i] == HIGH)) {
  58. processInput(tick, i);
  59. Serial.println(i);
  60. }
  61. prev[i] = read_data;
  62. }
  63.  
  64. if (pongGame.isDirty()) {
  65. pongGame.paint(buffer);
  66. drawScreen(buffer);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement