Author Topic: Multiplayer jumper with Flixel  (Read 7805 times)

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Multiplayer jumper with Flixel
« on: Thu, Jan 16, 2014 »
Hi everybody.

I want to do a multiplayer mode on my jumper (school game project) and I have no idea on how i can do that.

That anybody have an idea on how and where can I start?

Thanks <3
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #1 on: Thu, Jan 16, 2014 »
Are you talking about keyboard multiplayer or networked i.e. online multiplayer? I've recently made an online game for AIR (it's almost done, I'd say it's in an alpha state but it isn't terribly broken like most alphas).
https://github.com/Ohmnivore/HeadRush
I've had to conquer sockets on my own and I feel like I've gained a lot of experience on the subject, and I'm willing to help anyone so they don't need to go through hell to figure everything out.

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #2 on: Fri, Jan 17, 2014 »
Yes I talk about network multiplayer :)
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #3 on: Fri, Jan 17, 2014 »
So Ohmnivore, where can I start to create my multiplayer mode ?
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #4 on: Fri, Jan 17, 2014 »
Oh dear god, you're in for a trip then. Here's a starter (try and get through all the articles mentioned - they help)
http://ohmnivore.elementfx.com/247/good-multiplayer-networking-approaches/#.UtnTlhAo7b0

Then there's the multiplayer API. Sockets (this is sort of an abstract interface to send data) libraries on all languages have nearly the same API, because they provide the same functionality and are essentially wrappers around system stuff. I like to think of sockets as individual mailboxes. Your computer is a street, and has many mailboxes (thousands, actually). Your IP is the street's name, and the port is the mailbox's address.

One thing mentioned in the Gaffer on games posts is TCP vs UDP. They are both very popular protocols with a couple of differences. Both make sure that data sent is not corrupted. But that's where UDP stops. It's the only thing it does. It sends stuff out and doesn't care what happens next. TCP on the other hand ensures that data arrives reliably, and in-order. Because of this, TCP is more reliable than UDP - you'll never lose any data, but UDP is faster.

Note that the following can change between different protocols - like some things are different for TCP and UDP. I'll be mostly describing TCP.
From a programming perspective, to use a mailbox, you first need to specify which one you want to listen to. This is usually denoted by a function called bind(address -> ip, port -> which specific socket). In TCP, this is only necessary when you are running a server. In UDP this is always necessary if you want to receive messages.
Uhm wait I'll explain the client-server model before going on.

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #5 on: Fri, Jan 17, 2014 »
There's a couple of models for multiplayer networking. I mainly heard about peer-to-peer (cheating is a plague) and client-server. I personally prefer client-server, but then again it depends on how many people you want the game to support at a time.

There is only one server, and each player is a client.

Basically a client is like a puppet. It's the program that the player uses to play. It sends the player's input (ex: arrow keys, mouse position) to the server. The server runs an instance of the game, where each player is but an object in that instance. Depending on what the server just received from the client, the server updates its instance of the game (ex: set the player's velocity), which basically makes sure that nobody can cheat - the client can send nothing but control updates, and can't change anything in the server's game instance directly (other than the methods already available to him), ugh you know what i mean.

In turn, the server makes sure that all the clients have a representation of its game state. It will send position updates, for example, and the clients will display objects at these positions. That's why they're puppets - they merely obey the commands the server sends them.

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #6 on: Fri, Jan 17, 2014 »
From a client's perspective, you would then call connect(addr, port) to connect to the mailbox that the server hosts. This is a TCP-only thing. In UDP you will have to specify the addr and port everytime you send something (although AS3 has a solution for that). Once you have addresses and ports set up, you can send data and receive data. In AS3 this is done through events. Also other cool events for TCP are fired on connect from a client, on disconnect, and there's even more stuff.
I'd suggest looking into AS3's DatagramSocket, Socket, SocketServer, and maybe more classes.

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #7 on: Fri, Jan 17, 2014 »
Also, Flash only supports TCP sockets, UDP are only available for AIR. TCP might be enough for your needs. If not, then things get complicated. In my honest opinion, I'd switch to Haxe and use this:
https://code.google.com/p/hxreliableudp/
It's a wrapper around Enet which is a very well known C library developed for multiplayer game networking
Plus you get all the sweet goodies of Haxe and HaxeFlixel (which seems to have an active community - this forum is dead).

If I ever consider making another multiplayer game I will not hesitate even for a second to use Haxe.

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #8 on: Sat, Jan 18, 2014 »
Thank you so much, I will look this =)
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #9 on: Tue, Feb 11, 2014 »
Hi guys,

After a long period I re-work on my game project.

I've look Haxe and I've installed it.

Is this possible to move my flixel project into HaxeFlixel to use it with hxreliableudp ? (where did you download this by the way?)

I don't know how to use my flixel project with haxeflixel.
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

Gama11

  • Contributor
  • ****
  • Posts: 390
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #10 on: Tue, Feb 11, 2014 »
Quote
Is this possible to move my flixel project into HaxeFlixel to use it with hxreliableudp ? (where did you download this by the way?)

I don't know how to use my flixel project with haxeflixel.

You can definitely move your project to HaxeFlixel, but it has to be ported. HaxeFlixel doesn't have the same API as flixel as3 / 2.55, and of course, there are differences between AS3 and Haxe as well. The HaxeFlixel docs should help - specifically these two pages:


MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #11 on: Tue, Feb 11, 2014 »
Ok thank you :)
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #12 on: Wed, Feb 12, 2014 »
I've found SmartFoxServer to do a multiplayer mode.

Do you know this soft ? It is compatible with Flixel?

http://www.smartfoxserver.com/
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

Gama11

  • Contributor
  • ****
  • Posts: 390
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #13 on: Wed, Feb 12, 2014 »
If it supports Haxe, then almost certainly yes. If not, it's gonna be pretty tricky if possible at all.

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #14 on: Mon, Mar 10, 2014 »
Well if you plan to deploy to flash you can use smartfoxservers' swc

http://www.smartfoxserver.com/download/sfs2x#p=client

http://haxe.org/manual/swc

For cpp targets you can try using their c library, but I have no experience with that

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #15 on: Mon, Mar 10, 2014 »
By the way hxreliableudp hasn't been updated since 2008, sorry about that (don't use it).

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #16 on: Tue, May 6, 2014 »
Hi guys !

I came back to you because I have a little problem.

My multiplayer mode works but when I send data to my smart fox server my flixel client game has big lags.

For example, if i send data every 600 ms my game is ok but there is lags from the server (logical with 600 ms ping =D ), but if I send it every 150 ms my game (client) lag.

I think it's because the game take a pause every 150 ms to send data to the server. I think the solution is to add a thread in the server data send function.

There is my data send code ( send data to a java extension that send it to the server) :
Code: [Select]
if ( diff > 150)
{
lastupdate = now;
obj = new SFSObject();
obj.putUtfString("id", sfs.mySelf.name);
obj.putInt("x", player.x);
obj.putInt("y", player.y);
obj.putInt("vx", player.velocity.x);
obj.putInt("vy", player.velocity.y);
obj.putInt("facing", player.facing);
trace(obj.getDump());
sfs.send(new ExtensionRequest("data", obj));
}

What do you think about my problem ?
Do you have examples of thread with as3? Flixel ?

Koala.
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

Ohmnivore

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #17 on: Tue, May 6, 2014 »
BTW you should be fine sending your messages 20 times per second, so you can change it to 50ms. Honestly, I don't see how an action game could be playable at a send rate of 150ms. And yes, you should use threads, if I recall correctly there's a thing called worker threads in as3.

MrKoala

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
  • Koala Ninja 2.0
    • View Profile
    • Live Origin's
Re: Multiplayer jumper with Flixel
« Reply #18 on: Wed, May 7, 2014 »
OK, and yes there is workers in AS3.

I'll work this  :)

Thanks :)

PS : Somebody can explain me how it works (workers), with example if possible.
Thanks Flixel forum for all help !
I'm a french dev, this is a beta of my shcool projet : http://liveorigins.fr/FlixGame.swf

PRIZZA

  • Member
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: Multiplayer jumper with Flixel
« Reply #19 on: Wed, May 14, 2014 »
Do you have logic that moves the player smoothly to the next x/y coordinate that the game has received? Try to write some code that will move the character to the received x/y destination, and the game wont appear to lag anymore. I've developed a multiplayer action game that sends every 200 ms and there is very little to no lag with a decent connection. Even poor connections look decent.

 :) Check this out: http://www.spelagon.com/multiplayer-nutmeg-lab