Game Development Community

iTGB/TGB Network game - basic things

by Vyacheslav Klymenko · in iTorque 2D · 01/09/2010 (3:48 pm) · 4 replies

I am working on a network game on iTGB. I used functions and methods from TGB's example.
Connection is ok between few players.

But what next?

for example I want to have a sprite for each player and all players must handle own sprites by keyboard (move up for example only like setlinearvelocity("0 -10")).

onClientConnected()
onServerCreated() ...

how it'd be better to organize in way to define who are owners of sprites, etc ?

#1
01/09/2010 (6:59 pm)
You don't appear to own any licenses to either of the engines. If you have a different licensed account then please post using that account.
#2
01/10/2010 (7:10 am)
ok, that's better account? : ) I am not often ask for help at GG - would you be so kind to give an answer for the question? I promise - I'll not ask anymore about iTGB.
#3
01/16/2010 (9:46 am)
ok, I got basic things. if anyone interested:
(just my first experience and thoughts)

1. Connection

For connections it'd be better to take a look into "checkers" demo and to use ready gui network menu. Then step-by-step you can take functions from it and put into own game.
most important are:
createServer(true);
.connect($ServerInfo::Address);

2. Network's structure

As I understand we have not real-time, but turn based network, so we have server and clients, which are connected to server. Server - it is "person", who has created the game, so when he is creating a game - he just making text entry on server like Master Server at GG. And clients see that (server's ip) and can connect.

3. Scripting

function onClientConnected(%client)
{
}

this command executing only on server. so from this point we can handle all data. we can make a variable like "$isFirstConnection" - and to see is it %client is some man, who joined to the game, or it is "we" like:

$isFirstConnection = true;
function onClientConnected(%client)
{
if ($isFirstConnection)
{
// ignore it, this is our connection
$isFirstConnection = false;
}
else
{
// now we have some another player, who joined the game
}
}

onClientConnected is also executing, when server starting the game, so we may ignore first client, because it is "we" and then make some list like

new SimSet (Clients) {};

and in this function add clients to this list.

if we want to send something from client to server we're using

commandToServer('NewFunction');

so we must have function like

Function serverCmdNewFunction()
{
}
to receive the data

and if we need to send something to client:
commandToClient(%client,'NewFunction2');

as well we need to have
function clientCmdNewFunction2()
{
}

so we can send data (parameters: text,integer/float etc) between players, but in common server must handle all, but anyway we can send data between clients without executing script function on server (but for that we need to have clients list at every client).

it is only some first thoughts, anyway I will try to answer if you have question.





#4
05/24/2010 (6:35 am)
oh, yes, sorry, I forgot about the train in the end of the tunnel instead light.