single + multiplayer game

Started by
6 comments, last by ErUs 18 years, 2 months ago
hello, I am about to start work on a single and multiplayer game and i would like some advice on how to work this out. I figured i would need a like 2 seperate base classes - client and server. So the client would start and if needed, create an instance of server? is this the propper way todo it? and any other advice you can give?
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )
Advertisement
I just got the network portion of my game finished. I used RakNet, but the concepts still apply. Here's what I did:

First, when I was designing my game I decided that the actual game would be client only. This made it a bit easier to program in my opinion.

I wrote a seperate app in a C++ console that handled what the clients sent to it and redistributes that information across the network.

So basically what happens is this:

1) I start the server up, It initializes all it's info.
2) Start the game, enter a server ip, and connect.

(this is where it kinda splits up a little)

3) Client sends updates in position along with other things to server.
4) Server receives this packet, and redistributes across the network.

(to eliminate lag)

5) Client receives enemies first packet and sets position, from then on it only updates velocity (not position). Then every 333ms, I update the enemies to their "true" positions.

Honestly though, in the end it doesn't matter how you do it. This is just how I did mine. Technically, any method will work as long as it is valid. It's just that some methods are more efficient than others.

The thing that helped me the most was to shut your computer off. Really. Take out your pencil and paper, and actually think through how your clients and server are going to talk to each other. Make yourself a nice pretty flowchart and then start coding. Sounds silly, but it works.

Coming to the table with a solid plan is necessary. Well, I think I've trekked far enough off topic so...

I hope this helped,

toXic~
toXic1337
thanks toxic,

i am planning to use raknet, i find it good and easy to use.

i would like to know a bit more about how a client can play single player without having to start a seprate server program and connecting to it. what methods are used for this?
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )
just put a wrapper round all your input functions, so there's like an emulated network server built into 1 player mode. the kind of structure you'd use for recording and playing back demos, redefining inputs etc
@ErUs:

Could you elaborate a little more on what type of game you're making. It's hard for me to understand what you mean by single player when all I can think of in reference to multiplayer is a "Counter-Strike" type game.

Perhaps you mean how you would split up like a single player campaign with a story and the multiplayer pvp aspects? If that's the case, you're going to end up with two very different games wrapped into one.

They of course would pull on the same core data such as maps, character models, etc.

Elaborate a little bit more.

toXic
toXic1337
I'm thinking something along the lines of Quake II, where a 'single player' game creates an instance of the server, with a different ruleset, and connects to it in the usual way. That would contain all the code within the server section and its various rulesets, with the client code being relatively simple and just handling UI and display.

Without knowing more about the game you're planning, though, I can't be more specific.
I 'think' what he is trying to ask, is how would he structure his program so that it does what is needed depending on single/multiplayer modes. So that if the player chooses to play campaign in single player, how would he not have to interact with a server app. Then if they chose multiplayer, then it would start a server class/behaviour that the messages all get routed to in order to update everyone's game. So basically I am guessing he needs help on how to avoid all the networking code if its not needed in single player.

Thats what I understood anyways.
yes correct :D
-www.freewebs.com/tm1rbrt -> check out my gameboy emulator ( worklog updated regularly )

This topic is closed to new replies.

Advertisement