mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
merge
This commit is contained in:
commit
0405910c7a
49 changed files with 32827 additions and 126 deletions
|
|
@ -25,6 +25,7 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
|
||||
f:70,
|
||||
g:71,
|
||||
k:75,
|
||||
|
||||
up: 38,
|
||||
left: 37,
|
||||
|
|
@ -49,14 +50,16 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
this.keyboardInput.registerKey(keys.d, 'moveRight', 'stop');
|
||||
this.keyboardInput.registerKey(keys.right, 'moveRight', 'stop');
|
||||
|
||||
this.keyboardInput.registerKey(keys.w, 'jump');
|
||||
this.keyboardInput.registerKey(keys.up, 'jump');
|
||||
this.keyboardInput.registerKey(keys.space, 'jump');
|
||||
this.keyboardInput.registerKey(keys.w, 'jump', 'jumpStop');
|
||||
this.keyboardInput.registerKey(keys.up, 'jump', 'jumpStop');
|
||||
this.keyboardInput.registerKey(keys.space, 'jump', 'jumpStop');
|
||||
|
||||
this.keyboardInput.registerKey(keys.tab, 'showInfo', 'hideInfo');
|
||||
|
||||
this.keyboardInput.registerKey(keys.f, 'handActionLeft');
|
||||
this.keyboardInput.registerKey(keys.g, 'handActionRight');
|
||||
|
||||
this.keyboardInput.registerKey(keys.k, 'suicide');
|
||||
}
|
||||
|
||||
PlayerController.prototype.moveLeft = function () {
|
||||
|
|
@ -79,6 +82,11 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
NotificationCenter.trigger('sendGameCommand', 'jump');
|
||||
}
|
||||
|
||||
PlayerController.prototype.jumpStop = function () {
|
||||
Parent.prototype.jumpStop.call(this);
|
||||
NotificationCenter.trigger('sendGameCommand', 'jumpStop');
|
||||
}
|
||||
|
||||
PlayerController.prototype.setXY = function(x, y) {
|
||||
var options = {x:x, y:y};
|
||||
Parent.prototype.lookAt.call(this, options);
|
||||
|
|
@ -93,6 +101,10 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
this.handActionRequest(0.5, 0.5);
|
||||
};
|
||||
|
||||
PlayerController.prototype.suicide = function() {
|
||||
NotificationCenter.trigger("sendGameCommand", "suicide");
|
||||
};
|
||||
|
||||
PlayerController.prototype.handActionRequest = function(x, y) {
|
||||
var options = {x:x, y:y};
|
||||
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
|
||||
GameController.prototype = Object.create(Parent.prototype);
|
||||
|
||||
|
||||
GameController.prototype.destruct = function() {
|
||||
//destroy box2d world etc.
|
||||
};
|
||||
|
|
@ -35,6 +34,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
}
|
||||
|
||||
GameController.prototype.update = function () {
|
||||
|
||||
Parent.prototype.update.call(this);
|
||||
|
||||
DomController.statsBegin();
|
||||
|
||||
requestAnimFrame(this.update.bind(this));
|
||||
|
|
@ -111,7 +113,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
|
||||
var player = this.players[playerId];
|
||||
player.spawn(x, y);
|
||||
this.gameObjects.animated.push(player.getDoll());
|
||||
this.gameObjects.animated.push(player);
|
||||
|
||||
if(options.holdingItemUid) {
|
||||
this.onHandActionResponse({
|
||||
|
|
@ -148,7 +150,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
|
||||
GameController.prototype.onUpdateStats = function(options) {
|
||||
var player = this.players[options.playerId];
|
||||
player.stats = options.stats;
|
||||
player.setStats(options.stats);
|
||||
|
||||
// FIXME: move to canvas later
|
||||
if(player == this.me) {
|
||||
|
|
@ -156,23 +158,32 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
}
|
||||
};
|
||||
|
||||
GameController.prototype.onPlayerKill = function(playerId) {
|
||||
GameController.prototype.onPlayerKill = function(options) {
|
||||
var player = this.players[options.playerId];
|
||||
player.kill();
|
||||
var killedByPlayer = this.players[options.killedByPlayerId];
|
||||
player.kill(killedByPlayer);
|
||||
};
|
||||
|
||||
GameController.prototype.onRemoveGameObject = function(options) {
|
||||
var object = null;
|
||||
for (var i = 0; i < this.gameObjects[options.type].length; i++) {
|
||||
if(this.gameObjects[options.type][i].uid == options.uid) {
|
||||
object = this.gameObjects[options.type][i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(object) {
|
||||
this.onGameObjectRemove(options.type, object);
|
||||
object.destroy();
|
||||
} else {
|
||||
console.warn("GameObject for removal can not be found locally. " + options.uid);
|
||||
}
|
||||
};
|
||||
|
||||
GameController.prototype.loadLevel = function (path) {
|
||||
Parent.prototype.loadLevel.call(this, path);
|
||||
}
|
||||
|
||||
GameController.prototype.userLeft = function(user) {
|
||||
var doll = this.players[user.id].doll;
|
||||
var i = this.gameObjects.animated.indexOf(doll);
|
||||
if(i>=0) this.gameObjects.animated.splice(i, 1);
|
||||
|
||||
Parent.prototype.userLeft.call(this, user);
|
||||
}
|
||||
|
||||
GameController.prototype.toggleInfo = function(show) {
|
||||
|
||||
var playersArray = [];
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
|
|||
+ this.characterName + '/';
|
||||
|
||||
var callback = function(mesh) {
|
||||
console.log(name, self.baseMeshName)
|
||||
if(name == self.baseMeshName) {
|
||||
self.mesh = mesh;
|
||||
} else {
|
||||
|
|
@ -97,8 +96,14 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
|
|||
);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
RagDoll.prototype.destroy = function() {
|
||||
for (var name in this.limbMeshes) {
|
||||
NotificationCenter.trigger("view/removeMesh", this.limbMeshes[name]);
|
||||
};
|
||||
|
||||
Parent.prototype.destroy.call(this);
|
||||
};
|
||||
|
||||
return RagDoll;
|
||||
|
|
|
|||
21
app/Game/Client/GameObjects/SpectatorDoll.js
Normal file
21
app/Game/Client/GameObjects/SpectatorDoll.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/SpectatorDoll"
|
||||
],
|
||||
|
||||
function (Parent) {
|
||||
|
||||
function SpectatorDoll(physicsEngine, uid) {
|
||||
Parent.call(this, physicsEngine, uid);
|
||||
}
|
||||
|
||||
SpectatorDoll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
SpectatorDoll.prototype.render = function() {
|
||||
// warning is not being called yet!
|
||||
}
|
||||
|
||||
SpectatorDoll.prototype.createMesh = function() {
|
||||
}
|
||||
|
||||
return SpectatorDoll;
|
||||
});
|
||||
|
|
@ -1,9 +1,111 @@
|
|||
define([
|
||||
"Game/Core/Player"
|
||||
"Game/Core/Player",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
function (Parent, NotificationCenter, Settings) {
|
||||
|
||||
return Parent;
|
||||
function Player(id, physicsEngine) {
|
||||
Parent.call(this, id, physicsEngine);
|
||||
|
||||
this.playerInfoView = null;
|
||||
this.playerInfoViewVisibleTimeout = null;
|
||||
this.playerInfoViewVisible = false;
|
||||
this.initHealthBar();
|
||||
}
|
||||
|
||||
Player.prototype = Object.create(Parent.prototype);
|
||||
|
||||
});
|
||||
Player.prototype.setStats = function(stats) {
|
||||
var oldHealth = this.stats.health;
|
||||
this.stats = stats;
|
||||
|
||||
if(oldHealth != this.stats.health) {
|
||||
this.onHealthChange();
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.initHealthBar = function() {
|
||||
var self = this;
|
||||
|
||||
this.playerInfoViewVisible = false;
|
||||
|
||||
var options = {
|
||||
x: 100,
|
||||
y: 100,
|
||||
healthFactor: this.stats.health / 100,
|
||||
visible: this.playerInfoViewVisible
|
||||
};
|
||||
|
||||
var callback = function(playerInfoView) {
|
||||
self.playerInfoView = playerInfoView;
|
||||
}
|
||||
NotificationCenter.trigger("view/createAndAddPlayerInfo", callback, options);
|
||||
};
|
||||
|
||||
Player.prototype.onHealthChange = function() {
|
||||
if(this.stats.health != 100) {
|
||||
this.setPlayerInfoVisible(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Player.prototype.kill = function(killedByPlayer) {
|
||||
Parent.prototype.kill.call(this, killedByPlayer);
|
||||
};
|
||||
|
||||
Player.prototype.spawn = function(x, y) {
|
||||
Parent.prototype.spawn.call(this, x, y);
|
||||
this.setPlayerInfoVisible(false);
|
||||
};
|
||||
|
||||
Player.prototype.setPlayerInfoVisible = function(visible) {
|
||||
var self = this;
|
||||
this.playerInfoViewVisible = visible;
|
||||
if(this.playerInfoViewVisibleTimeout) clearTimeout(this.playerInfoViewVisibleTimeout);
|
||||
|
||||
if(visible) {
|
||||
var position = this.getPosition();
|
||||
|
||||
var options = {
|
||||
x: position.x * Settings.RATIO,
|
||||
y: position.y * Settings.RATIO,
|
||||
healthFactor: this.stats.health / 100,
|
||||
visible: this.playerInfoViewVisible
|
||||
};
|
||||
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, options);
|
||||
|
||||
this.playerInfoViewVisibleTimeout = setTimeout(function() {
|
||||
self.playerInfoViewVisible = false;
|
||||
NotificationCenter.trigger("view/updatePlayerInfo", self.playerInfoView, {visible: self.playerInfoViewVisible});
|
||||
}, Settings.HEALTH_DISPLAY_TIME * 1000);
|
||||
|
||||
} else {
|
||||
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, {visible: this.playerInfoViewVisible});
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.render = function() {
|
||||
|
||||
// dolls are self responsible
|
||||
|
||||
if(this.playerInfoViewVisible) {
|
||||
var position = this.getPosition();
|
||||
var options = {
|
||||
healthFactor: this.stats.health / 100,
|
||||
x: position.x * Settings.RATIO,
|
||||
y: position.y * Settings.RATIO,
|
||||
}
|
||||
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, options);
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.destroy = function() {
|
||||
Parent.prototype.destroy.call(this);
|
||||
NotificationCenter.trigger("view/removePlayerInfo", this.playerInfoView);
|
||||
};
|
||||
|
||||
return Player;
|
||||
|
||||
});
|
||||
|
|
@ -22,6 +22,10 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
NotificationCenter.on("view/toggleDebugMode", this.onToggleDebugMode, this);
|
||||
|
||||
NotificationCenter.on("view/toggleInfo", this.onToggleInfo, this);
|
||||
|
||||
NotificationCenter.on("view/createAndAddPlayerInfo", this.onCreateAndAddPlayerInfo, this);
|
||||
NotificationCenter.on("view/updatePlayerInfo", this.onUpdatePlayerInfo, this);
|
||||
NotificationCenter.on("view/removePlayerInfo", this.onRemovePlayerInfo, this);
|
||||
}
|
||||
|
||||
AbstractView.prototype.isWebGlEnabled = function () {
|
||||
|
|
@ -131,5 +135,17 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
throw new Exception('Abstract Function showInfo not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onCreateAndAddPlayerInfo = function(options) {
|
||||
throw new Exception('Abstract Function onCreateAndAddPlayerInfo not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
|
||||
throw new Exception('Abstract Function onUpdatePlayerInfo not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onRemovePlayerInfo = function(playerInfo) {
|
||||
throw new Exception('Abstract Function onRemovePlayerInfo not overwritten');
|
||||
};
|
||||
|
||||
return AbstractView;
|
||||
});
|
||||
|
|
@ -32,7 +32,7 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
console.log('WebGLRenderer')
|
||||
} else {
|
||||
this.renderer = new PIXI.CanvasRenderer(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
|
||||
console.log('CanvasRenderer')
|
||||
console.log('CanvasRenderer - not using WebGL!')
|
||||
}
|
||||
|
||||
this.stage = new PIXI.Stage(0x333333);
|
||||
|
|
@ -43,35 +43,8 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
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 && this.me.isSpawned) {
|
||||
if(this.me) {
|
||||
var pos = this.calculateCameraPosition();
|
||||
this.setCameraPosition(pos.x, pos.y);
|
||||
}
|
||||
|
|
@ -79,6 +52,8 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
this.renderer.render(this.stage);
|
||||
}
|
||||
|
||||
// Meshes
|
||||
|
||||
PixiView.prototype.addMesh = function(mesh) {
|
||||
this.container.addChild(mesh);
|
||||
};
|
||||
|
|
@ -89,9 +64,10 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
|
||||
PixiView.prototype.createMesh = function (texturePath, callback, options) {
|
||||
|
||||
var texture = PIXI.Texture.fromImage(texturePath);
|
||||
var texture = PIXI.Texture.fromImage(texturePath, false, PIXI.BaseTexture.SCALE_MODE.NEAREST);
|
||||
|
||||
var mesh = new PIXI.Sprite(texture);
|
||||
|
||||
if(options) this.updateMesh(mesh, options);
|
||||
|
||||
callback(mesh);
|
||||
|
|
@ -129,6 +105,13 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
if (options.pivot) mesh.pivot = new PIXI.Point(options.pivot.x, options.pivot.y);
|
||||
}
|
||||
|
||||
// Camera
|
||||
|
||||
PixiView.prototype.initCamera = function () {
|
||||
this.container = new PIXI.DisplayObjectContainer();
|
||||
this.stage.addChild(this.container);
|
||||
}
|
||||
|
||||
PixiView.prototype.calculateCameraPosition = function() {
|
||||
var zoom = this.container.scale.x;
|
||||
|
||||
|
|
@ -167,6 +150,29 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
}
|
||||
};
|
||||
|
||||
// Info Overlay
|
||||
|
||||
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.toggleInfo = function(show, string) {
|
||||
if(show) {
|
||||
this.infoText.setText(string);
|
||||
|
|
@ -197,5 +203,47 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
}
|
||||
};
|
||||
|
||||
// Player Info
|
||||
|
||||
PixiView.prototype.onCreateAndAddPlayerInfo = function(callback, options) {
|
||||
var playerInfo = new PIXI.Graphics();
|
||||
this.container.addChild(playerInfo);
|
||||
|
||||
this.onUpdatePlayerInfo(playerInfo, options);
|
||||
|
||||
callback(playerInfo);
|
||||
};
|
||||
|
||||
PixiView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
|
||||
var width = 14,
|
||||
height = 2,
|
||||
borderWidth = 1,
|
||||
offsetX = -8,
|
||||
offsetY = -52;
|
||||
|
||||
if(typeof options.healthFactor != 'undefined') {
|
||||
playerInfo.clear();
|
||||
|
||||
playerInfo.beginFill(0x000000);
|
||||
playerInfo.lineStyle(borderWidth, 0x000000);
|
||||
playerInfo.drawRect(0, 0, width, height);
|
||||
playerInfo.endFill();
|
||||
|
||||
if(options.healthFactor > 0) {
|
||||
playerInfo.beginFill(0x00FF00);
|
||||
playerInfo.lineStyle(0, 0x000000);
|
||||
playerInfo.drawRect(borderWidth, borderWidth, width * options.healthFactor, height);
|
||||
playerInfo.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
if (options.x && options.y) playerInfo.position = new PIXI.Point(offsetX + options.x, offsetY + options.y);
|
||||
if (options.visible === true || options.visible === false) playerInfo.visible = options.visible;
|
||||
};
|
||||
|
||||
PixiView.prototype.onRemovePlayerInfo = function(playerInfo) {
|
||||
this.container.removeChild(playerInfo);
|
||||
};
|
||||
|
||||
return PixiView;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue