Broadcast map changes

Post your help queries and engine programming questions here

Broadcast map changes

Postby Epsilon » Fri Oct 02, 2015 7:25 pm

Hello, Community!

I am new in Isogenic but I am good in Javascript though. I am developing a simple MMO game using rectangle map set. There are also some objects (Rocks) on the map. Rocks are moveable. Well, I guess I need to code Rocks as entities, which are syncronized by standard way. But main question is mainly about map itself. I want the map (it is actually big) to be changeable, it means for example one Rock can push the wall tile and wall tile become different or even become "empty".
What is the best way to syncronize tiles? I didn't find any syncronization methods in map2d object, I guess maps could not be synced by standard way.

First idea is to convert map tile to moveable entity, play an animation and then hard rewrite this tile on the all clients using some special procedure.

Could you tell me which way it better in Isogenic? Thanks.
ZX Spectrum fan and game developer in the past. Wanna be game developer in present again.
User avatar
Epsilon
 
Posts: 13
Joined: Sat Sep 26, 2015 9:40 pm
Location: Russian Federation

Re: Broadcast map changes

Postby rob » Fri Oct 02, 2015 8:29 pm

Hi, your approach to rewrite tile after event is the way forward. You just need to define a custom network event to tell client to change a tile.
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
User avatar
rob
Site Admin
 
Posts: 316
Joined: Tue Oct 22, 2013 5:08 pm

Re: Broadcast map changes

Postby Epsilon » Sat Oct 03, 2015 2:06 am

rob wrote:Hi, your approach to rewrite tile after event is the way forward. You just need to define a custom network event to tell client to change a tile.


Thank you, Rob. Please tell me in which Example can I see some relative piece of code? Or may you show it here please?
ZX Spectrum fan and game developer in the past. Wanna be game developer in present again.
User avatar
Epsilon
 
Posts: 13
Joined: Sat Sep 26, 2015 9:40 pm
Location: Russian Federation

Re: Broadcast map changes

Postby rob » Sat Oct 03, 2015 11:43 am

Hey, so any of the multiplayer examples will have the code you need but I'll explain how to use it here:

Here is part of an example Server.js:

Code: Select all
var Server = IgeClass.extend({
   classId: 'Server',
   Server: true,

   init: function (options) {
      var self = this;
      ige.timeScale(1);

      // Define an object to hold references to our player entities
      this.players = {};

      // Add the server-side game methods / event handlers
      this.implement(ServerNetworkEvents);

      // Add the networking component
      ige.addComponent(IgeNetIoComponent)
         // Start the network server
         .network.start(2000, function () {
            // Networking has started so start the game engine
            ige.start(function (success) {
               // Check if the engine started successfully
               if (success) {
                  // Create some network commands we will need
                  ige.network.define('tileChange');


You can see on the last line the command: ige.network.define('tileChange');

I've created that line as an example based on what you want to do. This defines a network command on the server that will allow the client to receive the tileChange command and act on it. Basically network commands are like events that you can listen to. When they are emitted on the server they propagate to clients and any client listening for that event will fire it's event listener with the data passed through from the server.

So let's create a listener on the client in Client.js:

Code: Select all
var Client = IgeClass.extend({
   classId: 'Client',

   init: function () {
      //ige.timeScale(0.1);
      ige.showStats(1);

      // Load our textures
      var self = this;

      // Enable networking
      ige.addComponent(IgeNetIoComponent);

      // Implement our game methods
      this.implement(ClientNetworkEvents);

      // Create the HTML canvas
      ige.createFrontBuffer(true);

      // Load the textures we want to use
      this.textures = {
         ship: new IgeTexture('./assets/PlayerTexture.js')
      };

      ige.on('texturesLoaded', function () {
         // Ask the engine to start
         ige.start(function (success) {
            // Check if the engine started successfully
            if (success) {
               // Start the networking (you can do this elsewhere if it
               // makes sense to connect to the server later on rather
               // than before the scene etc are created... maybe you want
               // a splash screen or a menu first? Then connect after you've
               // got a username or something?
               ige.network.start('http://localhost:2000', function () {
                  // Setup the network command listeners
                  ige.network.define('tileChange', function () { console.log(arguments); });


On that last line you can see we have asked the client's network system to also define the network command tileChange and this time we provide a listener method as well. This listener method will be called whenever the client receives the tileChange network command from the server and will be passed data that the server sent.

I've added console.log(arguments); to the method so that when the event occurs you will see the arguments passed to your listener in the console.

The final piece of the puzzle is to actually use the command on the server to send a message:

Code: Select all
ige.network.send('tileChange', {tileX: 1, tileY: 2, tileNewType: 'GRASS'});


I've created a contrived example there but you can see how you can send over data using the tileChange command.

The ige.network.send() method also accepts a third argument which allows you to pass a clientId or array of clientIds to send the message to. If you do not specify a clientId the message is sent to ALL connected clients.

I hope that has helped :)
CEO & Lead Developer
Irrelon Software Limited
http://www.isogenicengine.com
User avatar
rob
Site Admin
 
Posts: 316
Joined: Tue Oct 22, 2013 5:08 pm

Re: Broadcast map changes

Postby Epsilon » Sat Oct 03, 2015 3:11 pm

Hi Rob, thanks for so detailed answer. I've got everything now ! :)
ZX Spectrum fan and game developer in the past. Wanna be game developer in present again.
User avatar
Epsilon
 
Posts: 13
Joined: Sat Sep 26, 2015 9:40 pm
Location: Russian Federation


Return to Help & Questions

Who is online

Users browsing this forum: Google [Bot] and 1 guest
cron