EPISODE 25:

Do you love me?







2D "splatoon" game

There was actually two parts in this project. The first part was to only complete the teacher's code. We had to :

  • link dynamically each player's library to its associated player
  • code the player's action
  • handle the end of the game

This part was simple and could easily be done in 2-3 hours. Coding all this first part without any error would grant us a 15/20. But what about the 5 missing points ? What about the second part ?

Well to get the 5 last points we were asked to make the game better. It means "do whatever you want to do as long as you add cool things". He gave us examples such as making a little menu, display the score in real-time, things like this. But I thought "That's a shame the players move by themselves according to their library. I want to make them move by myself". So that's what I did. I used my CS bachelor knowledge in system programming to code a server and client process, and I added that to my code.

So it works like that : We have at least two process running at the same time. There is the game process, which handle the SDL rendering. At the beginning of the game process, I fork it to start the server. We then have a server process that'll get the commands sent by clients, and a game process that'll make the players move according to the commands transmitted by the server. The communication between the server and clients is a socket based communication. Between the server and the game process, it's a shared array. The idea is that whenever a client sends a command, the server writes it in the shared array at the index corresponding to the order of connection of the client (if it's the first client to connect, its commands will be written at index 0 and so on). Then the game process loops and read the array every 100ms and make the player move.

This project was quite fun because we were free to do what we wanted to do, and I could remember a lot of C functions and concepts I haven't practiced for almost a year, so it was a nice experience.