Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE Physac-MBED PinDetect SDFileSystem mbed-rtos mbed
Diff: hockey/hockey.cpp
- Revision:
- 16:6cf744b2623a
- Parent:
- 12:5d913b57da7c
- Child:
- 17:3517251daf96
diff -r 5d913b57da7c -r 6cf744b2623a hockey/hockey.cpp --- a/hockey/hockey.cpp Wed Nov 30 21:20:21 2022 +0000 +++ b/hockey/hockey.cpp Wed Nov 30 21:43:44 2022 +0000 @@ -281,12 +281,10 @@ runGameLogic(); } - float phys_time = timer.read() * 1000; // Render the game drawDynamicObjects(); - float render_time = timer.read()*1000 - phys_time; - + // Process input from the game blue.parseMessage(); if (blue.button[BUTTON_UP]) { @@ -313,8 +311,25 @@ SetPhysicsBodyRotation(paddle_a, paddle_a->orient + dt * input_sensitivity * 0.05); printf("CCW\r\n"); } - - float input_time = timer.read()*1000 - render_time - phys_time; + + // Player 2 Input + if (!(navSwitch & 0b00001)) { // Up + paddle_b->position.y -= dt * input_sensitivity; + } + if (!(navSwitch & 0b01000)) { // down + paddle_b->position.y += dt * input_sensitivity; + } + if (!(navSwitch & 0b00100)) { // left + paddle_b->position.x -= dt * input_sensitivity; + } + if (!(navSwitch & 0b10000)) { // right + paddle_b->position.x += dt * input_sensitivity; + } + if (!(navSwitch & 0b00010)) { // rotate + SetPhysicsBodyRotation(paddle_b, paddle_b->orient + 3.14159 / 4); + } + + Thread::yield(); } ClosePhysics(); // Unitialize physics