Permalink
Browse files

added 'debug' variable to turn on/off debug noise

  • Loading branch information...
1 parent 638f241 commit ea36d019a37dfc97d6b0a3e4bd66746263f0c91f @Arro Arro committed Nov 21, 2011
Showing with 36 additions and 25 deletions.
  1. +19 −13 games/ImpactJS/example-game/impact-pubnub.js
  2. +17 −12 games/ImpactJS/example-game/lib/game/main.js
View
32 games/ImpactJS/example-game/impact-pubnub.js
@@ -2,6 +2,7 @@ var pubnub = require('./pubnub.js');
var network;
exports.clients = {};
+exports.debug = false;
// node.js events are not working,
// let's define a simple event system
@@ -53,7 +54,8 @@ exports.startGame = function(players, entities) {
// bind events
exports.events.bind('ent_update_' + player_id, function(message) {
- console.log('received ' + message.type + ' on ' + message.id + ' from ' + player_id.substr(0,5));
+ if (exports.debug)
+ console.log('received ' + message.type + ' on ' + message.id + ' from ' + player_id.substr(0,5));
var entity = entities[message.id];
entity.pos = message.pos; // update position
@@ -105,7 +107,8 @@ exports.startGame = function(players, entities) {
});
exports.events.bind('disconnected_' + player_id, function(message) {
- console.log("player " + player_id.substr(0,5) + " left");
+ if (exports.debug)
+ console.log("player " + player_id.substr(0,5) + " left");
for (var i; i < players.length; i++) {
if (players[i] == player_id) continue;
exports.sendToUser(player.opponent, {'type': 'player_disconnected',
@@ -136,7 +139,8 @@ exports.initPlayer = function(player_id) {
'countdown': undefined };
exports.events.bind('still_here_' + player_id, function(message) {
- //console.log('received ' + message.type + ' from ' + player_id.substr(0,5));
+ if (exports.debug)
+ console.log('received ' + message.type + ' from ' + player_id.substr(0,5));
clearTimeout(client.timeout);
client.countdown = 3;
});
@@ -175,18 +179,20 @@ exports.sendToUser = function(player_id, message, callback) {
callback : callback
});
- switch (message.type) {
- case "ent_update":
- console.log('sent ' + message.type + ' on ent ' + message.id+ ' to ' + player_id.substr(0,5));
- break;
+ if (exports.debug) {
+ switch (message.type) {
+ case "ent_update":
+ console.log('sent ' + message.type + ' on ent ' + message.id+ ' to ' + player_id.substr(0,5));
+ break;
- case "still_there":
- //console.log('sent ' + message.type + ' to ' + player_id.substr(0,5));
- break;
+ case "still_there":
+ console.log('sent ' + message.type + ' to ' + player_id.substr(0,5));
+ break;
- default:
- console.log('sent ' + message.type + ' to ' + player_id.substr(0,5));
- break;
+ default:
+ console.log('sent ' + message.type + ' to ' + player_id.substr(0,5));
+ break;
+ }
}
};
View
29 games/ImpactJS/example-game/lib/game/main.js
@@ -15,6 +15,9 @@ ig.module(
.defines(function(){
MyGame = ig.PubNubGame.extend({
+
+ // make true to see debug info on screen
+ debug: false,
// Load a font
font: new ig.Font( 'media/04b03.font.png' ),
@@ -97,19 +100,21 @@ MyGame = ig.PubNubGame.extend({
draw: function() {
// Draw all entities and backgroundMaps
this.parent();
- puck = this.getPuck();
- paddle1 = this.getPaddle1();
- paddle2 = this.getPaddle2();
- if (puck.belongs_to_me === true) {
- this.font.draw("belongs_to_me", puck.pos.x, puck.pos.y );
- }
- if (paddle1.belongs_to_me === true) {
- this.font.draw("belongs_to_me", paddle1.pos.x + 15, paddle1.pos.y + 5 );
- }
- if (paddle2.belongs_to_me === true) {
- this.font.draw("belongs_to_me", paddle2.pos.x + 15, paddle2.pos.y + 5 );
+ if (this.debug) {
+ puck = this.getPuck();
+ paddle1 = this.getPaddle1();
+ paddle2 = this.getPaddle2();
+ if (puck.belongs_to_me === true) {
+ this.font.draw("belongs_to_me", puck.pos.x, puck.pos.y );
+ }
+ if (paddle1.belongs_to_me === true) {
+ this.font.draw("belongs_to_me", paddle1.pos.x + 15, paddle1.pos.y + 5 );
+ }
+ if (paddle2.belongs_to_me === true) {
+ this.font.draw("belongs_to_me", paddle2.pos.x + 15, paddle2.pos.y + 5 );
+ }
+ this.font.draw("you are " + this.which_player, 370, 100 );
}
- this.font.draw("you are " + this.which_player, 370, 100 );
this.font.draw(this.player_notification, 370, 80 );
},

0 comments on commit ea36d01

Please sign in to comment.