Want to Play a Game of Snake?! Cause it Can!

I can talk to the cube over UDP!


UDP is a communication standard to send data over the internet, the other main one being TCP. TCP is a reliable method of sending data, while UDP is not natively. TCP is like sending a parcel in the mail, where you get a tracking number, and know when it arrives with confirmation. UDP is like the letter mail, where after it is sent, you do not know if or when it gets there, and there is no 100% guarantee of delivery. The standard webpage is delivered over TCP as it needs to get there, while if you play any form of online game, most of its data is sent over UDP as it is faster. The main good thing for UDP is its speed and guarantee that if the letter is delivered, the entire letter made it. Bluetooth does not have this guarantee which was a major factor in this rebuild as I was having to pack in large amounts of error correction into an already overtaxed system. 


Talking to my cube over UDP allows for so many possibilities as I can control the colours in standard RGB methods and send the data in binary to it. For example to set the colour, I send it "data:" followed by the value of each light in binary. Turning the first LED yellow for example is "data:FFFF00". With this layout, I only use 197 bytes out of 255 available inside a standard UDP packet, which makes it very quick to update. 


I have also set up the cube to have its mode of operation changed the same way, as well as set the text for the ticker tape mode, all working without needing to change the actual program running on the arduino. 


Due to this being UDP, it means that any computer thjat has the ability to send these packets over the internet are able to change the behaviour of the cube, making the LEDCube achieve its final purpose of being a screen for a game. As a test, I coded a simple game of Snake, that uses the 3d nature of the cube as a part of the gameplay itself. I built the game itself inside C++ using SFML, which is a 2d graphics and game library. I set up the C++ code so that whenever the gamestate changes, the game will send over UDP the frame to be drawn, which the LEDCube will hold until the next frame. This results in a full game of snake as can be seen in the video below, and a LEDCube library I can use to add the cube to any future project I want. 


Comments

Log in to add a comment.