Here is the list of assumptions I'm having.
- That sending "Data" across the interwebs is not that hard. In my dream world right now its a matter of telling the client which port and IP it should poke with a stick and telling the server which port it should be guarding for pokes on.
- That I need to follow a pattern on the server side. (This will be pointed out further later on)
- That the majority of the data packages I send will actually turn up. (So not taking into account data loss)
Now onto my logic! So for this made up game the game itself is going to be simple. You have a 10 x 10 tiles map in all green, each tile is 64x64 pixels. On this map of grassyness there will be one stick man. all we can see of this man is is the round black head which fits inside one single tile. All you can do in this game is press W,A,S,D to move one tile in whatever direction those represent. So basically position is moved by 64 pixels in somewhat direction.
Now this is going to be the normal type of game (Please note I've only made games in C# before so this might be colored by that) So we'll have an Update part in our loop and a Draw part. Update happens before the Draw.
So, we'll have 3 variables that we actually care about. That's the PositionX, PositionY and PlayerID Out of all these 3 only the PlayerID is something we initiate on the client side. It's going to be the integer value 1.
So, (This is going to partly be experience from PHP + mySQL) I'm assuming that I'm making a variable at the start with something like Ipadr and Port which are a double and integer variables storing the information on where to connect.
So during game loading the client does something like this
- Lets say we have a function in whichever network library that are available that is something like "netDatasend(data1, data2, data3, data4)" where you can send data.
- We're going to send something like netDatasend(PlayerID)
- So what I'm thinking is that even though you can send whatever you want to the server it has to know what the fudge to do with what it gets. So we have some kind of constructor or the C++ equivalent of that. So somehow on the server side we've made it so that if it only gets a single integer value sent to it that its a PlayerID (At this point i'm not really sure how it would be in C++ but the server should check if there is any object of the "Players" class. If it doesn't find any Object with that name then it creates a new one. With the PlayerID which would be 1. So now on the server there is an Object or whatever its called in C++ by the name of 1 which holds two Variables PositionX and PositionY who hold a default position that would be something like upper left corner or whatever.
- The client would now in the update part of the game ask the server for those position variables - After which the player would be drawn on the map.
- At some point the player decides to press a button for the stick man to move to the right. Now at the update logic the game still asks the server for the position of the player, then he subtracts or adds the 64 needed to move one to the right (And all the other stuff like changing the sprite of the player to make it look like its moving happens here as well)
- At the end of the update the client sends another netDatasend(PlayerID, PositionX, PositionY) which the server is instructed that when it gets an integer value followed by two double it should use the first integer to find the object in this case PlayerID == 1 and use the following two numbers to set the PositionX and PositionY of the object.
- And so it goes.
This is a rough sketch, I can imagine there is tons of things I haven't considered which is why I'm posting this here.
Still there are a few things I want to mention
- Yes, I realise that it would be smart to make some kind of system that checks the PositionX and PositionY against the PositionX and PositionY of the prev update to check if there has been any movement, and only incase of movement would you actually bother requesting or sending the positions to the server.
- Might also be some advantage to calculate the position's server side. So what you send is instead what key has been pressed and then the server does the calculation.
- Now to make this a multiplayer game you could add it so that at the end of update the client sends a request that makes the server respond with the Positions of all active players and draw them in the Draw. Then add some kind of collision detection on the server and you have some crappy game.
Any and all input would be love! I will also answer any question you might have.

New Topic/Question
Reply




MultiQuote




|