Skip to content

Commit

Permalink
Get it working...
Browse files Browse the repository at this point in the history
  • Loading branch information
BonsaiDen committed Jan 6, 2012
1 parent 76933e0 commit 913aa7c
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 263 deletions.
29 changes: 18 additions & 11 deletions client/bison.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,12 @@
type, top, value, obj,

// Objects
getKey = false, key = null, isObj, decoded;
getKey = false, key, isObj, decoded;

while (pos < l) {

// Grab type from string and current top of stack
type = string.charCodeAt(pos++);
obj = top;

// Null
if (type === 0) {
Expand All @@ -171,14 +170,25 @@
} else if (type < 5) {

value = type === 3 ? [] : {};
getKey = isObj = key !== null || type === 4;
top = stack[++i] = value;

if (decoded === undefined) {
decoded = value;
continue;

} else {

if (isObj) {
top[key] = value;

} else {
top.push(value)
}
}

getKey = type === 4;
top = stack[++i] = value;
isObj = !(top instanceof array);
continue;

// Close Array / Object
} else if (type === 5) {
top = stack[--i];
Expand Down Expand Up @@ -240,13 +250,12 @@
}

// Assign value to top of stack or return value
if (isObj && key !== null) {
obj[key] = value;
if (isObj) {
top[key] = value;
getKey = true;
key = null;

} else {
obj.push(value);
top.push(value);
}

}
Expand All @@ -268,5 +277,3 @@

})();


exports.encode([1.16, 65533.01, 24.123123])
15 changes: 11 additions & 4 deletions client/flash/web_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
// Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol

(function() {


if (typeof WebSocket === 'undefined') {
if (typeof MozWebSocket !== 'undefined') {
WebSocket = MozWebSocket;
}
}


if (window.WebSocket) return;

var console = window.console;
Expand Down Expand Up @@ -33,7 +40,7 @@
});
}, 1);
}

WebSocket.prototype.__createFlash = function(url, protocol, proxyHost, proxyPort, headers) {
var self = this;
self.__flash =
Expand Down Expand Up @@ -359,7 +366,7 @@
WebSocket.__tasks.push(task);
}
};

WebSocket.__isFlashLite = function() {
if (!window.navigator || !window.navigator.mimeTypes) return false;
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
Expand All @@ -384,5 +391,5 @@
window.attachEvent("onload", WebSocket.__initialize);
}
}

})();
66 changes: 35 additions & 31 deletions client/game.events.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
NodeGame: Shooter
Copyright (c) 2010 Ivo Wetzel.
All rights reserved.
NodeGame: Shooter is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License along with
NodeGame: Shooter. If not, see <http://www.gnu.org/licenses/>.
*/


Expand All @@ -27,14 +27,14 @@ Shooter.onCreate = function(flash) {
if (document.cookie !== 'SET') {
document.cookie = 'SET'; // FF fix for certain cookie settings
}

// Sounds
this.sound = new SoundPlayer(7, 'sounds', [
'explosionBig',
'explosionMedium',
'explosionShip',
'explosionSmall',

'fadeIn',
'fadeOut',
'launchBig',
Expand All @@ -45,30 +45,31 @@ Shooter.onCreate = function(flash) {
'powerSound'
]);
this.onSound(this.getItem('sound', false));

// Tutorial
this.tutorialTimers = [null, null];
this.tutorialFadeTimer = null;
this.onTutorial(this.getItem('tutorial', true));

// Achievements
this.achievementTimer = null;
this.achievementFadeTimer = null;
this.achievementPriority = 0;

// General
var that = this;
this.reset();
this.colorSelected = this.getItemInt('color');
this.colorSelected = this.getItemInt('color');

// Input
this.keys = {};
window.onkeydown = window.onkeyup = function(e) {

var key = e.keyCode;
if (key !== 116 && !e.shiftKey && !e.altKey && !e.ctrlKey) {
if (e.type === "keydown") {
that.keys[key] = 1;

} else {
that.keys[key] = 2;
}
Expand All @@ -77,34 +78,37 @@ Shooter.onCreate = function(flash) {
return false;
}
}

};

window.onblur = function(e) {
that.keys = {};
};

$('login').onkeypress = function(e) {
that.onLogin(e);
};

if (flash) {
show('warning');
}

// Firefox race condition with the colors div...
window.setTimeout(function(){that.createColors();}, 0);

};

Shooter.onConnect = function(success) {
Shooter.onConnect = function(success) {
if (!success) {
this.watch();

} else {
this.send(['init']);
}
};

Shooter.onUpdate = function(data, init) {

// Fields
if (data.s !== undefined) {
this.width = data.s[0];
Expand All @@ -119,36 +123,36 @@ Shooter.onUpdate = function(data, init) {
if (data.o !== undefined) {
this.playerColors = data.o;
}
if (data.p !== undefined) {
if (data.p !== undefined) {
this.playerNames = data.p;
this.checkPlayers(data);
}
if (data.rg !== undefined) {
this.checkRound(data);
}

if (init) {
this.initCanvas();
if (!this.watching) {
show('loginBox');
$('login').focus();
}
show('sub');
show('sub');
show(this.canvas);
$('gameInfo').style.width = this.width + 'px';
$('gameInfoRight').style.width = 260 + 'px';
$('gameInfoLeft').style.width = (this.width - 16 - 260) + 'px';

} else {
// Tutorial
if (this.playing && !this.tutorialStarted && this.roundGO) {
this.tutorial(this.tutorialNext);
this.tutorialStarted = true;

} else if (!this.roundGO && $('tutorial').style.display !== 'none') {
this.tutorialFadeOut();
}

if (!this.roundGO) {
this.achievementHide();
}
Expand Down Expand Up @@ -176,7 +180,7 @@ Shooter.onMessage = function(msg) {
Shooter.onClose = function(error) {
if (this.kicked) {
this.play();

} else {
this.watch();
}
Expand All @@ -194,7 +198,7 @@ Shooter.onInput = function() {
this.keys[65] || this.keys[37] || 0,
this.keys[32] || 0]
};

for(var i in this.keys) {
if (this.keys[i] === 2) {
this.keys[i] = 0;
Expand Down Expand Up @@ -228,7 +232,7 @@ Shooter.onServerStatus = function(online) {
$('serverStatus').innerHTML = 'SERVER ONLINE!';
hide('watching');
show('goplaying');

} else {
$('serverStatus').innerHTML = 'SERVER OFFLINE';
show('watching');
Expand All @@ -239,7 +243,7 @@ Shooter.onServerStatus = function(online) {
Shooter.onSound = function(data) {
if (data !== undefined) {
this.sound.enabled = data;

} else {
this.sound.enabled = !this.sound.enabled;
}
Expand All @@ -251,7 +255,7 @@ Shooter.onSound = function(data) {
Shooter.onTutorial = function(data) {
if (data !== undefined) {
this.tutorialEnabled = data;

} else {
this.tutorialEnabled = !this.tutorialEnabled;
}
Expand All @@ -263,11 +267,11 @@ Shooter.onTutorial = function(data) {
this.tutorial(this.tutorialNext);
this.tutorialStarted = true;
}

this.setItem('tutorial', this.tutorialEnabled);
$('tut').innerHTML = (this.tutorialEnabled ? 'DISABLE' : 'RE-ENABLE')
+ ' TUTORIAL';

if (!this.tutorialEnabled && $('tutorial').style.display !== 'none') {
this.tutorialFadeOut();
}
Expand Down
Loading

0 comments on commit 913aa7c

Please sign in to comment.