Tuesday, March 27, 2012

BrowserQuest – a massively multiplayer HTML5 (WebSocket + Canvas) game experiment

It’s time for some gaming action with a new HTML5 game demo: BrowserQuest, a massively multiplayer adventure game created by Little Workshop (@glecollinet & @whatthefranck) and Mozilla.

Play the game: browserquest.mozilla.org
BrowserQuest

BrowserQuest is a tribute to classic video-games with a multiplayer twist. You play as a young warrior driven by the thrill of adventure. No princess to save here, just a dangerous world filled with treasures to discover. And it’s all done in glorious HTML5 and JavaScript.

Even better, it’s open-source so be sure to check out the source code on GitHub!

Watch a screencast:

A multiplayer experience

BrowserQuest screenshot

BrowserQuest can be played by thousands of simultaneous players, distributed across different instances of the in-game world. Click on the population counter at any time to know exactly how many total players are currently online.

Players can see and interact with each other by using an in-game chat system. They can also team up and fight enemies together.

BrowserQuest is a game of exploration: the more dangerous the places you go, the better the rewards.

Powered by WebSockets

WebSockets are a new technology enabling bi-directional communication between a browser and a server on the web.

BrowserQuest is a demo of how this technology can be used today to create a real-time multiplayer game in a single webpage. When you start to play, your browser opens up a WebSocket connection to one of several load-balanced game servers. Each server hosts multiple world instances and handles the player synchronization and game logic within all instances. Because the server code is running on Node.js, both the server and client codebases share a small portion of the same JavaScript source code.

Server code is available on Github.

BrowserQuest screenshot

Built on the Web platform

BrowserQuest makes extensive use of different web technologies, such as:

  • HTML5 Canvas, which powers the 2D tile-based graphics engine.
  • Web workers, allowing to initialize the large world map without slowing down the homepage UI.
  • localStorage, in which the progress of your character is continually saved.
  • CSS3 Media Queries, so that the game can resize itself and adapt to many devices.
  • HTML5 audio, so you can hear that rat or skeleton die!

Available everywhere

Since BrowserQuest is written in HTML5/JavaScript, it is available across a lot of different browsers and platforms. The game can be played in Firefox, Chrome and Safari. With WebSockets enabled, it’s also playable in Opera. Moreover, it’s compatible with iOS devices, as well as tablets and phones running Firefox for Android.

BrowserQuest screenshot

The mobile versions are more experimental than the desktop experience, which has richer features and performance, but it’s an early glimpse of what kind of games will be coming to the mobile Web in the future. Give it a try with your favorite mobile device!

Join the adventure

Want to be part of BrowserQuest? Create your own character and venture into the world. Fight enemies by yourself or with friends to get your hands on new equipment and items. You might even stumble upon a couple of surprises along the way…

Monday, March 26, 2012

15 Best HTML5 Game Engines


15 Best HTML5 Game Engines

HTML which stands for Hypertext mark-up language is supposed to be the main language for web pages. Hence the purpose of a web browser is to read the HTML documents and then compose them into either audible or visible websites. This technology also used to developing games, there are lots of HTML5 game engines by using developers can build different kind of attractive and advanced games for game lovers.

HTML5 is a language that used to create web pages, its fifth revision of HTML, a core technology of internet and basic language of designing. This advanced technology has some new features and tags that presents website designs with special effects and awesome layouts. HTML5 adds many new syntactical features.

These include the

and elements, as well as the integration of SVG(Scalable Vector Graphics) content. I have been searching the best game engines for developers and finally i got the best HTML5 game engines that provides the platform where developers can create games according to requirement.

This list introduced some best CSS, javascript and HTML5 game engines. Visit this list and choose the best one for your game development. Also share your thought in our comment section below.

1) HTML5 Game Engine

Construct 2 is a leading high quality HTML5 game engine. Tens of thousands of HTML5 game developers are choosing Construct 2 to make HTML5 games.

2) Clanfx

clanfx is a 2D, tile-based Javascript game engine developed using Javascript and CSS. It currently works in Firefox, Epiphany and Opera browsers. Features include many animated sprites, spell effects, buildings, tiles/textures and basic game AI.

3) Crafty js

4) CSS Game Engine

This is a free game engine developed for programming browser based games. It uses the Javascript language and CSS (Cascading Style Sheets) to dress up the page. They run pretty reliably together. Use this engine to create your own game.

5) Effect Games

Effect Games provides a suite of developer tools for creating and publishing web-based video games. The software is free, and includes an asset manager, level editor, sprite manager, environment editor, and publishing tools.

6) Entity js

Entity is an awsome all new javascript game engine. It focuses on flexibility, reusability and robustness. To make this happen Entity utilizies the, entity-component design where all logic is implemented in components and entities are created from adding or removing components.

7) Flash js

FlashJS was born at the crossroad of HTML / CSS and beautiful Flash objective model that is known by many interactive developers and fits great for game development. This library allows to develop HTML5 games and applications in the way that is similar to ordinary AS3 development.

8 ) Game Query js

gameQuery is a jQuery plug-in to help make javascript game development easier by adding some simple game-related classes. It’s still in an early stage of development and may change a lot in future versions.

9) Gamma js

Gamma is a new Javascript library which can be used to create 2.5D platform games for a web browser using the power of HTML, JavaScript, CSS and WebGL.

10) Geom

Geom is a JavaScript Game Engine that allows you to develop HTML5 Games in no time. Games created with Geom require no browser plugins or any software installations and work with old browsers that support only the Javascript.

11) Impact js

Impact is a JavaScript Game Engine that allows you to develop stunning HTML5 Games for desktop and mobile browsers.

12) Isogenic Engine

The Isogenic Engine is a modern web-based game engine that allows you to rapidly develop your next single or multiplayer game for the web. Isogenic does not require any browser plugins which means players can run your game without Adobe Flash or Microsoft Silverlight, straight from their web browser.

13) Jaws js

Jaws is a 2D game lib powered by HTML5. It started out only doing canvas but is now also supporting ordinary DOM based sprites through the same API.

14) GMP

GMP is great for making sprite-based, 2-D games, and it can easily power most retro-style arcade game designs. It is also well suited to making puzzles such as sudoku or gogopop.

15) Ingenio JS

ingenioJS is a JavaScript / HTML5 game engine. Its structure allows independent rendering methods, such as WebGL, Canvas or DOM Elements.

Friday, March 16, 2012

Impact engine / Socket.io + Node.js

Using the impact engine to build a node.js/socket.io game:

Part 1: http://www.nodejs-news.com/nodejs-tech/Building-Multiplayer-Game-HTML5-Node-Socketio/

Part 2: http://www.nodejs-news.com/nodejs-tech/Nodejs-Socketio-Building-HTML5-game/

Videos 1 to 4 are mostly about the Impact game engine, 5+ are more about socket.io/node.js realtime client/server communication

Video 1:




Video 2:



Video 3:



Video 4:




Video 5: Less Impact, more Socket.io



Video 6:



Source Code:
http://www.mediafire.com/?tkb6b9k6185n7lh

Monday, January 9, 2012

Nowjs Multiplayer Map

A wonderful example now on http://nowjs.com/examples/map it is slightly wonky on firefox 11, but the core concept is there:

A multiplayer map with individual controllable points, the basis for a multiplayer game.

This is a simple and elegant breakthrough.  We can now couple this with any scenegraph and we're almost golden in terms of an onscreen sprite tied to an individual with the ability to move it by keyboard.  Wonderful.

The example is at the link above, code below.

The big key is in the server side code:
 
actors[this.user.clientId]

We have an array of actors with the clientId as the key.  So simple and so powerful.

Client Side


var context;
var viewport = {
  width: 500,
  height: 400,
  x: 0,
  y: 0,
}

$(document).ready(function() {
  context = $('#map')[0].getContext('2d');
  $('#map').keydown(function(e) {
    e.preventDefault();
    switch(e.which) {
      //left
      case 37:
        viewport.x -= 5;
        now.updateActor(viewport.x, viewport.y);
        break;
      //right
      case 39:
        viewport.x += 5;
        now.updateActor(viewport.x, viewport.y);
        break;
      //up
      case 38:
        viewport.y -= 5;
        now.updateActor(viewport.x, viewport.y);
        break;
      //down
      case 40:
        viewport.y += 5;
        now.updateActor(viewport.x, viewport.y);
        break;  
    }
  });
  now.ready(function() {
    now.updateActor(viewport.x, viewport.y);
  });
});

now.drawActors = function(actors) {  
  context.clearRect(0, 0, 500, 400);
  context.beginPath();

  for(var i in actors) {
    if(i == now.core.clientId) {
      context.fillStyle = 'red';
      context.fillRect(viewport.width / 2 + actors[i].x - viewport.x, viewport.height / 2 + actors[i].y - viewport.y, 5, 5);
      for (var x = -actors[i].x % 40; x < 500; x += 40) {
        context.moveTo(x, 0);
        context.lineTo(x, 400);
      }
      for (var y = -actors[i].y % 40; y < 400; y += 40) {
        context.moveTo(0, y);
        context.lineTo(500, y);
      }
      context.strokeStyle = "#eee";
      context.stroke();   
    } else {
      context.fillStyle = 'black';
      context.fillRect(viewport.width / 2 + actors[i].x - viewport.x, viewport.height / 2 + actors[i].y - viewport.y, 5, 5);
    }
  }
} 
 
 

Server Side


var actors = [];
nowjs.on('connect', function() {
  actors[this.user.clientId] = {x: 0, y: 0};
});

nowjs.on('disconnect', function() {
  for(var i in actors) {
    if(i == this.user.clientId) {
      delete actors[i];
      break;
    }
  }
});

everyone.now.updateActor = function(x, y) {
  actors[this.user.clientId].x = x;
  actors[this.user.clientId].y = y;
  var toUpdate = {};
  for(var i in actors) {
    if(Math.abs(x - actors[i].x) < 310 && Math.abs(y - actors[i].y) < 210) {
        toUpdate[i] = {x: actors[i].x, y: actors[i].y};
    }
  }
  for(var i in toUpdate) {
    nowjs.getClient(i, function(err) {
      this.now.drawActors(toUpdate);
    });
  }
}



-----------------------------------


That is all well and good, but how do we jump into making this work?
Ok, in your now/examples/ folder create another folder called "map" or something like that.
Create one file called:
mp_server.js
and one called:
mp.html

Open the mp_server.js and paste in:

var fs = require('fs');
var server = require('http').createServer(function(req, response){
  fs.readFile(__dirname+'/mp.html', function(err, data){
    response.writeHead(200, {'Content-Type':'text/html'});
    response.write(data); 
    response.end();
  });
});
server.listen(8080);


var nowjs = require("now");
var everyone = nowjs.initialize(server);


var actors = [];
nowjs.on('connect', function() {
  actors[this.user.clientId] = {x: 0, y: 0};
  console.log("nowjs.on Connect");
});

nowjs.on('disconnect', function() {
  for(var i in actors) {
    if(i == this.user.clientId) {
      delete actors[i];
console.log("nowjs.on disconnect: " + i);
      break;
    }
  }
});

everyone.now.updateActor = function(x, y) {
  actors[this.user.clientId].x = x;
  actors[this.user.clientId].y = y;
  var toUpdate = {};
  for(var i in actors) {
    if(Math.abs(x - actors[i].x) < 310 && Math.abs(y - actors[i].y) < 210) {
        toUpdate[i] = {x: actors[i].x, y: actors[i].y};
    }
  }
  for(var i in toUpdate) {
    nowjs.getClient(i, function(err) {
      this.now.drawActors(toUpdate);
    });
  }
}




Save and close, now open the mp.html and paste in:


<!DOCTYPE html>
<html lang="en">
<head>
<title>nowjs test</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>




<script src="/nowjs/now.js"></script>


<script>
var context;
var viewport = {
  width: 500,
  height: 400,
  x: 0,
  y: 0,
}

$(document).ready(function() {
  context = $('#map')[0].getContext('2d');
  $('#map').keydown(function(e) {
    e.preventDefault();
    switch(e.which) {
      //left
      case 37:
        viewport.x -= 5;
        now.updateActor(viewport.x, viewport.y);
        break;
      //right
      case 39:
        viewport.x += 5;
        now.updateActor(viewport.x, viewport.y);
        break;
      //up
      case 38:
        viewport.y -= 5;
        now.updateActor(viewport.x, viewport.y);
        break;
      //down
      case 40:
        viewport.y += 5;
        now.updateActor(viewport.x, viewport.y);
        break; 
    }
  });
  now.ready(function() {
    now.updateActor(viewport.x, viewport.y);
  });
});

now.drawActors = function(actors) { 
  context.clearRect(0, 0, 500, 400);
  context.beginPath();


  for(var i in actors) {
    if(i == now.core.clientId) {
      context.fillStyle = 'red';
      context.fillRect(viewport.width / 2 + actors[i].x - viewport.x, viewport.height / 2 + actors[i].y - viewport.y, 5, 5);
     
      
    for (var x = -actors[i].x % 40; x < 500; x += 40) {
      context.moveTo(x, 0);
      context.lineTo(x, 400);
    }


    for (var y = -actors[i].y % 40; y < 400; y += 40) {
      context.moveTo(0, y);
      context.lineTo(500, y);
    }
   
    context.strokeStyle = "#eee";
    context.stroke();  
    } else {
      context.fillStyle = 'black';
      context.fillRect(viewport.width / 2 + actors[i].x - viewport.x, viewport.height / 2 + actors[i].y - viewport.y, 5, 5);
    }
  }
}
</script>


</head>

<body>

  <canvas id='map' width='500' height='400' tabindex='1' style="border:solid 1px #000000;"></canvas>

</body>
</html>


Now just execute mp_server.js like you have done with the other nowjs examples. Then point multiple browsers to localhost:8080 or whatever your testing medium might be.  You should have a fully working example of a multiplayer map.   We are well on our way.  Awesome.

Friday, January 6, 2012

RPT: .NET as a webpage language.

Stumbled on: http://smp.if.uj.edu.pl/~mkol/il2js/

 Github link: https://github.com/mkol/il2js/wiki

From their site:

IL2JS

IL2JS is .NET Framework, which allows to use any .NET language (for example C#) instead of JavaScript on your HTML page
It generates JavaScript, CSS and HTML files from .NET DLL files. It also allows for simple use of synchronous and asynchronous calls of .NET server-side methods, making AJAX and Comet style applications easier. All code before transformation to JavaScript is statically verified and optimized by .NET compiler, and then optimized to use features specific to JavaScript.
  • The main emphasis of project is to make generated JavaScript code as small as possible and allow for aggressive caching of files and data by browsers and proxy servers.
  • Second point of project is to make Web development easier in single environment (instead of mix of CSS, JavaScript, HTML, and server side scripts) and to remove manually added glue layers (automatic serializations, double form validation, error handling(partial)).
Generated JavaScript code uses prototype.js library. You can easily use other libraries in your code.
We are supporting both MS .NET 3.0 environment, as well Mono 2.4, and newer versions.


----
and:

Features

IL2JS framework supports multitude of basic features, which will drastically simplify common tasks of a webdeveloper. To list few most important:
  • dom - easily use standard HTML DOM interfaces to dynamically (and actually also statically) operate on Web Page, and interact with it in real time.
  • dotnet_methods - Many class/methods from System.* are available, and their usage is converted to equivalent JavaScript code. This can be easily and flexibly be extended by user.
  • ajax - automatically perform AJAX queries in multiple ways, ranging from just calling method to asynchronous events and error handling.
  • syntax - use all cool things and syntactic sugars from C#, or other .NET languages.
  • threads - write simple multi-threaded application which will run in the browser using standard Thread methods. Locking mechanisms are implemented.
  • exceptions - simplifies error handling. It even handles situations when exception was thrown on the Server side of AJAX call!
  • jsnative - allows for using JavaScript code directly in .NET. It also helps user in creating bindings to JavaScript interfaces and libraries, so they can be used transparently.
     
    ----
Now this is interesting.
Quite a bit of potential if you know .net but not javascript.  But I'm sure there is a penalty on speed/memory/etc.  This might be a great tool as a transitional element, for people moving from .NET to javascript, as I'm sure quite a few people are doing.  I remember learning C#/VB.NET sometime around 2002/2003 writing gdi+/bitblt/dx games trying to wrap/port all of my old stuff to .net, it was fun, it was long ago.  I don't know if I still have the chops to dive into .net, or the want really.  Javascript is my current future of hobby programming for the short term future.

Tuesday, December 27, 2011

Javascript Virtual Joystick

http://learningthreejs.com/blog/2011/12/26/let-s-make-a-3d-game-virtual-joystick/

This isn't going to be a lengthy article.  Just wanted everyone to know about: https://github.com/jeromeetienne/virtualjoystick.js



It's exactly what it sounds like, a virtual joystick for mobile devices.  Wonderful.