Get your game working first, but design it so you can easily add multiplayer.
what I'm doing for Captain Failure is:
If you're playing locally, the client creates the server, keeps a reference to it, and calls a method to give the server input state. The client also has a Vector declared thet is set to reference the server's entity container for drawing.
If you're on a network, the client connects to the server, and sends input over the network. the networking code on the server calls the aforementioned input method. The client's entities array is updated over the network by spawn messages, position messages, etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| class client { vector entities; server serv;
init() {
if(singleplayer) {
serv=new server(); entities=serv.entities; } else { entities = new Vector();
} }
loop() {
if(singleplayer) { serv.giveinput(input state); } else {
}
}
class server { Vector entities;
init() { if(!local) {
} }
loop() {
if(!local) {
} } |