multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Diff: main.cpp
- Revision:
- 27:fcc5fee18a24
- Parent:
- 26:ebadab157abe
- Child:
- 28:a26a43cdaea8
diff -r ebadab157abe -r fcc5fee18a24 main.cpp --- a/main.cpp Mon Nov 16 04:27:47 2020 +0000 +++ b/main.cpp Mon Nov 23 01:19:17 2020 +0000 @@ -64,6 +64,7 @@ // change ISRs to game controls leftButton.attach(&pressLeftGame, IRQ_RISE, DEBOUNCE); + middleButton.reset(); rightButton.attach(&pressRightGame, IRQ_RISE, DEBOUNCE); while (!gs->done()) { @@ -83,12 +84,26 @@ int bytesRead = sock.receiveFrom(nist, readTo, sizeof(readTo)); readTo[bytesRead] = 0; if (bytesRead > 0) { + printf("data received: %s", readTo); parse(serverResponse, readTo); - gs->update(&serverResponse, gfx); + gs->updateAndRender(&serverResponse, gfx); } wait(.1); } - gfx->renderLaunchScreen(); + MbedJSONValue dcReq; + dcReq["hash"] = "jaredyeagersflipflop"; + dcReq["type"] = "disconnect"; + + string dcReqContent = dcReq.serialize(); + int len = dcReqContent.size(); + char *dcPayload = (char *)dcReqContent.c_str(); + + sock.sendTo(nist, dcPayload, len); + gfx->renderGameOver(gs); + leftButton.attach(&pressButtonMenu, IRQ_RISE, DEBOUNCE); + middleButton.attach(&pressButtonMenu, IRQ_RISE, DEBOUNCE); + rightButton.attach(&pressButtonMenu, IRQ_RISE, DEBOUNCE); + // reset the game menuPress = 0; }