implemented clientReady and changed loading of assets, fixed unique ragdoll id
|
|
@ -56,6 +56,21 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
DomController.statsEnd();
|
||||
}
|
||||
|
||||
GameController.prototype.onClientReadyResponse = function(options) {
|
||||
|
||||
if (options.spawnedPlayers) {
|
||||
for(var i = 0; i < options.spawnedPlayers.length; i++) {
|
||||
this.onSpawnPlayer(options.spawnedPlayers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.worldUpdate) {
|
||||
this.onWorldUpdate(options.worldUpdate);
|
||||
}
|
||||
|
||||
this.createMe(options.userId);
|
||||
};
|
||||
|
||||
GameController.prototype.onWorldUpdate = function (updateData) {
|
||||
|
||||
var body = this.physicsEngine.world.GetBodyList();
|
||||
|
|
@ -66,7 +81,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
if(updateData[gameObject.uid]) {
|
||||
var update = updateData[gameObject.uid];
|
||||
body.SetAwake(true);
|
||||
body.SetPosition(this.centerBetween(update.p, body.GetPosition()));
|
||||
body.SetPosition(update.p);
|
||||
body.SetAngle(update.a);
|
||||
body.SetLinearVelocity(update.lv);
|
||||
body.SetAngularVelocity(update.av);
|
||||
|
|
@ -82,25 +97,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
|
||||
}
|
||||
|
||||
GameController.prototype.centerBetween = function(n, o) {
|
||||
var x, y;
|
||||
|
||||
if(n.x > o.x) {
|
||||
x = o.x + (n.x - o.x) / 2;
|
||||
} else {
|
||||
x = o.x - (o.x - n.x) / 2;
|
||||
}
|
||||
|
||||
if(n.y > o.y) {
|
||||
y = o.y + (n.y - o.y) / 2;
|
||||
} else {
|
||||
y = o.y - (o.y - n.y) / 2;
|
||||
}
|
||||
|
||||
return {x:x, y:y};
|
||||
};
|
||||
|
||||
GameController.prototype.onJoinMe = function (playerId) {
|
||||
GameController.prototype.createMe = function (playerId) {
|
||||
this.me = this.players[playerId];
|
||||
this.me.setPlayerController(new PlayerController(this.me));
|
||||
this.view.setMe(this.me);
|
||||
|
|
@ -161,7 +158,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
|
|||
GameController.prototype.onPlayerKill = function(options) {
|
||||
var player = this.players[options.playerId];
|
||||
var killedByPlayer = this.players[options.killedByPlayerId];
|
||||
player.kill(killedByPlayer);
|
||||
player.kill(killedByPlayer, options.ragDollId);
|
||||
};
|
||||
|
||||
GameController.prototype.onRemoveGameObject = function(options) {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,14 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
|
||||
var texturePaths = [];
|
||||
for (var i = start; i <= end; i++) {
|
||||
texturePaths.push(Settings.GRAPHICS_PATH + "Animation/WithArms/ChuckAnimations0" + padF(i) + ".png");
|
||||
texturePaths.push(
|
||||
Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||
+ this.characterName
|
||||
+ "/Animation/WithArms/ChuckAnimations0"
|
||||
+ padF(i)
|
||||
+ ".png"
|
||||
);
|
||||
}
|
||||
|
||||
var callback = function(mesh) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
define([
|
||||
"Game/Core/Loader/Level",
|
||||
"Game/Config/Settings"
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Vendor/Pixi"
|
||||
],
|
||||
|
||||
function (Parent, Settings) {
|
||||
function (Parent, Settings, NotificationCenter, PIXI) {
|
||||
|
||||
function Level (uid, engine, gameObjects) {
|
||||
Parent.call(this, uid, engine, gameObjects);
|
||||
|
|
@ -12,12 +14,12 @@ function (Parent, Settings) {
|
|||
Level.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Level.prototype.loadLevelDataFromPath = function (path, callback) {
|
||||
|
||||
var self = this;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState == 4) {
|
||||
if(xhr.status == 200) {
|
||||
callback(JSON.parse(xhr.responseText))
|
||||
self.loadAssets(JSON.parse(xhr.responseText), callback);
|
||||
} else {
|
||||
console.error("Ajax error: " + xhr.status + " " + xhr.statusText)
|
||||
}
|
||||
|
|
@ -27,5 +29,62 @@ function (Parent, Settings) {
|
|||
xhr.send(null);
|
||||
}
|
||||
|
||||
Level.prototype.loadAssets = function(levelData, callback) {
|
||||
|
||||
var paths = this.getAssetPaths(levelData);
|
||||
|
||||
var count = 0;
|
||||
var numPaths = paths.length;
|
||||
var loader = new PIXI.AssetLoader(paths);
|
||||
loader.onComplete = function() { callback(levelData); };
|
||||
loader.onProgress = function() {
|
||||
var progress = parseInt(100 / numPaths * ++count, 10) + 1;
|
||||
NotificationCenter.trigger("view/updateLoader", progress);
|
||||
}
|
||||
loader.load();
|
||||
};
|
||||
|
||||
Level.prototype.getAssetPaths = function(levelData) {
|
||||
|
||||
var paths = [];
|
||||
|
||||
// Get chuck
|
||||
var padF = function(n) {
|
||||
if(n<10) return "00" + n;
|
||||
if(n<100) return "0" + n;
|
||||
return n;
|
||||
}
|
||||
|
||||
var characterNames = ["Chuck"];
|
||||
var animationSets = ["WithArms"]; // FIXME add WithoutArms
|
||||
for (var i = 0; i < characterNames.length; i++) {
|
||||
var characterName = characterNames[i];
|
||||
for (var j = 1; j <= 126; j++) {
|
||||
for (var k = 0; k < animationSets.length; k++) {
|
||||
var animationSet = animationSets[k];
|
||||
paths.push(
|
||||
Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||
+ characterName
|
||||
+ "/Animation/"
|
||||
+ animationSet
|
||||
+ "/ChuckAnimations0"
|
||||
+ padF(j)
|
||||
+ ".png"
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
paths.push(
|
||||
Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||
+ characterName
|
||||
+ "/head.png"
|
||||
);
|
||||
|
||||
return paths;
|
||||
};
|
||||
|
||||
return Level;
|
||||
});
|
||||
|
|
@ -1,9 +1,50 @@
|
|||
define([
|
||||
"Game/Core/Loader/TiledLevel"
|
||||
"Game/Core/Loader/TiledLevel",
|
||||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function (Parent) {
|
||||
function (Parent, Settings) {
|
||||
|
||||
return Parent;
|
||||
function TiledLevel(uid, engine, gameObjects) {
|
||||
Parent.call(this, uid, engine, gameObjects);
|
||||
}
|
||||
|
||||
TiledLevel.prototype = Object.create(Parent.prototype);
|
||||
|
||||
TiledLevel.prototype.getAssetPaths = function(levelData) {
|
||||
var paths = Parent.prototype.getAssetPaths.call(this, levelData);
|
||||
|
||||
// Get tiles images
|
||||
for (var i = 0; i < levelData.tilesets.length; i++) {
|
||||
var tileset = levelData.tilesets[i];
|
||||
for (var key in tileset.tiles) {
|
||||
var imagePpath = tileset.tiles[key].image;
|
||||
if(imagePpath) {
|
||||
paths.push(Settings.MAPS_PATH + imagePpath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Get items images
|
||||
var objects = this.getLayer(levelData, "items").objects;
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
var object = objects[i];
|
||||
var options = object.properties;
|
||||
|
||||
var texturePath = Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_ITEMS
|
||||
+ options.category + '/'
|
||||
+ options.image;
|
||||
|
||||
paths.push(texturePath);
|
||||
};
|
||||
|
||||
// FIXME: Get background image
|
||||
|
||||
return paths;
|
||||
|
||||
}
|
||||
|
||||
return TiledLevel;
|
||||
|
||||
});
|
||||
|
|
@ -13,6 +13,7 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
|
|||
this.socketLink = socketLink;
|
||||
this.gameController = null;
|
||||
this.users = {};
|
||||
this.userId = null;
|
||||
|
||||
this.socketLink.on('connect', this.onConnect.bind(this));
|
||||
this.socketLink.on('disconnect', this.onDisconnect.bind(this));
|
||||
|
|
@ -26,6 +27,7 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
|
|||
});
|
||||
|
||||
NotificationCenter.on("sendGameCommand", this.sendGameCommand, this);
|
||||
NotificationCenter.on("game/level/loaded", this.onLevelLoaded, this);
|
||||
}
|
||||
|
||||
// Socket callbacks
|
||||
|
|
@ -43,15 +45,12 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
|
|||
}
|
||||
|
||||
Networker.prototype.onJoinSuccess = function (options) {
|
||||
NotificationCenter.on("game/level/loaded", function() {
|
||||
this.onLevelLoaded(options);
|
||||
}, this);
|
||||
this.userId = options.userId;
|
||||
|
||||
this.gameController = new GameController();
|
||||
this.gameController.loadLevel(options.levelUid);
|
||||
|
||||
this.onUserJoined(options.userId);
|
||||
this.gameController.onJoinMe(options.userId);
|
||||
|
||||
if (options.joinedUsers) {
|
||||
for(var i = 0; i < options.joinedUsers.length; i++) {
|
||||
|
|
@ -62,20 +61,15 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
|
|||
this.initPing();
|
||||
}
|
||||
|
||||
Networker.prototype.onLevelLoaded = function(options) {
|
||||
if (options.spawnedPlayers) {
|
||||
for(var i = 0; i < options.spawnedPlayers.length; i++) {
|
||||
this.gameController.onSpawnPlayer(options.spawnedPlayers[i]);
|
||||
}
|
||||
Networker.prototype.onLevelLoaded = function() {
|
||||
for (var userId in this.users) {
|
||||
this.gameController.createPlayer(this.users[userId]);
|
||||
}
|
||||
|
||||
if (options.worldUpdate) {
|
||||
this.gameController.onWorldUpdate(options.worldUpdate);
|
||||
}
|
||||
this.sendGameCommand("clientReady");
|
||||
};
|
||||
|
||||
Networker.prototype.initPing = function() {
|
||||
|
||||
this.ping();
|
||||
};
|
||||
|
||||
|
|
@ -86,6 +80,7 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
|
|||
|
||||
// Sending commands
|
||||
|
||||
// Remember: control commands are coordinator relevant commands
|
||||
Networker.prototype.sendCommand = function (command, options) {
|
||||
var message = ProtocolHelper.encodeCommand(command, options);
|
||||
this.socketLink.send(message);
|
||||
|
|
@ -105,12 +100,18 @@ function (ProtocolHelper, GameController, User, NotificationCenter, Settings, Do
|
|||
Networker.prototype.onUserJoined = function (userId) {
|
||||
var user = new User(userId);
|
||||
this.users[userId] = user;
|
||||
this.gameController.userJoined(user);
|
||||
|
||||
if (this.gameController
|
||||
&& this.gameController.level
|
||||
&& this.gameController.level.isLoaded) {
|
||||
|
||||
this.gameController.createPlayer(user);
|
||||
};
|
||||
}
|
||||
|
||||
Networker.prototype.onUserLeft = function (userId) {
|
||||
var user = this.users[userId];
|
||||
this.gameController.userLeft(user);
|
||||
this.gameController.onUserLeft(user);
|
||||
delete this.users[userId];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,6 @@ function (Parent, NotificationCenter, Settings) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
NotificationCenter.on("view/createAndAddPlayerInfo", this.onCreateAndAddPlayerInfo, this);
|
||||
NotificationCenter.on("view/updatePlayerInfo", this.onUpdatePlayerInfo, this);
|
||||
NotificationCenter.on("view/removePlayerInfo", this.onRemovePlayerInfo, this);
|
||||
|
||||
NotificationCenter.on("view/updateLoader", this.onUpdateLoader, this);
|
||||
}
|
||||
|
||||
AbstractView.prototype.isWebGlEnabled = function () {
|
||||
|
|
@ -147,5 +149,9 @@ function (DomController, Settings, Exception, NotificationCenter) {
|
|||
throw new Exception('Abstract Function onRemovePlayerInfo not overwritten');
|
||||
};
|
||||
|
||||
AbstractView.prototype.onUpdateLoader = function(progress) {
|
||||
throw new Exception('Abstract Function onUpdateLoader not overwritten');
|
||||
};
|
||||
|
||||
return AbstractView;
|
||||
});
|
||||
|
|
@ -19,6 +19,7 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
this.infoContainer = null;
|
||||
this.infoFilters = [];
|
||||
this.infoBox = null;
|
||||
this.loader = null;
|
||||
this.init();
|
||||
this.pixi = PIXI;
|
||||
}
|
||||
|
|
@ -39,6 +40,7 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
|
||||
this.initCamera();
|
||||
this.initInfo();
|
||||
this.initLoader();
|
||||
|
||||
this.setCanvas(this.renderer.view);
|
||||
}
|
||||
|
|
@ -247,5 +249,41 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
this.container.removeChild(playerInfo);
|
||||
};
|
||||
|
||||
PixiView.prototype.initLoader = function() {
|
||||
this.loader = new PIXI.Graphics();
|
||||
this.stage.addChild(this.loader);
|
||||
this.onUpdateLoader(0);
|
||||
};
|
||||
|
||||
PixiView.prototype.onUpdateLoader = function(progress) {
|
||||
var width = 200,
|
||||
height = 5,
|
||||
borderWidth = 1;
|
||||
|
||||
if(progress < 100) {
|
||||
this.loader.clear();
|
||||
|
||||
this.loader.beginFill(0x000000);
|
||||
this.loader.lineStyle(borderWidth, 0x000000);
|
||||
this.loader.drawRect(0, 0, width, height);
|
||||
this.loader.endFill();
|
||||
|
||||
if(progress > 0) {
|
||||
var color = 0xFF0FA3;
|
||||
this.loader.beginFill(color);
|
||||
this.loader.lineStyle(0, 0x000000);
|
||||
this.loader.drawRect(borderWidth, borderWidth, width * progress / 100, height);
|
||||
this.loader.endFill();
|
||||
}
|
||||
|
||||
this.loader.position = new PIXI.Point(
|
||||
Settings.STAGE_WIDTH / 2 - width / 2 - borderWidth,
|
||||
Settings.STAGE_HEIGHT / 2 - height / 2 - borderWidth
|
||||
);
|
||||
}
|
||||
|
||||
this.loader.visible = progress < 100;
|
||||
};
|
||||
|
||||
return PixiView;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
|
|||
|
||||
NotificationCenter.on("game/object/add", this.onGameObjectAdd, this);
|
||||
NotificationCenter.on("game/object/remove", this.onGameObjectRemove, this);
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
GameController.prototype.update = function() {
|
||||
|
|
@ -61,7 +63,7 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
|
|||
};
|
||||
|
||||
GameController.prototype.onLevelLoaded = function() {
|
||||
this.update();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -71,11 +73,13 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
GameController.prototype.userJoined = function (user) {
|
||||
this.players[user.id] = this.createPlayer(user);
|
||||
}
|
||||
*/
|
||||
|
||||
GameController.prototype.userLeft = function (user) {
|
||||
GameController.prototype.onUserLeft = function (user) {
|
||||
var player = this.players[user.id];
|
||||
|
||||
var i = this.gameObjects.animated.indexOf(player);
|
||||
|
|
@ -86,7 +90,9 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
|
|||
}
|
||||
|
||||
GameController.prototype.createPlayer = function(user) {
|
||||
return new Player(user.id, this.physicsEngine);
|
||||
var player = new Player(user.id, this.physicsEngine);
|
||||
this.players[user.id] = player;
|
||||
return player;
|
||||
};
|
||||
|
||||
return GameController;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
|
||||
function Doll (physicsEngine, uid, player) {
|
||||
|
||||
this.characterName = "Chuck";
|
||||
this.player = player;
|
||||
this.height = 43;
|
||||
this.width = 9;
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ function (Parent, Box2D, Options, Settings) {
|
|||
|
||||
var vector = new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE / this.options.weight,
|
||||
-y * Settings.MAX_THROW_FORCE * 1.5 / this.options.weight // 1.5 is to throw higher then far
|
||||
-y * Settings.MAX_THROW_FORCE / this.options.weight
|
||||
);
|
||||
this.body.SetLinearVelocity(vector);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ define([
|
|||
throw "Level: Can't create level, nothing found";
|
||||
}
|
||||
|
||||
var collisionLayer = this.getLayer("collision");
|
||||
var collisionLayer = this.getLayer(this.levelData, "collision");
|
||||
|
||||
if(collisionLayer) {
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ define([
|
|||
}
|
||||
|
||||
TiledLevel.prototype.createItems = function() {
|
||||
var objects = this.getLayer("items").objects;
|
||||
var objects = this.getLayer(this.levelData, "items").objects;
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
var object = objects[i];
|
||||
var options = object.properties;
|
||||
|
|
@ -84,7 +84,7 @@ define([
|
|||
return Parent.prototype.getRandomSpawnPoint.call(this);
|
||||
} else {
|
||||
|
||||
var spawnLayer = this.getLayer("spawnpoints");
|
||||
var spawnLayer = this.getLayer(this.levelData, "spawnpoints");
|
||||
|
||||
var size = spawnLayer.objects.length;
|
||||
var object = spawnLayer.objects[parseInt(Math.random() * (size -1), 10)];
|
||||
|
|
@ -97,10 +97,10 @@ define([
|
|||
}
|
||||
};
|
||||
|
||||
TiledLevel.prototype.getLayer = function(name) {
|
||||
for (var i = 0; i < this.levelData.layers.length; i++) {
|
||||
if(this.levelData.layers[i].name === name) {
|
||||
return this.levelData.layers[i];
|
||||
TiledLevel.prototype.getLayer = function(levelData, name) {
|
||||
for (var i = 0; i < levelData.layers.length; i++) {
|
||||
if(levelData.layers[i].name === name) {
|
||||
return levelData.layers[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,11 +26,6 @@ function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll)
|
|||
this.spectatorDoll = new SpectatorDoll(this.physicsEngine, "spectatorDoll-" + this.id, this);
|
||||
}
|
||||
|
||||
Player.prototype.getDoll = function() {
|
||||
throw new Exception('-- PLEASE REMOVE getDoll Calls --');
|
||||
return this.doll;
|
||||
};
|
||||
|
||||
Player.prototype.getActiveDoll = function() {
|
||||
if(this.isSpawned) {
|
||||
return this.doll;
|
||||
|
|
@ -96,7 +91,7 @@ function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll)
|
|||
this.holdingItem = null;
|
||||
};
|
||||
|
||||
Player.prototype.kill = function(killedByPlayer) {
|
||||
Player.prototype.kill = function(killedByPlayer, ragDollId) {
|
||||
if(!this.isSpawned) return false;
|
||||
|
||||
// FIXME: do something better then just respawn in GameController
|
||||
|
|
@ -119,9 +114,9 @@ function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll)
|
|||
height: 12
|
||||
};
|
||||
|
||||
var ragDoll = new RagDoll(this.physicsEngine, "ragDoll-" + this.id, options);
|
||||
var ragDoll = new RagDoll(this.physicsEngine, "ragDoll-" + this.id + "-" + ragDollId, options);
|
||||
ragDoll.setVelocities(this.doll.getVelocities());
|
||||
|
||||
console.log(ragDoll.uid)
|
||||
|
||||
this.isSpawned = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -60,8 +60,6 @@
|
|||
Channel.prototype.sendJoinSuccess = function(userId) {
|
||||
var user = new User(userId, this);
|
||||
var joinedUsers = Object.keys(this.users);
|
||||
var spawnedPlayers = this.gameController.getSpawnedPlayersAndTheirPositions();
|
||||
var worldUpdate = this.gameController.getWorldUpdateObject(true);
|
||||
|
||||
var levelUid = null;
|
||||
if(this.gameController.level) {
|
||||
|
|
@ -74,8 +72,6 @@
|
|||
userId: user.id,
|
||||
channelName: this.name,
|
||||
joinedUsers: joinedUsers,
|
||||
spawnedPlayers: spawnedPlayers,
|
||||
worldUpdate: worldUpdate,
|
||||
levelUid: levelUid
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,10 +19,11 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
Parent.call(this);
|
||||
|
||||
NotificationCenter.on('user/joined', this.userJoined, this);
|
||||
NotificationCenter.on('user/left', this.userLeft, this); // FIXME: refactor this.userLeft -> this.onUserLeft, even in core and client
|
||||
NotificationCenter.on('user/joined', this.onUserJoined, this);
|
||||
NotificationCenter.on('user/left', this.onUserLeft, this); // FIXME: refactor this.userLeft -> this.onUserLeft, even in core and client
|
||||
NotificationCenter.on('user/resetLevel', this.onResetLevel, this);
|
||||
NotificationCenter.on('player/killed', this.spawnPlayer, this);
|
||||
NotificationCenter.on('user/clientReady', this.onClientReady, this);
|
||||
NotificationCenter.on('player/killed', this.onPlayerKilled, this);
|
||||
|
||||
console.checkpoint('starting game controller for channel ' + channel.name);
|
||||
|
||||
|
|
@ -49,13 +50,20 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
this.updateWorld();
|
||||
};
|
||||
|
||||
GameController.prototype.userJoined = function (user) {
|
||||
Parent.prototype.userJoined.call(this, user);
|
||||
var player = this.players[user.id];
|
||||
user.setPlayer(player);
|
||||
this.spawnPlayer(player, 0);
|
||||
GameController.prototype.onUserJoined = function (user) {
|
||||
this.createPlayer(user);
|
||||
}
|
||||
|
||||
GameController.prototype.createPlayer = function(user) {
|
||||
var player = Parent.prototype.createPlayer.call(this, user);
|
||||
player.setPlayerController(new PlayerController(player))
|
||||
user.setPlayer(player);
|
||||
};
|
||||
|
||||
GameController.prototype.onPlayerKilled = function(player, respawnTime) {
|
||||
this.spawnPlayer(player, respawnTime);
|
||||
};
|
||||
|
||||
GameController.prototype.spawnPlayer = function(player, respawnTime) {
|
||||
var self = this;
|
||||
var spawnPoint = this.level.getRandomSpawnPoint();
|
||||
|
|
@ -81,12 +89,14 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
}, respawnTime * 1000);
|
||||
};
|
||||
|
||||
/*
|
||||
GameController.prototype.createPlayer = function(user) {
|
||||
var player = new Player(user.id, this.physicsEngine);
|
||||
player.setPlayerController(new PlayerController(player))
|
||||
|
||||
return player;
|
||||
};
|
||||
*/
|
||||
|
||||
GameController.prototype.updateWorld = function () {
|
||||
|
||||
|
|
@ -154,6 +164,40 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
return spawnedPlayers;
|
||||
};
|
||||
|
||||
GameController.prototype.getAdditionalObjects = function() {
|
||||
var objects = []
|
||||
|
||||
for (var i = 0; i < this.gameObjects.animated.length; i++) {
|
||||
if(this.gameObjects.animated[i] instanceof RagDoll) {
|
||||
var object = this.gameObjects.animated[i];
|
||||
objects.push({
|
||||
uid: objects.uid,
|
||||
options: object.options,
|
||||
x: object.getPosition().x,
|
||||
y: object.getPosition().y
|
||||
});
|
||||
}
|
||||
};
|
||||
var object = {
|
||||
// FIXME: finish it!
|
||||
}
|
||||
|
||||
return objects;
|
||||
};
|
||||
|
||||
GameController.prototype.onClientReady = function(userId) {
|
||||
var player = this.players[userId];
|
||||
this.spawnPlayer(player, 0);
|
||||
|
||||
var options = {
|
||||
spawnedPlayers: this.getSpawnedPlayersAndTheirPositions(),
|
||||
worldUpdate: this.getWorldUpdateObject(true),
|
||||
userId: userId
|
||||
}
|
||||
|
||||
NotificationCenter.trigger('user/' + userId + "/gameCommand", "clientReadyResponse", options);
|
||||
};
|
||||
|
||||
GameController.prototype.onResetLevel = function(userId) {
|
||||
Parent.prototype.onResetLevel.call(this);
|
||||
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", {resetLevel:true});
|
||||
|
|
|
|||
|
|
@ -80,12 +80,15 @@ function (Parent, NotificationCenter) {
|
|||
};
|
||||
|
||||
Player.prototype.kill = function(killedByPlayer) {
|
||||
Parent.prototype.kill.call(this, killedByPlayer);
|
||||
this.stats.deaths++;
|
||||
var ragDollId = this.stats.deaths;
|
||||
Parent.prototype.kill.call(this, killedByPlayer, ragDollId);
|
||||
|
||||
this.broadcastStats();
|
||||
NotificationCenter.trigger("broadcastGameCommand", "playerKill", {
|
||||
playerId: this.id,
|
||||
killedByPlayerId: killedByPlayer.id
|
||||
killedByPlayerId: killedByPlayer.id,
|
||||
ragDollId: ragDollId
|
||||
});
|
||||
|
||||
if(this.ragDoll) {
|
||||
|
|
|
|||
|
|
@ -50,9 +50,12 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
|
|||
|
||||
if(command.hasOwnProperty("resetLevel")) {
|
||||
NotificationCenter.trigger("user/resetLevel", this.id);
|
||||
} else if(command.hasOwnProperty("clientReady")) {
|
||||
NotificationCenter.trigger("user/clientReady", this.id);
|
||||
} else {
|
||||
this.player.playerController.applyCommand(command);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,4 +8,19 @@ function() {
|
|||
return f + this.substr(1);
|
||||
}
|
||||
|
||||
if(GLOBALS.context == "Server") {
|
||||
|
||||
console.checkpoint = function (s) {
|
||||
console.log(' \033[32mbeep - \033[0m' + s);
|
||||
}
|
||||
|
||||
console.warn = function (s) {
|
||||
console.log(' \033[33mwarn - \033[0m' + s);
|
||||
}
|
||||
|
||||
console.error = function (s) {
|
||||
console.log(' \033[31merror - \033[0m' + s);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -38,6 +38,7 @@ function (Parent, ProtocolHelper, NotificationCenter) {
|
|||
|
||||
|
||||
// User command callbacks
|
||||
// Remember: control commands are coordinator relevant commands
|
||||
|
||||
User.prototype.onJoin = function(options) {
|
||||
this.coordinator.assignUserToChannel(this, options);
|
||||
|
|
|
|||
|
|
@ -9,10 +9,6 @@ requirejs.config({
|
|||
|
||||
var inspector = {};
|
||||
|
||||
console.checkpoint = function (s) {
|
||||
console.log(' \033[34mbeep - \033[0m' + s);
|
||||
}
|
||||
|
||||
requirejs([
|
||||
"Game/Server/PipeToLobby"
|
||||
],
|
||||
|
|
|
|||
58
client.js
|
|
@ -18,48 +18,18 @@ requirejs([
|
|||
|
||||
function (Networker, SocketIO, Settings, Exception, PIXI) {
|
||||
|
||||
function loadAssets(callback) {
|
||||
var url = "static/img/paths.txt";
|
||||
var loaded = document.getElementById("loaded");
|
||||
var loading = document.getElementById("loading");
|
||||
var count = 0;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState == 4) {
|
||||
if(xhr.status == 200) {
|
||||
var paths = xhr.responseText.split("\n");
|
||||
var max = paths.length;
|
||||
loader = new PIXI.AssetLoader(paths);
|
||||
loader.onComplete = function() { loading.style.display = "none"; callback(); };
|
||||
loader.onProgress = function() { loaded.style.width = (100 / max * ++count) + "%"; }
|
||||
loader.load();
|
||||
} else {
|
||||
throw new Exception("Assets preloader error: " + xhr.status + " " + xhr.statusText)
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.open("GET", url, true);
|
||||
xhr.send(null);
|
||||
//callback();
|
||||
}
|
||||
|
||||
loadAssets(function() {
|
||||
var options = {
|
||||
"reconnect": false,
|
||||
"reconnection delay": 500,
|
||||
"max reconnection attempts": 10,
|
||||
|
||||
"transports": [
|
||||
"websocket",
|
||||
"flashsocket"
|
||||
],
|
||||
};
|
||||
var socket = SocketIO.connect(location.href, options);
|
||||
var networker = new Networker(socket);
|
||||
inspector.networker = networker;
|
||||
inspector.settings = Settings;
|
||||
inspector.resetLevel = function() { networker.sendGameCommand("resetLevel"); }
|
||||
});
|
||||
|
||||
var options = {
|
||||
"reconnect": false,
|
||||
"reconnection delay": 500,
|
||||
"max reconnection attempts": 10,
|
||||
"transports": [
|
||||
"websocket",
|
||||
"flashsocket"
|
||||
]
|
||||
};
|
||||
var socket = SocketIO.connect(location.href, options);
|
||||
var networker = new Networker(socket);
|
||||
inspector.networker = networker;
|
||||
inspector.settings = Settings;
|
||||
inspector.resetLevel = function() { networker.sendGameCommand("resetLevel"); }
|
||||
});
|
||||
12
server.js
|
|
@ -20,18 +20,6 @@ var options = {
|
|||
logLevel: process.argv[3] || 0
|
||||
};
|
||||
|
||||
console.checkpoint = function (s) {
|
||||
console.log(' \033[32mbeep - \033[0m' + s);
|
||||
}
|
||||
|
||||
console.warn = function (s) {
|
||||
console.log(' \033[33mwarn - \033[0m' + s);
|
||||
}
|
||||
|
||||
console.error = function (s) {
|
||||
console.log(' \033[31merror - \033[0m' + s);
|
||||
}
|
||||
|
||||
requirejs([
|
||||
"Bootstrap/HttpServer",
|
||||
"Bootstrap/Socket",
|
||||
|
|
|
|||
|
|
@ -15,21 +15,6 @@
|
|||
font-family: monospace;
|
||||
}
|
||||
|
||||
#loading {
|
||||
border: 1px solid white;
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#loaded {
|
||||
height: 10px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 1px solid black;
|
||||
background: white;
|
||||
}
|
||||
|
||||
#canvasContainer {
|
||||
/*
|
||||
text-align: center;
|
||||
|
|
@ -70,9 +55,7 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="loading"><p id="loaded"></p></div>
|
||||
<div id="canvasContainer">
|
||||
</div>
|
||||
<div id="canvasContainer"></div>
|
||||
<script data-main="client" src="require.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 749 B After Width: | Height: | Size: 749 B |
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
|
Before Width: | Height: | Size: 1,016 B After Width: | Height: | Size: 1,016 B |
|
Before Width: | Height: | Size: 992 B After Width: | Height: | Size: 992 B |
|
Before Width: | Height: | Size: 924 B After Width: | Height: | Size: 924 B |
|
Before Width: | Height: | Size: 899 B After Width: | Height: | Size: 899 B |
|
Before Width: | Height: | Size: 851 B After Width: | Height: | Size: 851 B |
|
Before Width: | Height: | Size: 787 B After Width: | Height: | Size: 787 B |
|
Before Width: | Height: | Size: 833 B After Width: | Height: | Size: 833 B |
|
Before Width: | Height: | Size: 851 B After Width: | Height: | Size: 851 B |
|
Before Width: | Height: | Size: 872 B After Width: | Height: | Size: 872 B |
|
Before Width: | Height: | Size: 918 B After Width: | Height: | Size: 918 B |
|
Before Width: | Height: | Size: 937 B After Width: | Height: | Size: 937 B |
|
Before Width: | Height: | Size: 980 B After Width: | Height: | Size: 980 B |
|
Before Width: | Height: | Size: 1,003 B After Width: | Height: | Size: 1,003 B |
|
Before Width: | Height: | Size: 1,019 B After Width: | Height: | Size: 1,019 B |
|
Before Width: | Height: | Size: 969 B After Width: | Height: | Size: 969 B |
|
Before Width: | Height: | Size: 952 B After Width: | Height: | Size: 952 B |
|
Before Width: | Height: | Size: 889 B After Width: | Height: | Size: 889 B |
|
Before Width: | Height: | Size: 794 B After Width: | Height: | Size: 794 B |
|
Before Width: | Height: | Size: 800 B After Width: | Height: | Size: 800 B |
|
Before Width: | Height: | Size: 870 B After Width: | Height: | Size: 870 B |
|
Before Width: | Height: | Size: 858 B After Width: | Height: | Size: 858 B |
|
Before Width: | Height: | Size: 875 B After Width: | Height: | Size: 875 B |
|
Before Width: | Height: | Size: 901 B After Width: | Height: | Size: 901 B |
|
Before Width: | Height: | Size: 958 B After Width: | Height: | Size: 958 B |
|
Before Width: | Height: | Size: 947 B After Width: | Height: | Size: 947 B |
|
Before Width: | Height: | Size: 1,022 B After Width: | Height: | Size: 1,022 B |
|
Before Width: | Height: | Size: 1,022 B After Width: | Height: | Size: 1,022 B |
|
Before Width: | Height: | Size: 978 B After Width: | Height: | Size: 978 B |
|
Before Width: | Height: | Size: 953 B After Width: | Height: | Size: 953 B |
|
Before Width: | Height: | Size: 912 B After Width: | Height: | Size: 912 B |
|
Before Width: | Height: | Size: 883 B After Width: | Height: | Size: 883 B |
|
Before Width: | Height: | Size: 837 B After Width: | Height: | Size: 837 B |
|
Before Width: | Height: | Size: 876 B After Width: | Height: | Size: 876 B |
|
Before Width: | Height: | Size: 822 B After Width: | Height: | Size: 822 B |
|
Before Width: | Height: | Size: 847 B After Width: | Height: | Size: 847 B |
|
Before Width: | Height: | Size: 886 B After Width: | Height: | Size: 886 B |
|
Before Width: | Height: | Size: 955 B After Width: | Height: | Size: 955 B |
|
Before Width: | Height: | Size: 995 B After Width: | Height: | Size: 995 B |
|
Before Width: | Height: | Size: 997 B After Width: | Height: | Size: 997 B |
|
Before Width: | Height: | Size: 1,007 B After Width: | Height: | Size: 1,007 B |
|
Before Width: | Height: | Size: 1,001 B After Width: | Height: | Size: 1,001 B |
|
Before Width: | Height: | Size: 919 B After Width: | Height: | Size: 919 B |
|
Before Width: | Height: | Size: 915 B After Width: | Height: | Size: 915 B |
|
Before Width: | Height: | Size: 849 B After Width: | Height: | Size: 849 B |
|
Before Width: | Height: | Size: 795 B After Width: | Height: | Size: 795 B |
|
Before Width: | Height: | Size: 840 B After Width: | Height: | Size: 840 B |
|
Before Width: | Height: | Size: 768 B After Width: | Height: | Size: 768 B |
|
Before Width: | Height: | Size: 851 B After Width: | Height: | Size: 851 B |
|
Before Width: | Height: | Size: 883 B After Width: | Height: | Size: 883 B |
|
Before Width: | Height: | Size: 919 B After Width: | Height: | Size: 919 B |
|
Before Width: | Height: | Size: 986 B After Width: | Height: | Size: 986 B |
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 721 B |
|
Before Width: | Height: | Size: 822 B After Width: | Height: | Size: 822 B |
|
Before Width: | Height: | Size: 838 B After Width: | Height: | Size: 838 B |
|
Before Width: | Height: | Size: 813 B After Width: | Height: | Size: 813 B |
|
Before Width: | Height: | Size: 814 B After Width: | Height: | Size: 814 B |
|
Before Width: | Height: | Size: 854 B After Width: | Height: | Size: 854 B |
|
Before Width: | Height: | Size: 841 B After Width: | Height: | Size: 841 B |
|
Before Width: | Height: | Size: 843 B After Width: | Height: | Size: 843 B |
|
Before Width: | Height: | Size: 827 B After Width: | Height: | Size: 827 B |
|
Before Width: | Height: | Size: 850 B After Width: | Height: | Size: 850 B |
|
Before Width: | Height: | Size: 882 B After Width: | Height: | Size: 882 B |
|
Before Width: | Height: | Size: 954 B After Width: | Height: | Size: 954 B |
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
|
Before Width: | Height: | Size: 868 B After Width: | Height: | Size: 868 B |
|
Before Width: | Height: | Size: 958 B After Width: | Height: | Size: 958 B |
|
Before Width: | Height: | Size: 989 B After Width: | Height: | Size: 989 B |
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 1 KiB |