-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 978f3a5
Showing
6 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_STORE | ||
node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.