Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Some guidance with a multiplayer game please  (Read 2442 times)
0 Members and 1 Guest are viewing this topic.
Offline Trosters

Junior Devvie


Projects: 1



« Posted 2011-04-06 10:52:26 »

So I've been thinking about making a small multiplayer 'game' where you, for a start atleast, just explore the world and chat with people in the same zone as you are. The game would be kind of like pokemon when it comes to layout etc, but it'd be multiplayer.

But because I have very limited experience with network programming (I've only ever made a TCP chat and a small game where you throw knives at eachothers  and it didn't even seem like the clients were synched as I wanted them to be) I wanted to ask you:
# what parts of the game would you put on the server and what parts on the client?

I've built a singleplayer game which pretty much works the way I want it to - you can move around a world, enter houses and other new zones and when you do the new zone is loaded and replaces your old BUT:
I make the 'camera' follow my character using the following method:
When you are about to move outside the screen (well the center of it) - I instead move every other object in the oposite direction that you try and move - so it looks like the character is moving but instead it is actually everything else moving. This does not feel like a very good solution to me, and especially not if I want to turn this into a multiplayer game. What other solutions are there for this? How would you solve this?

Any comments and help you might have with a project like this are greatly appreciated!
Offline zlandorf

Junior Devvie


Medals: 1
Projects: 1



« Reply #1 - Posted 2011-04-06 11:05:49 »

# what parts of the game would you put on the server and what parts on the client?

I've built a single player game which pretty much works the way I want it to - you can move around a world, enter houses and other new zones and when you do the new zone is loaded and replaces your old BUT:
I make the 'camera' follow my character using the following method:
When you are about to move outside the screen (well the center of it) - I instead move every other object in the opposite direction that you try and move - so it looks like the character is moving but instead it is actually everything else moving. This does not feel like a very good solution to me, and especially not if I want to turn this into a multi player game. What other solutions are there for this? How would you solve this?

I'm a noob too, but I'll try and give a bit of an answer.

To know what the server must do and what the client must do depends on how secure you want your game to be. If you let the client compute a lot of things and make the server become just a multiplexer, then somebody can hack your client and send false information and the server will probably not notice.
So, generally, the server has to at least double check information sent by the clients. If you're going for something simple, the clients can just send inputs to the server which will then process them and make a character move or whatever.

For your problem : make your character move only. If you want him in the middle of the screen, just make the client move his view port accordingly to his character.

Offline Trosters

Junior Devvie


Projects: 1



« Reply #2 - Posted 2011-04-06 11:08:35 »

I understand that I want to make only my character move - my problem is that I have no idea how to properly do this :/

As for the other part, yes - I supose I would want to make most of the stuff server-side but I do not know how to connect the client and server with minimum lag and without having the server do alot of un-necesarry work. The knife game I did my friend decompiled and rebuilt and kept owning me with extra big extra high damage extra fast knives:(
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zlandorf

Junior Devvie


Medals: 1
Projects: 1



« Reply #3 - Posted 2011-04-06 11:27:17 »

The way I'd do it is to use an inverse translation before drawing but it's probably not the right thing to do. Sorry to not be able to help you more.
Offline Mike

« JGO Spiffy Duke »


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #4 - Posted 2011-04-06 12:14:17 »

The knife game I did my friend decompiled and rebuilt and kept owning me with extra big extra high damage extra fast knives:(

...which is why the server never should trust what the client says Smiley

Regarding how you draw and move the background, that's perfectly fine for a multiplayer game, all you send to the server is your position anyway, not where the buildings are.

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2011-04-07 02:29:04 »

What I do is have all the game logic in the server and it just sends the position of all moving objects. Cheesy

Offline Mike

« JGO Spiffy Duke »


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #6 - Posted 2011-04-07 06:12:27 »

What I do is have all the game logic in the server and it just sends the position of all moving objects. Cheesy

Which is another way to do it if you aren't planning to have a lot of users and be safe against a high latency.

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline Trosters

Junior Devvie


Projects: 1



« Reply #7 - Posted 2011-04-07 08:42:56 »

the problem I get if I just send positions to the server every time I  move is:

Because of the camera thing I mentioned in my first post, I move each object one step in the opposite direction of that I am moving - I would also be moving other characters with this now would I not? (I know I could just ignore "instanceof Character" when I move my objects but then the character might end up getting stuck on in a wall on my screen). So basically my idea is to have all the logic on the server and all the actual work run there (it'd be a small game, perhaps at maximum 10 players, would this be ok?) but how would I then fix my camera problem?

I started to work with slick2d yesterday and I find it very interesting - the 'tile maps' might be something for me? Does it have some inbuilt feature for stuff like this?

I feel really stupid not being able to figure out how to solve this myself but I've just tried and failed in so many ways I can't remember which ways there's still to try:(
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2011-04-07 08:44:15 »

What exactly are you doing with a Camera?

Offline Trosters

Junior Devvie


Projects: 1



« Reply #9 - Posted 2011-04-07 16:30:48 »

wow I thought I made that clear, sorry! :/
With camera I mean the frame that follows my character. Say if my character is positioned in the middle of a 800x600 frame then I consider that frame to be my camera. If I move 100pixels to the right, I want the camera to follow and update with my new surroundings.

I hope you understand now.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2011-04-07 19:19:09 »

Ah so instead of manually setting the x and y of each object on the screen, you have a Camera class that contains the offset from the origin?

Offline Gudradain
« Reply #11 - Posted 2011-04-07 20:34:08 »

Basically you just have a scrolling map? I don't see why this would affect anything for client/server work. If it does, there must be something really wrong in your design.

Ok now, how to make a good client/server where the server is the decision maker (validate every move from the client) and the client doesn't have any lag? Here is a solution :

You will need to run a simulation of your code on the clients and on the server. Yeah you can't save this, the server need to run the exact same logic game update code as your client.
On your client you need to have 2 world. One world that is up to date (current time) and another one that lag behind. The world that lag behind is for comparison. You will compare this world with the world that the server will send to you from time to time to see if your client is still sync with the world of the server. If it's not, you will take the world from the server, send it to the client, update it to the current time and continue your simulation. To do so, you need to keep track of every move that you did and every move that the server told you the other players did.

The world that will be display on the client screen is the up to date world. In this world, when the player make a move (like move forward) the client automatically move forward so there is no lag. Then this event reach the server and the process of validation (as mentioned above start). If everything is perfect, there will be no modification to the client if there is a problem the simulation will be rerun from the point were the problem occurs. But most of the time, there shouldn't be a problem.

That way you got a client with no lag and it will be synchronize with the server.

Ok, that's simple to explain like that but it requires a couple of work and things need be done right.

One of the thing that you will see is that the server doesn't require to have the drawing code so you can remove it to reduce the overhead of running the same simulation on the server.

Another very important thing is that you need to have a fix deltaTime for your update method. If you have a random deltaTime, you can't synchronize the client and the server with this method. So get a good gameloop. With your fix deltaTime you can assigned each input from the player to a specific update. So if on the client side the player press to move forward on update 213, on the server this client need to be move forward on update 213. You always need to update on the same update number. That bring another problem, the update number on the client and the server need to be roughly the same hence the need of an synchronized clock between the client and the server.

So yeah it's a lot of work. If you don't need to have perfect simulation on the client then just make the server decide everything and send message to the client for when to move or do a specific action. The simulation won't be perfect and you will feel the lag a bit but it's easier.
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #12 - Posted 2011-04-07 21:52:09 »

@Gudradain
Yes! I saw that design somewhere else on this forum but it was too confusing to understand Tongue
However, I think his problem here is when sending the data and how to reflect the scrolling of his player vs the surrounding the world and other players.

@Trosters
The server should have nothing to do with camera. All you server should do is hold the world and periodically give the clients all the positions. Your client should just use that data to recreate the world and then show a piece of it (the camera) on the screen.

Offline Trosters

Junior Devvie


Projects: 1



« Reply #13 - Posted 2011-04-08 07:44:10 »

@Gudradain
Thank you very much for your answer. Indeed I have understood that "basically I should just have a scrolling map". But the problem is, still, that I do not know how to implement this in a good way:/
Offline Gudradain
« Reply #14 - Posted 2011-04-09 05:20:25 »

Indeed I have understood that "basically I should just have a scrolling map". But the problem is, still, that I do not know how to implement this in a good way:/

Do you use the translate(x, y) function? That pretty much solved it.
Offline Trosters

Junior Devvie


Projects: 1



« Reply #15 - Posted 2011-04-09 07:05:57 »

I think I managed to solve this, I can't believe I did not realize I could draw stuff on a certain spot even without changing their actual positions.. Works now anyway! Thanks!:)
Offline ra4king

JGO Kernel


Medals: 355
Projects: 3
Exp: 5 years


I'm the King!


« Reply #16 - Posted 2011-04-09 07:16:09 »

Haha yes that's what we've been trying to tell you Tongue

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (65 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (28 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!