diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 812ce21..a993544 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -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) { diff --git a/app/Game/Client/GameObjects/Doll.js b/app/Game/Client/GameObjects/Doll.js index b8a0138..fbf286c 100755 --- a/app/Game/Client/GameObjects/Doll.js +++ b/app/Game/Client/GameObjects/Doll.js @@ -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) { diff --git a/app/Game/Client/Loader/Level.js b/app/Game/Client/Loader/Level.js index ce01e12..6a80692 100755 --- a/app/Game/Client/Loader/Level.js +++ b/app/Game/Client/Loader/Level.js @@ -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; }); \ No newline at end of file diff --git a/app/Game/Client/Loader/TiledLevel.js b/app/Game/Client/Loader/TiledLevel.js index e23fbd3..cd5fb98 100644 --- a/app/Game/Client/Loader/TiledLevel.js +++ b/app/Game/Client/Loader/TiledLevel.js @@ -1,9 +1,50 @@ define([ - "Game/Core/Loader/TiledLevel" + "Game/Core/Loader/TiledLevel", + "Game/Config/Settings" ], -function (Parent) { +function (Parent, Settings) { + + function TiledLevel(uid, engine, gameObjects) { + Parent.call(this, uid, engine, gameObjects); + } - return Parent; + 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; }); \ No newline at end of file diff --git a/app/Game/Client/Networker.js b/app/Game/Client/Networker.js index bd02287..5ee400d 100755 --- a/app/Game/Client/Networker.js +++ b/app/Game/Client/Networker.js @@ -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(); }; @@ -85,7 +79,8 @@ 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]; } diff --git a/app/Game/Client/Player.js b/app/Game/Client/Player.js index af6d21b..81b524e 100755 --- a/app/Game/Client/Player.js +++ b/app/Game/Client/Player.js @@ -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); diff --git a/app/Game/Client/View/Views/AbstractView.js b/app/Game/Client/View/Views/AbstractView.js index f274cb7..4c9fa91 100755 --- a/app/Game/Client/View/Views/AbstractView.js +++ b/app/Game/Client/View/Views/AbstractView.js @@ -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; }); \ No newline at end of file diff --git a/app/Game/Client/View/Views/PixiView.js b/app/Game/Client/View/Views/PixiView.js index 087a03b..3a362cf 100755 --- a/app/Game/Client/View/Views/PixiView.js +++ b/app/Game/Client/View/Views/PixiView.js @@ -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; }); diff --git a/app/Game/Core/GameController.js b/app/Game/Core/GameController.js index 631b2cb..e7fae16 100755 --- a/app/Game/Core/GameController.js +++ b/app/Game/Core/GameController.js @@ -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; diff --git a/app/Game/Core/GameObjects/Doll.js b/app/Game/Core/GameObjects/Doll.js index 8f59d24..21e6051 100755 --- a/app/Game/Core/GameObjects/Doll.js +++ b/app/Game/Core/GameObjects/Doll.js @@ -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; diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index 1e53f12..29d7d4e 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -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); diff --git a/app/Game/Core/Loader/TiledLevel.js b/app/Game/Core/Loader/TiledLevel.js index 016b33e..4303faa 100755 --- a/app/Game/Core/Loader/TiledLevel.js +++ b/app/Game/Core/Loader/TiledLevel.js @@ -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]; } } diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index eb945b3..957d847 100755 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -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; diff --git a/app/Game/Server/Channel.js b/app/Game/Server/Channel.js index 943bb93..76d8dc6 100755 --- a/app/Game/Server/Channel.js +++ b/app/Game/Server/Channel.js @@ -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 }; diff --git a/app/Game/Server/GameController.js b/app/Game/Server/GameController.js index 3bf402a..47f9d3e 100755 --- a/app/Game/Server/GameController.js +++ b/app/Game/Server/GameController.js @@ -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}); diff --git a/app/Game/Server/Player.js b/app/Game/Server/Player.js index 3dc1739..4c41018 100755 --- a/app/Game/Server/Player.js +++ b/app/Game/Server/Player.js @@ -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) { diff --git a/app/Game/Server/User.js b/app/Game/Server/User.js index 86b93e2..d02c373 100755 --- a/app/Game/Server/User.js +++ b/app/Game/Server/User.js @@ -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); } + }; diff --git a/app/Lib/Utilities/Extensions.js b/app/Lib/Utilities/Extensions.js index edc97f7..6af99e1 100755 --- a/app/Lib/Utilities/Extensions.js +++ b/app/Lib/Utilities/Extensions.js @@ -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); + } + } + }); \ No newline at end of file diff --git a/app/Lobby/User.js b/app/Lobby/User.js index a6c312d..8a15316 100755 --- a/app/Lobby/User.js +++ b/app/Lobby/User.js @@ -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); diff --git a/channel.js b/channel.js index 9c92c0e..6d397d8 100755 --- a/channel.js +++ b/channel.js @@ -9,10 +9,6 @@ requirejs.config({ var inspector = {}; -console.checkpoint = function (s) { - console.log(' \033[34mbeep - \033[0m' + s); -} - requirejs([ "Game/Server/PipeToLobby" ], diff --git a/client.js b/client.js index 9aa6ff4..bf6cc0d 100755 --- a/client.js +++ b/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"); } }); \ No newline at end of file diff --git a/server.js b/server.js index 899c13a..28c88d4 100755 --- a/server.js +++ b/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", diff --git a/static/html/index.html b/static/html/index.html index 19e8c6f..e043031 100755 --- a/static/html/index.html +++ b/static/html/index.html @@ -14,21 +14,6 @@ color: white; 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 { /* @@ -70,9 +55,7 @@
-