summaryrefslogtreecommitdiff
path: root/public/javascripts/game.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/javascripts/game.js')
-rw-r--r--public/javascripts/game.js25
1 files changed, 17 insertions, 8 deletions
diff --git a/public/javascripts/game.js b/public/javascripts/game.js
index be86b86..dc69682 100644
--- a/public/javascripts/game.js
+++ b/public/javascripts/game.js
@@ -1,5 +1,6 @@
-var cursor = "https://s3.amazonaws.com/luckyplop/52d5f60fde3d8562ad566838e0e09ca52725bb09.gif";
+var cursor_image = "https://s3.amazonaws.com/luckyplop/52d5f60fde3d8562ad566838e0e09ca52725bb09.gif";
+var own_cursor;
var socket = io.connect();
@@ -12,6 +13,11 @@ var game = {
init: function (){
game.bindSocket();
if (window._id) {
+ socket.emit('joined', JSON.stringify({ "id": window._id }));
+ own_cursor = new Cursor({
+ firstName: "you"
+ });
+ own_cursor.el.addClass("own");
game.bindEvents();
}
game.loop();
@@ -19,7 +25,7 @@ var game = {
loop: function (){
requestAnimFrame(game.loop);
- ui.updateWait(Date.now());
+ UI.updateWait(Date.now());
},
bindSocket: function(){
@@ -65,12 +71,15 @@ var game = {
$("#reset").html( "You left the page for " + timeInWords(delay) + ", counting it against your score.." );
}
}
- window.onmousemove = $.throttle(50, function (e) {
- var y = Math.floor( e.pageY - window.innerHeight / 2 );
- var x = Math.floor( e.pageX - window.innerWidth / 2 );
- socket.emit('mouse', { x: x, y: y, id: _id });
- own_cursor.el.css({ 'margin-right': -data.x, 'margin-bottom': -data.y });
+ var emit_mouse_movement = $.throttle(50, function (e) {
+ var y = Math.floor( e.pageY - window.innerHeight / 2 );
+ var x = Math.floor( e.pageX - window.innerWidth / 2 );
+ socket.emit('mouse', { x: x, y: y, id: _id });
});
+ window.onmousemove = function(e){
+ emit_mouse_movement(e);
+ own_cursor.el.css({ 'left': e.pageX, 'top': e.pageY });
+ }
}
};
@@ -88,7 +97,7 @@ var UI = {
$("#reset").html( "You left the page for " + timeInWords(now - blurTime) + ", counting it against your score.." );
}
}
- }
+ },
updateUsers: function(data) {
console.log(data.users);