mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
parent
89c5e4a5d8
commit
ed23753c04
17 changed files with 286 additions and 224 deletions
|
|
@ -37,6 +37,9 @@ function (Key) {
|
|||
if(callback) this._playerController[callback]();
|
||||
key.setActive(true);
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
if(e.keyCode == 9) return false;
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyUp = function (e) {
|
||||
|
|
@ -46,6 +49,9 @@ function (Key) {
|
|||
if(callback) this._playerController[callback]();
|
||||
key.setActive(false);
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
if(e.keyCode == 9) return false;
|
||||
}
|
||||
|
||||
return KeyboardInput;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
down: 40,
|
||||
right: 39,
|
||||
|
||||
space: 32
|
||||
space: 32,
|
||||
|
||||
tab: 9
|
||||
}
|
||||
|
||||
this.init(keys);
|
||||
|
|
@ -47,6 +49,8 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
this.keyboardInput.registerKey(keys.w, 'jump');
|
||||
this.keyboardInput.registerKey(keys.up, 'jump');
|
||||
this.keyboardInput.registerKey(keys.space, 'jump');
|
||||
|
||||
this.keyboardInput.registerKey(keys.tab, 'showInfo', 'hideInfo');
|
||||
}
|
||||
|
||||
PlayerController.prototype.moveLeft = function () {
|
||||
|
|
@ -78,7 +82,16 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
PlayerController.prototype.handActionRequest = function(x, y) {
|
||||
var options = {x:x, y:y};
|
||||
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);
|
||||
};
|
||||
};
|
||||
|
||||
PlayerController.prototype.showInfo = function() {
|
||||
NotificationCenter.trigger("game/toggleInfo", true);
|
||||
};
|
||||
|
||||
PlayerController.prototype.hideInfo = function() {
|
||||
NotificationCenter.trigger("game/toggleInfo", false);
|
||||
};
|
||||
|
||||
|
||||
return PlayerController;
|
||||
});
|
||||
|
|
@ -18,6 +18,8 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
this.view = ViewManager.createView();
|
||||
this.me = null;
|
||||
|
||||
NotificationCenter.on("game/toggleInfo", this.toggleInfo, this);
|
||||
|
||||
Parent.call(this);
|
||||
}
|
||||
|
||||
|
|
@ -136,6 +138,11 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
}
|
||||
};
|
||||
|
||||
GameController.prototype.onPlayerKill = function(playerId) {
|
||||
var player = this.players[options.playerId];
|
||||
player.kill();
|
||||
};
|
||||
|
||||
GameController.prototype.loadLevel = function (path) {
|
||||
Parent.prototype.loadLevel.call(this, path);
|
||||
}
|
||||
|
|
@ -148,5 +155,56 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
Parent.prototype.userLeft.call(this, user);
|
||||
}
|
||||
|
||||
GameController.prototype.toggleInfo = function(show) {
|
||||
|
||||
var playersArray = [];
|
||||
for (var key in this.players) {
|
||||
playersArray.push(this.players[key]);
|
||||
};
|
||||
|
||||
var sortedPlayers = playersArray.sort(function(a,b) {
|
||||
if(a.score > b.score) return 1;
|
||||
if(a.score < b.score) return -1;
|
||||
if(a.deaths < b.deaths) return 1;
|
||||
if(a.deaths > b.deaths) return -1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
function pad(string, max, alignLeft) {
|
||||
string = string.substring(0, max - 1);
|
||||
|
||||
var spaces = new Array( max - string.length + 1 ).join(" ");
|
||||
if(alignLeft) {
|
||||
return string + spaces;
|
||||
} else {
|
||||
return spaces + string;
|
||||
}
|
||||
}
|
||||
|
||||
var string = "" +
|
||||
pad("#", 2, false) + " " +
|
||||
pad("Name", 12, true) +
|
||||
pad("Score", 6, false) +
|
||||
pad("Deaths", 7, false) +
|
||||
pad("Health", 7, false) +
|
||||
"\n-----------------------------------\n";
|
||||
|
||||
var lines = [];
|
||||
sortedPlayers.forEach(function(player, i) {
|
||||
var name = player == this.me ? "You" : "Player " + (Object.keys(this.players).indexOf(player.id) + 1);
|
||||
lines.push(
|
||||
pad("" + (i + 1) + ".", 2, false) + " " +
|
||||
pad(name, 12, true) +
|
||||
pad("" + player.stats.score, 6, false) +
|
||||
pad("" + player.stats.deaths, 7, false) +
|
||||
pad("" + parseInt(player.stats.health, 10), 7, false)
|
||||
);
|
||||
}, this);
|
||||
|
||||
string += lines.join("\n");
|
||||
|
||||
this.view.toggleInfo(show, string);
|
||||
};
|
||||
|
||||
return GameController;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -71,7 +71,9 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
|
||||
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, {
|
||||
visible: false,
|
||||
pivot: "mb"
|
||||
pivot: "mb",
|
||||
width: 35,
|
||||
height: 40
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +84,11 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
self.headMesh = mesh;
|
||||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
}
|
||||
NotificationCenter.trigger("view/createMesh", texturePath, callback, { pivot: "mb" });
|
||||
NotificationCenter.trigger("view/createMesh", texturePath, callback, {
|
||||
pivot: "mb",
|
||||
width: 10,
|
||||
height: 12
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +136,8 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
this.animatedMeshes[this.actionState],
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO,
|
||||
y: this.body.GetPosition().y * Settings.RATIO
|
||||
y: this.body.GetPosition().y * Settings.RATIO,
|
||||
rotation: this.body.GetAngle()
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
|
||||
NotificationCenter.on("view/fullscreenChange", this.onFullscreenChange, this);
|
||||
NotificationCenter.on("view/toggleDebugMode", this.onToggleDebugMode, this);
|
||||
|
||||
NotificationCenter.on("view/toggleInfo", this.onToggleInfo, this);
|
||||
}
|
||||
|
||||
AbstractView.prototype.isWebGlEnabled = function () {
|
||||
|
|
@ -37,35 +39,35 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
}
|
||||
|
||||
AbstractView.prototype.loadPlayerMesh = function(player) {
|
||||
throw new Exception('Abstract Function loadPlayerMesh not overwritten ');
|
||||
throw new Exception('Abstract Function loadPlayerMesh not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.loadMeshes = function(objects) {
|
||||
throw new Exception('Abstract Function loadMeshes not overwritten ');
|
||||
throw new Exception('Abstract Function loadMeshes not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.render = function () {
|
||||
throw new Exception('Abstract Function render not overwritten ');
|
||||
throw new Exception('Abstract Function render not overwritten');
|
||||
}
|
||||
|
||||
AbstractView.prototype.createMesh = function (texturePath, callback, options) {
|
||||
throw new Exception('Abstract Function createMesh not overwritten ');
|
||||
throw new Exception('Abstract Function createMesh not overwritten');
|
||||
}
|
||||
|
||||
AbstractView.prototype.createAnimatedMesh = function (texturePaths, callback, options) {
|
||||
throw new Exception('Abstract Function createAnimatedMesh not overwritten ');
|
||||
throw new Exception('Abstract Function createAnimatedMesh not overwritten');
|
||||
}
|
||||
|
||||
AbstractView.prototype.addMesh = function(mesh) {
|
||||
throw new Exception('Abstract Function addMesh not overwritten ');
|
||||
throw new Exception('Abstract Function addMesh not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.removeMesh = function(mesh) {
|
||||
throw new Exception('Abstract Function removeMesh not overwritten ');
|
||||
throw new Exception('Abstract Function removeMesh not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.updateMesh = function(mesh, options) {
|
||||
throw new Exception('Abstract Function updateMesh not overwritten ');
|
||||
throw new Exception('Abstract Function updateMesh not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.setMe = function(player) {
|
||||
|
|
@ -73,15 +75,15 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
};
|
||||
|
||||
AbstractView.prototype.addPlayer = function(player) {
|
||||
throw new Exception('Abstract Function addPlayer not overwritten ');
|
||||
throw new Exception('Abstract Function addPlayer not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.removPlayer = function(player) {
|
||||
throw new Exception('Abstract Function removPlayer not overwritten ');
|
||||
throw new Exception('Abstract Function removPlayer not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.setCameraPosition = function (x, y) {
|
||||
throw new Exception('Abstract Function setCameraPosition not overwritten ');
|
||||
throw new Exception('Abstract Function setCameraPosition not overwritten');
|
||||
}
|
||||
|
||||
AbstractView.prototype.calculateCameraPosition = function() {
|
||||
|
|
@ -101,7 +103,7 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
};
|
||||
|
||||
AbstractView.prototype.setCameraZoom = function (z) {
|
||||
throw new Exception('Abstract Function setCameraZoom not overwritten ');
|
||||
throw new Exception('Abstract Function setCameraZoom not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onFullscreenChange = function(isFullScreen) {
|
||||
|
|
@ -125,5 +127,9 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
this.debugMode = debugMode;
|
||||
};
|
||||
|
||||
AbstractView.prototype.toggleInfo = function(show, string) {
|
||||
throw new Exception('Abstract Function showInfo not overwritten');
|
||||
};
|
||||
|
||||
return AbstractView;
|
||||
});
|
||||
|
|
@ -16,6 +16,9 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
this.camera = null;
|
||||
this.stage = null;
|
||||
this.container = null;
|
||||
this.infoContainer = null;
|
||||
this.infoFilters = [];
|
||||
this.infoBox = null;
|
||||
this.init();
|
||||
this.pixi = PIXI;
|
||||
}
|
||||
|
|
@ -35,21 +38,40 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
this.stage = new PIXI.Stage(0x333333);
|
||||
|
||||
this.initCamera();
|
||||
|
||||
/*
|
||||
var blurFilter = new PIXI.BlurFilter();
|
||||
blurFilter.blurX = 12;
|
||||
blurFilter.blurY = 0;
|
||||
var grayFilter = new PIXI.GrayFilter();
|
||||
grayFilter.gray = .6;
|
||||
this.stage.filters = [grayFilter];
|
||||
*/
|
||||
this.initInfo();
|
||||
|
||||
this.setCanvas(this.renderer.view);
|
||||
}
|
||||
|
||||
|
||||
PixiView.prototype.initCamera = function () {
|
||||
this.container = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.container);
|
||||
}
|
||||
|
||||
PixiView.prototype.initInfo = function() {
|
||||
this.infoContainer = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.infoContainer);
|
||||
|
||||
var blurFilter = new PIXI.BlurFilter();
|
||||
blurFilter.blurX = 12;
|
||||
blurFilter.blurY = 12;
|
||||
var grayFilter = new PIXI.GrayFilter();
|
||||
grayFilter.gray = 0.85;
|
||||
this.infoFilters = [blurFilter, grayFilter];
|
||||
|
||||
this.infoText = new PIXI.Text("", {font: "normal 20px monospace", fill: "red", align: "center"});
|
||||
this.infoBox = new PIXI.Graphics();
|
||||
this.infoBox.alpha = 0.7;
|
||||
|
||||
this.infoContainer.addChild(this.infoBox);
|
||||
this.infoContainer.addChild(this.infoText);
|
||||
|
||||
this.infoContainer.visible = false;
|
||||
};
|
||||
|
||||
PixiView.prototype.render = function () {
|
||||
if(this.me) {
|
||||
if(this.me && this.me.isSpawned) {
|
||||
var pos = this.calculateCameraPosition();
|
||||
this.setCameraPosition(pos.x, pos.y);
|
||||
}
|
||||
|
|
@ -79,11 +101,15 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
var textures = [];
|
||||
for (var i = 0; i < texturePaths.length; i++) {
|
||||
var texture = PIXI.Texture.fromImage(texturePaths[i]);
|
||||
texture.width = options.width;
|
||||
texture.height = options.height;
|
||||
PIXI.texturesToUpdate.push(texture);
|
||||
textures.push(texture);
|
||||
}
|
||||
|
||||
var mesh = new PIXI.MovieClip(textures);
|
||||
if(options) this.updateMesh(mesh, options);
|
||||
|
||||
mesh.animationSpeed = 0.5;
|
||||
|
||||
mesh.play();
|
||||
|
|
@ -117,12 +143,6 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
};
|
||||
}
|
||||
|
||||
PixiView.prototype.initCamera = function () {
|
||||
|
||||
this.container = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.container);
|
||||
}
|
||||
|
||||
PixiView.prototype.calculateCameraPosition = function() {
|
||||
var zoom = this.container.scale.x;
|
||||
|
||||
|
|
@ -161,5 +181,35 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
}
|
||||
};
|
||||
|
||||
PixiView.prototype.toggleInfo = function(show, string) {
|
||||
if(show) {
|
||||
this.infoText.setText(string);
|
||||
this.infoText.updateText();
|
||||
this.infoText.dirty = false;
|
||||
|
||||
var x = Settings.STAGE_WIDTH / 2 - this.infoText.width / 2,
|
||||
y = Settings.STAGE_HEIGHT / 2 - this.infoText.height / 2;
|
||||
this.infoText.position = new PIXI.Point(x, y);
|
||||
|
||||
var borderWidth = 3;
|
||||
var padding = 20;
|
||||
this.infoBox.clear();
|
||||
this.infoBox.beginFill(0x000000);
|
||||
this.infoBox.lineStyle(borderWidth, 0xAA0000);
|
||||
this.infoBox.drawRect(0, 0, this.infoText.width - borderWidth + 2 * padding * 2, this.infoText.height - borderWidth + 2 * padding);
|
||||
this.infoBox.endFill();
|
||||
this.infoBox.position.x = this.infoText.position.x + borderWidth/2 - padding * 2;
|
||||
this.infoBox.position.y = this.infoText.position.y + borderWidth/2 - padding;
|
||||
|
||||
this.infoContainer.visible = true;
|
||||
this.container.filters = this.infoFilters;
|
||||
this.infoFilters.forEach(function(filter) { filter.dirty = true; });
|
||||
} else {
|
||||
this.infoText.setText("...");
|
||||
this.infoContainer.visible = false;
|
||||
this.container.filters = null;
|
||||
}
|
||||
};
|
||||
|
||||
return PixiView;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue