Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "PongGame.h"
- const int nrow = 8;
- const int ncol = 8;
- PongGame pongGame(nrow, ncol);
- int* buffer = new int[nrow * ncol];
- const int buttons[] = {9, 8, 13, 12, 7};
- int prev[] = {LOW, LOW, LOW, LOW, LOW};
- void setup() {
- Serial.begin(9600);
- for (int i = 0; i < 5; i++) {
- pinMode(buttons[i], INPUT_PULLUP);
- }
- pongGame.start(millis());
- }
- void drawScreen(int* buffer) {
- for (int irow = 0; irow < nrow; irow++) {
- for (int icol = 0; icol < ncol; icol++) {
- // mvprintw(irow, icol, buffer[irow * ncol + icol] == 0 ? "." : "O");
- }
- }
- refresh();
- }
- void processInput(unsigned long tick, int bIndex) { //You will need to change this
- switch (bIndex) {
- case 0:
- pongGame.movePad(Player::PLAYER_ONE, PadDirection::UP);
- break;
- case 1:
- pongGame.movePad(Player::PLAYER_ONE, PadDirection::DOWN);
- break;
- case 4:
- pongGame.reset();
- pongGame.start(tick);
- break;
- case 2:
- pongGame.movePad(Player::PLAYER_TWO, PadDirection::UP);
- break;
- case 3:
- pongGame.movePad(Player::PLAYER_TWO, PadDirection::DOWN);
- break;
- }
- }
- void loop() {
- const unsigned long tick = millis();
- pongGame.update(tick);
- for (int i = 0; i < 5; i++) {
- int read_data = digitalRead(buttons[i]);
- if ((prev[i] != read_data) & (prev[i] == HIGH)) {
- processInput(tick, i);
- Serial.println(i);
- }
- prev[i] = read_data;
- }
- if (pongGame.isDirty()) {
- pongGame.paint(buffer);
- drawScreen(buffer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement