Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 17 commits
  • 19 files changed
  • 1 commit comment
  • 5 contributors
View
27 bin/build.sh
@@ -2,21 +2,30 @@
# Script to generate an optimized client build of BrowserQuest
-BUILDDIR="../client-build"
-PROJECTDIR="../client/js"
-CURDIR=$(pwd)
+TOPLEVELDIR="`dirname $0`/.."
+BUILDDIR="$TOPLEVELDIR/client-build"
+PROJECTDIR="$TOPLEVELDIR/client/js"
echo "Deleting previous build directory"
rm -rf $BUILDDIR
echo "Building client with RequireJS"
-cd $PROJECTDIR
-node ../../bin/r.js -o build.js
-cd $CURDIR
+node $TOPLEVELDIR/bin/r.js -o $PROJECTDIR/build.js
echo "Removing unnecessary js files from the build directory"
-find $BUILDDIR/js -type f -not \( -name "game.js" -o -name "home.js" -o -name "log.js" -o -name "require-jquery.js" -o -name "modernizr.js" -o -name "css3-mediaqueries.js" -o -name "mapworker.js" -o -name "detect.js" -o -name "underscore.min.js" -o -name "text.js" \) -delete
+find $BUILDDIR/js -type f \
+ -not \( -name "game.js" \
+ -o -name "home.js" \
+ -o -name "log.js" \
+ -o -name "require-jquery.js" \
+ -o -name "modernizr.js" \
+ -o -name "css3-mediaqueries.js" \
+ -o -name "mapworker.js" \
+ -o -name "detect.js" \
+ -o -name "underscore.min.js" \
+ -o -name "text.js" \) \
+ -delete
echo "Removing sprites directory"
rm -rf $BUILDDIR/sprites
@@ -25,6 +34,6 @@ echo "Removing config directory"
rm -rf $BUILDDIR/config
echo "Moving build.txt to current dir"
-mv $BUILDDIR/build.txt $CURDIR
+mv $BUILDDIR/build.txt $TOPLEVELDIR
-echo "Build complete"
+echo "Build complete"
View
4 client/index.html
@@ -75,7 +75,7 @@ <h1 id="logo">
<div></div>
</div>
<form action="none" method="get" accept-charset="utf-8">
- <input type="text" id="nameinput" class="stroke" name="player-name" placeholder="Name your character" maxlength="15">
+ <input type="text" id="nameinput" class="stroke" name="player-name" placeholder="Name your character" maxlength="15" autofocus>
</form>
<div class="play button disabled">
<div></div>
@@ -339,7 +339,7 @@ <h1 id="logo">
if(!Modernizr.localstorage) {
var alert = document.createElement("div");
alert.className = 'alert';
- alertMsg = document.createTextNode("You need to enable cookies/localStorage to play BrowserQuest");
+ var alertMsg = document.createTextNode("You need to enable cookies/localStorage to play BrowserQuest");
alert.appendChild(alertMsg);
target = document.getElementById("intro");
View
10 client/js/app.js
@@ -230,8 +230,8 @@ define(['jquery', 'storage'], function($, Storage) {
},
initEquipmentIcons: function() {
- var scale = this.game.renderer.getScaleFactor();
- var getIconPath = function(spriteName) {
+ var scale = this.game.renderer.getScaleFactor(),
+ getIconPath = function(spriteName) {
return 'img/'+ scale +'/item-' + spriteName + '.png';
},
weapon = this.game.player.getWeaponName(),
@@ -281,9 +281,9 @@ define(['jquery', 'storage'], function($, Storage) {
},
displayUnlockedAchievement: function(id) {
- var $achievement = $('#achievements li.achievement' + id);
+ var $achievement = $('#achievements li.achievement' + id),
+ achievement = this.game.getAchievementById(id);
- var achievement = this.game.getAchievementById(id);
if(achievement && achievement.hidden) {
this.setAchievementData($achievement, achievement.name, achievement.desc);
}
@@ -319,7 +319,7 @@ define(['jquery', 'storage'], function($, Storage) {
$a.find('.twitter').attr('href', 'http://twitter.com/share?url=http%3A%2F%2Fbrowserquest.mozilla.org&text=I%20unlocked%20the%20%27'+ achievement.name +'%27%20achievement%20on%20Mozilla%27s%20%23BrowserQuest%21&related=glecollinet:Creators%20of%20BrowserQuest%2Cwhatthefranck');
$a.show();
$a.find('a').click(function() {
- var url = $(this).attr('href');
+ var url = $(this).attr('href');
self.openPopup('twitter', url);
return false;
View
4 client/js/audio.js
@@ -189,7 +189,7 @@ define(['area'], function(Area) {
if(music && !music.sound.fadingOut) {
this.clearFadeIn(music);
music.sound.fadingOut = setInterval(function() {
- var step = 0.02;
+ var step = 0.02,
volume = music.sound.volume - step;
if(self.enabled && volume >= step) {
@@ -208,7 +208,7 @@ define(['area'], function(Area) {
if(music && !music.sound.fadingIn) {
this.clearFadeOut(music);
music.sound.fadingIn = setInterval(function() {
- var step = 0.01;
+ var step = 0.01,
volume = music.sound.volume + step;
if(self.enabled && volume < 1 - step) {
View
2 client/js/character.js
@@ -65,7 +65,7 @@ define(['entity', 'transition', 'timer'], function(Entity, Transition, Timer) {
},
animate: function(animation, speed, count, onEndCount) {
- var oriented = ['atk', 'walk', 'idle'];
+ var oriented = ['atk', 'walk', 'idle'],
o = this.orientation;
if(!(this.currentAnimation && this.currentAnimation.name === "death")) { // don't change animation if the character is dying
View
4 client/js/entity.js
@@ -166,8 +166,8 @@ define(function() {
*
*/
getDistanceToEntity: function(entity) {
- var distX = Math.abs(entity.gridX - this.gridX);
- var distY = Math.abs(entity.gridY - this.gridY);
+ var distX = Math.abs(entity.gridX - this.gridX),
+ distY = Math.abs(entity.gridY - this.gridY);
return (distX > distY) ? distX : distY;
},
View
84 client/js/game.js
@@ -1561,13 +1561,58 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
},
/**
+ *
+ */
+ makePlayerAttackNext: function()
+ {
+
+ pos = {
+ x: this.player.gridX,
+ y: this.player.gridY
+ };
+ switch(this.player.orientation)
+ {
+ case Types.Orientations.DOWN:
+ pos.y += 1;
+ this.makePlayerAttackTo(pos);
+ break;
+ case Types.Orientations.UP:
+ pos.y -= 1;
+ this.makePlayerAttackTo(pos);
+ break;
+ case Types.Orientations.LEFT:
+ pos.x -= 1;
+ this.makePlayerAttackTo(pos);
+ break;
+ case Types.Orientations.RIGHT:
+ pos.x += 1;
+ this.makePlayerAttackTo(pos);
+ break;
+
+ default:
+ break;
+ }
+ },
+
+ /**
+ *
+ */
+ makePlayerAttackTo: function(pos)
+ {
+ entity = this.getEntityAt(pos.x, pos.y);
+ if(entity instanceof Mob) {
+ this.makePlayerAttack(entity);
+ }
+ },
+
+ /**
* Moves the current player to a given target location.
* @see makeCharacterGoTo
*/
makePlayerGoTo: function(x, y) {
this.makeCharacterGoTo(this.player, x, y);
},
-
+
/**
* Moves the current player towards a specific item.
* @see makeCharacterGoTo
@@ -1817,7 +1862,7 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
*/
findPath: function(character, x, y, ignoreList) {
var self = this,
- grid = this.pathingGrid;
+ grid = this.pathingGrid,
path = [],
isPlayer = (character === this.player);
@@ -1899,20 +1944,39 @@ function(InfoManager, BubbleManager, Renderer, Map, Animation, Sprite, AnimatedT
}
},
- /**
- * Processes game logic when the user triggers a click/touch event during the game.
- */
- click: function() {
- var pos = this.getMouseGridPosition(),
- entity;
-
+ /**
+ * Moves the player one space, if possible
+ */
+ keys: function(pos, orientation) {
+ oldHoveringCollidingValue = this.hoveringCollidingTile;
+ this.hoveringCollidingTile = false;
+
+ this.processInput(pos);
+ this.player.turnTo(orientation);
+
+ this.hoveringCollidingTile = oldHoveringCollidingValue;
+ },
+
+ click: function()
+ {
+ var pos = this.getMouseGridPosition();
+
if(pos.x === this.previousClickPosition.x
&& pos.y === this.previousClickPosition.y) {
return;
} else {
this.previousClickPosition = pos;
}
-
+
+ this.processInput(pos);
+ },
+
+ /**
+ * Processes game logic when the user triggers a click/touch event during the game.
+ */
+ processInput: function(pos) {
+ var entity;
+
if(this.started
&& this.player
&& !this.isZoning()
View
6 client/js/gameclient.js
@@ -293,9 +293,9 @@ define(['player', 'entityfactory', 'lib/bison'], function(Player, EntityFactory,
receiveDrop: function(data) {
var mobId = data[1],
id = data[2],
- kind = data[3];
-
- var item = EntityFactory.createEntity(kind, id);
+ kind = data[3],
+ item = EntityFactory.createEntity(kind, id);
+
item.wasDropped = true;
item.playersInvolved = data[4];
View
52 client/js/main.js
@@ -307,13 +307,63 @@ define(['jquery', 'app'], function($, App) {
var key = e.which,
$chat = $('#chatinput');
- if(key === 13) {
+ if(key === Types.Keys.ENTER) {
if($('#chatbox').hasClass('active')) {
app.hideChat();
} else {
app.showChat();
}
}
+ if (game.started && !$('#chatbox').hasClass('active'))
+ {
+ pos = {
+ x: game.player.gridX,
+ y: game.player.gridY
+ };
+ switch(key) {
+ case Types.Keys.LEFT:
+ case Types.Keys.A:
+ case Types.Keys.KEYPAD_4:
+ pos.x -= 1;
+ game.keys(pos, Types.Orientations.LEFT);
+ break;
+ case Types.Keys.RIGHT:
+ case Types.Keys.D:
+ case Types.Keys.KEYPAD_6:
+ pos.x += 1;
+ game.keys(pos, Types.Orientations.RIGHT);
+ break;
+ case Types.Keys.UP:
+ case Types.Keys.W:
+ case Types.Keys.KEYPAD_8:
+ pos.y -= 1;
+ game.keys(pos, Types.Orientations.UP);
+ break;
+ case Types.Keys.DOWN:
+ case Types.Keys.S:
+ case Types.Keys.KEYPAD_2:
+ pos.y += 1;
+ game.keys(pos, Types.Orientations.DOWN);
+ break;
+ case Types.Keys.SPACE:
+ game.makePlayerAttackNext();
+ break;
+ case Types.Keys.I:
+ $('#achievementsbutton').click();
+ break;
+ case Types.Keys.H:
+ $('#helpbutton').click();
+ break;
+ case Types.Keys.M:
+ $('#mutebutton').click();
+ break;
+ case Types.Keys.P:
+ $('#playercount').click();
+ break;
+ default:
+ break;
+ }
+ }
});
$('#chatinput').keydown(function(e) {
View
10 client/js/map.js
@@ -123,8 +123,8 @@ define(['jquery', 'area'], function($, Area) {
},
_loadTileset: function(filepath) {
- var self = this;
- var tileset = new Image();
+ var self = this,
+ tileset = new Image();
tileset.src = filepath;
@@ -161,7 +161,7 @@ define(['jquery', 'area'], function($, Area) {
return 0;
}
return (num % w == 0) ? w - 1 : (num % w) - 1;
- }
+ };
tileNum -= 1;
x = getX(tileNum + 1, this.width);
@@ -193,7 +193,7 @@ define(['jquery', 'area'], function($, Area) {
self = this;
this.grid = [];
- for(var j, i = 0; i < this.height; i++) {
+ for(var j, i = 0; i < this.height; i++) {
this.grid[i] = [];
for(j = 0; j < this.width; j++) {
this.grid[i][j] = 0;
@@ -218,7 +218,7 @@ define(['jquery', 'area'], function($, Area) {
var tileIndex = 0;
this.plateauGrid = [];
- for(var j, i = 0; i < this.height; i++) {
+ for(var j, i = 0; i < this.height; i++) {
this.plateauGrid[i] = [];
for(j = 0; j < this.width; j++) {
if(_.include(this.plateau, tileIndex)) {
View
6 client/js/mapworker.js
@@ -12,7 +12,7 @@ function generateCollisionGrid() {
var tileIndex = 0;
mapData.grid = [];
- for(var j, i = 0; i < mapData.height; i++) {
+ for(var j, i = 0; i < mapData.height; i++) {
mapData.grid[i] = [];
for(j = 0; j < mapData.width; j++) {
mapData.grid[i][j] = 0;
@@ -36,7 +36,7 @@ function generatePlateauGrid() {
var tileIndex = 0;
mapData.plateauGrid = [];
- for(var j, i = 0; i < mapData.height; i++) {
+ for(var j, i = 0; i < mapData.height; i++) {
mapData.plateauGrid[i] = [];
for(j = 0; j < mapData.width; j++) {
if(_.include(mapData.plateau, tileIndex)) {
@@ -58,7 +58,7 @@ function tileIndexToGridPosition(tileNum) {
return 0;
}
return (num % w == 0) ? w - 1 : (num % w) - 1;
- }
+ };
tileNum -= 1;
x = getX(tileNum + 1, mapData.width);
View
13 client/js/renderer.js
@@ -131,9 +131,8 @@ function(Camera, Item, Character, Player, Timer) {
},
drawText: function(text, x, y, centered, color, strokeColor) {
- var ctx = this.context;
-
- var strokeSize;
+ var ctx = this.context,
+ strokeSize;
switch(this.scale) {
case 1:
@@ -334,7 +333,7 @@ function(Camera, Item, Character, Player, Timer) {
ds = this.upscaledRendering ? this.scale : 1;
if(anim && sprite) {
- var frame = anim.currentFrame,
+ var frame = anim.currentFrame,
s = this.scale,
x = frame.x * os,
y = frame.y * os,
@@ -400,7 +399,7 @@ function(Camera, Item, Character, Player, Timer) {
if(weapon) {
var weaponAnimData = weapon.animationData[anim.name],
- index = frame.index < weaponAnimData.length ? frame.index : frame.index % weaponAnimData.length;
+ index = frame.index < weaponAnimData.length ? frame.index : frame.index % weaponAnimData.length,
wx = weapon.width * index * os,
wy = weapon.height * anim.row * os,
ww = weapon.width * os,
@@ -468,7 +467,7 @@ function(Camera, Item, Character, Player, Timer) {
});
if(this.game.clearTarget && this.lastTargetPos) {
- var last = this.lastTargetPos;
+ var last = this.lastTargetPos,
rect = this.getTargetBoundingRect(last.x, last.y);
this.clearDirtyRect(rect);
@@ -688,7 +687,7 @@ function(Camera, Item, Character, Player, Timer) {
shadow = this.game.shadows["small"],
sw = shadow.width * os,
sh = shadow.height * os,
- ox = -sprite.offsetX * os;
+ ox = -sprite.offsetX * os,
oy = -sprite.offsetY * os;
canvas.width = w;
View
13 package.json
@@ -0,0 +1,13 @@
+{
+ "name": "BrowserQuest",
+ "version": "0.1.0",
+ "scripts": {"start": "node server/js/main.js"},
+ "dependencies":
+ {"underscore": "1.x",
+ "log": "1.x",
+ "bison": "1.x",
+ "websocket": "1.x",
+ "websocket-server": "1.x",
+ "sanitizer": "0.x",
+ "memcache": "0.x"}
+}
View
1 server/README.md
@@ -9,6 +9,7 @@ The game server currently runs on nodejs v0.4.7 (but should run fine on the late
- websocket
- websocket-server
- sanitizer
+- memcache
All of them can be installed via `npm install [module_name]`
View
9 server/js/main.js
@@ -9,11 +9,11 @@ function main(config) {
Log = require('log'),
_ = require('underscore'),
server = new ws.MultiVersionWebsocketServer(config.port),
- metrics = config.metrics_enabled ? new Metrics(config) : null;
+ metrics = config.metrics_enabled ? new Metrics(config) : null,
worlds = [],
lastTotalPlayers = 0,
checkPopulationInterval = setInterval(function() {
- if(metrics.isReady) {
+ if(metrics && metrics.isReady) {
metrics.getTotalPlayers(function(totalPlayers) {
if(totalPlayers !== lastTotalPlayers) {
lastTotalPlayers = totalPlayers;
@@ -44,7 +44,7 @@ function main(config) {
}
};
- if(config.metrics_enabled) {
+ if(metrics) {
metrics.getOpenWorldCount(function(open_world_count) {
// choose the least populated world among open worlds
world = _.min(_.first(worlds, open_world_count), function(w) { return w.playerCount; });
@@ -78,8 +78,7 @@ function main(config) {
var world = new WorldServer('world'+ (i+1), config.nb_players_per_world, server);
world.run(config.map_filepath);
worlds.push(world);
-
- if(config.metrics_enabled) {
+ if(metrics) {
world.onPlayerAdded(onPopulationChange);
world.onPlayerRemoved(onPopulationChange);
}
View
8 server/js/map.js
@@ -63,7 +63,7 @@ module.exports = Map = cls.Class.extend({
return 0;
}
return (num % w == 0) ? w - 1 : (num % w) - 1;
- }
+ };
tileNum -= 1;
x = getX(tileNum + 1, this.width);
@@ -81,7 +81,7 @@ module.exports = Map = cls.Class.extend({
if(this.isLoaded) {
var tileIndex = 0;
- for(var j, i = 0; i < this.height; i++) {
+ for(var j, i = 0; i < this.height; i++) {
this.grid[i] = [];
for(j = 0; j < this.width; j++) {
if(_.include(this.collisions, tileIndex)) {
@@ -201,8 +201,8 @@ module.exports = Map = cls.Class.extend({
},
getRandomStartingPosition: function() {
- var nbAreas = _.size(this.startingAreas);
- i = Utils.randomInt(0, nbAreas-1);
+ var nbAreas = _.size(this.startingAreas),
+ i = Utils.randomInt(0, nbAreas-1),
area = this.startingAreas[i];
return area.getRandomPosition();
View
7 server/js/metrics.js
@@ -1,14 +1,13 @@
var cls = require("./lib/class"),
- _ = require("underscore"),
- memcache = require("memcache");
+ _ = require("underscore");
module.exports = Metrics = Class.extend({
init: function(config) {
var self = this;
this.config = config;
- this.client = new memcache.Client(config.memcached_port, config.memcached_host),
+ this.client = new require("memcache").Client(config.memcached_port, config.memcached_host),
this.client.connect();
this.isReady = false;
@@ -73,4 +72,4 @@ module.exports = Metrics = Class.extend({
callback(result);
});
}
-});
+});
View
4 server/js/utils.js
@@ -61,8 +61,8 @@ Utils.Mixin = function(target, source) {
};
Utils.distanceTo = function(x, y, x2, y2) {
- var distX = Math.abs(x - x2);
- var distY = Math.abs(y - y2);
+ var distX = Math.abs(x - x2),
+ distY = Math.abs(y - y2);
return (distX > distY) ? distX : distY;
};
View
21 shared/js/gametypes.js
@@ -97,6 +97,27 @@ Types = {
DOWN: 2,
LEFT: 3,
RIGHT: 4
+ },
+
+ Keys: {
+ ENTER: 13,
+ UP: 38,
+ DOWN: 40,
+ LEFT: 37,
+ RIGHT: 39,
+ W: 87,
+ A: 65,
+ S: 83,
+ D: 68,
+ SPACE: 32,
+ I: 73,
+ H: 72,
+ M: 77,
+ P: 80,
+ KEYPAD_4: 100,
+ KEYPAD_6: 102,
+ KEYPAD_8: 104,
+ KEYPAD_2: 98
}
};

Showing you all comments on commits in this comparison.

@ejemba

Hi there it can be a good thing, if you made this compatible keyboard layout based (azerty, qwerty etc etc ) here I'm azerty ....

Something went wrong with that request. Please try again.