Meteor.com is a wonderful JavaScript framework which enables developers to make reactive, top-quality web applications in lightning speed. It is a perfect way to get the functionality of a node.js implementation without all the hassle.
In this example, I created a game – the most basic of games! – called Block vs Block. The aim of the game is to place more blocks than anyone else, in the world, ever, by clicking within a dotted area. You can see the final product (and try and win the game) at:
Demo: http://convincingly-magnificent-leaderboard-experiment.meteor.com/
Source: https://github.com/andygirvan/MeteorBlocks
Update: For some unknown reason, the once-working demo has stopped working! I’ll fix this as soon as possible…
Update 2: New blog post about the latest updates to Meteor JS: What’s happening with Meteor JS?
Tutorial
Step 1 – Install Meteor on your local computer
First things first, you need to install the Meteor environment onto your local computer. You can enter this into the terminal:
Step 2 – Create a Meteor project and run it
The next step is to use the Meteor environment to create a Meteor project and run it as a server. To do this, enter this into the terminal:
This will initialise the meteor server and it is now accessible in your browser at http://localhost:3000. If port 3000 is unavailable, you can use –port as an option when running the meteor server:
Step 3 – Reorganise
I like to set up my Meteor projects into 3 areas:
- - General (contains Block-vs-Block.html, Block-vs-Block.css and Block-vs-Block.js)
- - Server (contains server.js)
- - Client (contains client.js)
-
Step 4 – Create the HTML and the Game (Canvas)
- To implement the Meteor JS funtionality, we need a game layer to be able to play with – otherwise there would be no challenge! In this example, I have used basic Canvas techniques to place a blue block on user click. All the functionality for the game was placed into a Game class in Block-vs-Block.js:
- As well as this, we need to set up the basic HTML structure in Block-vs-Block.html:
Step 5 – Set up the data objects
When a user starts the game, they are associated to a player who can then place Blocks onto the game board. This means we’ll need to create a Player and a Block object, available for the whole application. In Block-vs-Block.js:
Step 6 – Setup the Meteor client functionality
In order for the client to recognise there is a new player who is able to interact with the game object, we need to edit the client.js file and put in the following:
Step 7 – Create a block & associate to the current player
In an earlier step, we had an eventListener for the click event within the canvas. We want to use a similar method to the Player.insert({}) functionality to create, place and associate a new Shape/Block on click. To do this, we want to do:
To draw this new block to the screen, we want to add a draw loop through ALL the shapes in the database in the Canvas redraw method:
If you check your application you should be able to click and create blue squares all over the canvas area. Thats 99% of the game, all we need to do now is show who’s winning…
Step 8 – Create the Leaderboard
Now that the game is up and running, we need to keep track of who has the most blocks. To do this, we need to add a bit of HTML to the Block-vs-Block.html file:
The final thing we need to do now is populate the template. This is done in client.js:
And that’s it!
And that’s it! You should be able to re-load your game and start climbing up the leaderboard to become the BEST at Block vs Block!
The full source code is available on GitHub at: https://github.com/andygirvan/MeteorBlocks and demo at http://convincingly-magnificent-leaderboard-experiment.meteor.com/
To step further into the world of Meteor, here are a few links to some recent tutorials/blogs:
- Build web apps the suspiciously easy way with Meteor.js
- What’s This Meteor Thing?
- Meteor JS


Meteor lite | Calicastillo
Jul 13, 2012 -
[...] BlockVsBlock – A basic introduction to Meteor JS – Andy Girvan … [...]
Joe chapman
Oct 3, 2012 -
Thanks for the overview. P.S, I can’t see the code terminal examples on my iPhone. P.P.S, why don’t you use the prototype?
Meteor Resources | narvenblog – there's something about the web…
Nov 5, 2012 -
[...] BlockVsBlock – A basic introduction tutorial to Meteor JS [...]
Dolores
Feb 1, 2013 -
Hello there! Would you mind if I share your blog with my myspace group?
There’s a lot of folks that I think would really appreciate your content. Please let me know. Cheers
admin
Feb 19, 2013 -
Absolutely – share away
This Site
Feb 24, 2013 -
Everyone loves what you guys tend to be up too.
This type of clever work and exposure! Keep up the
very good works guys I’ve added you guys to blogroll.
What’s happening with Meteor JS? | Andy Girvan
Mar 13, 2013 -
[...] while ago, I posted a mini-tutorial on how to use the latest Javascript platform Meteor JS to create a simple game. It’s been [...]
Dhruv Mehrotra
Apr 5, 2013 -
FYI It seems that there have been some changes to Meteor. It looks like Meteor.deps.Context has changed to Deps.Computation. So the startUpdateListener function should be changed to.
this.startUpdateListener = function() {
var redrawCanvas = function() {
Deps.autorun(function() {
var shapes = Shapes.find({})
shapes.forEach(function(shape) {
ctx.fillStyle = “rgba(0, 0, 200, 0.5)”;
ctx.fillRect (shape.positionx, shape.positiony, 20, 20);
})
})
}
redrawCanvas()
}
Nathan Schuett
May 20, 2013 -
Thanks @ Dhruv Mehrotra for posting that fix. I was getting an error:
“Uncaught TypeError: Cannot read property ‘Context’ of undefined meteor”
and your code cleaned it right up.