⬆️ ⬇️

Arkanoid with a joystick on the phone

Recently, my colleagues reminded me of the wonderful game MortalKombat, in which, well, it is simply not possible to play without joysticks, and if there is perhaps no pleasure.



And I remembered the technology of controlling any screens from a mobile phone, which I described in a previous article . The goal in that article was achieved but the practical application of zero.



And without hesitation, a game was created that, according to my feelings, can be played if there are no wild brakes on your network and proxy for knocking out web sockets.

')





The game itself now lies on the main library page .



Actually all the code as always lies on the github .



All the main control code (of which, as you understand, not a lot) is concentrated in the js file example / js / main.js , everything that does not belong to the control, but refers only to the game lies in the file example / js / game.js



In short, using the remoteall library API, we simply take the signals from the joystick and transfer them to the game as a change in the status of global variables (the game is taken on the Internet, and the link is lost, so I can’t answer for the code and logic of the game)

The whole code for setting this interaction fits into 30 lines.
ra.on('recive_code', function (data, session_id) { if( (data.button_code=='LENTER' || data.button_code=='RENTER') && data.event_name =='button_down'){ //reset game restartGame() return } switch (data.event_name) { case 'button_down': switch (data.button_code) { case 'LEFT': // 'Left' key bLeftBut = true; break; case 'RIGHT': // 'Right' key bRightBut = true; break; } break; case 'button_up': switch (data.button_code) { case 'LEFT': // 'Left' key bLeftBut = false; break; case 'RIGHT': // 'Right' key bRightBut = false; break; } break; } }) 




With this game I would like to demonstrate that games with instant response can work in open networks on the principles of this technology. Further, with the presence of enthusiasm and enthusiasts, I would like to sbatsat more interesting thing (for example, the same tanchiki)



And immediately there are questions for the habra people:







Thank you all for a good weekend.



UDP:

The server should deal with a bunch of requests and web sockets, but still the likelihood that node.js won't handle about 5% :)

Source: https://habr.com/ru/post/190348/



All Articles