Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanoehlman committed Apr 5, 2012
0 parents commit 978f3a5
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_STORE
node_modules
*.log
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GameBase Types
-----------------

Using the code developed by Mozilla (and Little Worlds) for BrowserQuest as a base, GameBase is intended to be collection of reusable components for the creation of top-down HTML5 browser based games.

The types component is designed to provide common source for files which can be used on both the server, and client side.
49 changes: 49 additions & 0 deletions src/map/map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var _ = require('underscore'),
Tile = require('./tile');

/**
The 2dMap contains all the information related to a 2d map
**/
function Map2D(opts) {

opts = opts || {};
this.size = opts.size || {width: 300, height: 300};

this.initialise();
}

Map2D.prototype.initialise = function() {

this.tiles = new Array(this.size.width);
for (var i = 0; i < this.size.width; i++) {
this.tiles[i] = new Array(this.size.height);
}
}

/**
Gets the tile at the given coordinates
**/
Map2D.prototype.getTile = function(x, y) {
return this.tiles[x][y] = tile;
}

/**
Sets the tile at the given coordinates
**/
Map2D.prototype.setTile = function(x, y, tile) {
this.tiles[x][y] = tile;
}

Map2D.prototype.toJSON = function() {
var results = {world: {size: this.size}, tiles: []};

for (var i = 0; i < this.tiles.length; i++) {
var column = this.tiles[i];
for (var j = 0; j < column.length; j++) {
results.tiles.push(column[j]);
}
}
return results;
}

module.exports = Map2D;
27 changes: 27 additions & 0 deletions src/map/tile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Tile(opts) {

opts = opts || {};
this.update(opts);
}

Tile.prototype.update = function(opts) {
if (!opts) return;
if (opts.elevation) this.el = opts.elevation;
if (opts.terrain) this.tn = opts.terrain;
}

/**
Sets the height of the tile
**/
Tile.prototype.setElevation = function(elevation) {
this.el = elevation;
}

/**
Sets the terrain of the tile
**/
Tile.prototype.setTerrain = function(terrain) {
this.tn = terrain;
}

module.exports = Tile;
5 changes: 5 additions & 0 deletions src/utils/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
randomInRange: function(min, max) {
return Math.round(min+ (Math.random() * (max - min)));
}
}
Empty file added src/utils/sort.js
Empty file.

0 comments on commit 978f3a5

Please sign in to comment.