From 5007ab5b028c3435d1c616c073e6d404b4529890 Mon Sep 17 00:00:00 2001 From: logsol Date: Mon, 2 Mar 2015 00:13:21 +0100 Subject: [PATCH] better feedback on killing. fixes #109 --- app/Game/Channel/GameObjects/Doll.js | 2 +- app/Game/Channel/Player.js | 11 ++-- app/Game/Client/GameController.js | 12 ++++ app/Game/Client/View/Pixi/Layer.js | 16 +---- app/Game/Client/View/Pixi/Layers/Debug.js | 2 +- app/Game/Client/View/Pixi/Layers/Messages.js | 63 ++++++++++++++++++++ app/Game/Client/View/Pixi/View.js | 8 ++- app/Lib/Utilities/NotificationCenter.js | 3 +- 8 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 app/Game/Client/View/Pixi/Layers/Messages.js diff --git a/app/Game/Channel/GameObjects/Doll.js b/app/Game/Channel/GameObjects/Doll.js index 85510b6..26461f6 100755 --- a/app/Game/Channel/GameObjects/Doll.js +++ b/app/Game/Channel/GameObjects/Doll.js @@ -70,7 +70,7 @@ function (Parent, Item, Box2D, Nc) { var player = item.lastMoved.player; var callback = function() { - self.player.addDamage(damage, player); + self.player.addDamage(damage, player, item); } Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback) diff --git a/app/Game/Channel/Player.js b/app/Game/Channel/Player.js index 2ac4413..045dea4 100755 --- a/app/Game/Channel/Player.js +++ b/app/Game/Channel/Player.js @@ -58,14 +58,14 @@ function (Parent, Nc) { this.addDamage(100, this); }; - Player.prototype.addDamage = function(damage, enemy) { + Player.prototype.addDamage = function(damage, enemy, byItem) { this.stats.health -= damage; if(this.stats.health < 0) this.stats.health = 0; if(this.stats.health <= 0) { if(enemy != this) enemy.score(); - this.kill(enemy); + this.kill(enemy, byItem); } else { this.broadcastStats(); } @@ -77,7 +77,7 @@ function (Parent, Nc) { this.broadcastStats(); }; - Player.prototype.kill = function(killedByPlayer) { + Player.prototype.kill = function(killedByPlayer, byItem) { this.stats.deaths++; var ragDollId = this.stats.deaths; Parent.prototype.kill.call(this, killedByPlayer, ragDollId); @@ -86,9 +86,12 @@ function (Parent, Nc) { Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "playerKill", { playerId: this.id, killedByPlayerId: killedByPlayer.id, - ragDollId: ragDollId + ragDollId: ragDollId, + item: byItem.options.name }); + + Nc.trigger(Nc.ns.channel.events.game.player.killed, this, killedByPlayer); // sends endround if(this.ragDoll) { diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index cde05ac..f962892 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -213,6 +213,18 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque var player = this.players[options.playerId]; var killedByPlayer = this.players[options.killedByPlayerId]; player.kill(killedByPlayer, options.ragDollId); + + Nc.trigger(Nc.ns.client.view.gameStats.kill, { + victim: { + name: player.user.options.nickname, + isMe: player === this.me + }, + killer: { + name: killedByPlayer.user.options.nickname, + isMe: killedByPlayer === this.me + }, + item: options.item + }); }; GameController.prototype.onPositionStateReset = function(options) { diff --git a/app/Game/Client/View/Pixi/Layer.js b/app/Game/Client/View/Pixi/Layer.js index d7ee866..7063924 100644 --- a/app/Game/Client/View/Pixi/Layer.js +++ b/app/Game/Client/View/Pixi/Layer.js @@ -43,7 +43,6 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter) { case "ghost": y++; case "item": y++; case "tile": y++; - case "debug": y++; case "spawn": y=y; } @@ -212,7 +211,6 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter) { /* - // we would need another zoom state, // to separate fixed zooming (by window size) // and user zoom by +/-/0 keys @@ -240,17 +238,8 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter) { // Position - /* - var posXStep = (this.position.target.x - this.position.current.x) * Settings.CAMERA_GLIDE / 100; - this.position.current.x += posXStep; - this.container.x = this.position.current.x + (this.position.current.x * this.parallaxSpeed); - - var posYStep = (this.position.target.y - this.position.current.y) * Settings.CAMERA_GLIDE / 100; - this.position.current.y += posYStep; - this.container.y = this.position.current.y + (this.position.current.y * this.parallaxSpeed); - */ - if (!this.static) { + // Fixme: needs to read from actual level size var levelSize = { x: 600, y: 400 @@ -265,11 +254,12 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter) { this.container.x = this.position.current.x + levelSize.x / 2 - (-this.parallaxSpeed) * (this.position.current.x + levelSize.x / 2); this.container.y = this.position.current.y + levelSize.y / 2 - (-this.parallaxSpeed) * (this.position.current.y + levelSize.y / 2); + + // Add here to set 0,0 not in the center of the map but the level origin in the top left if (this.name == "spawn" || this.name == "tile" || this.name == "item" || this.name == "ghost" - || this.name == "debug" || this.name == "swiper") { this.container.x = this.position.current.x; this.container.y = this.position.current.y; diff --git a/app/Game/Client/View/Pixi/Layers/Debug.js b/app/Game/Client/View/Pixi/Layers/Debug.js index 011b103..08c10a4 100644 --- a/app/Game/Client/View/Pixi/Layers/Debug.js +++ b/app/Game/Client/View/Pixi/Layers/Debug.js @@ -10,7 +10,7 @@ function (Parent, PIXI, Settings) { "use strict"; function Debug() { - Parent.call(this, "Debug", 0); + Parent.call(this, "debug", 0); this.graphics = new PIXI.Graphics(); diff --git a/app/Game/Client/View/Pixi/Layers/Messages.js b/app/Game/Client/View/Pixi/Layers/Messages.js new file mode 100644 index 0000000..10273ae --- /dev/null +++ b/app/Game/Client/View/Pixi/Layers/Messages.js @@ -0,0 +1,63 @@ +define([ + "Game/Client/View/Pixi/Layer", + "Lib/Vendor/Pixi", + "Lib/Utilities/NotificationCenter", + "Game/Config/Settings" +], + +function (Parent, PIXI, Nc, Settings) { + + "use strict"; + + function Messages() { + Parent.call(this, "messages", -1); + + this.ncTokens = [ + Nc.on(Nc.ns.client.view.gameStats.kill, this.onKill, this) + ]; + + this.mainTextOptions = { + font: "normal 22px 'Joystix'", + fill: "#cc0000", + stroke: "rgba(0,0,0,0.8)", + strokeThickness: 6 + }; + + this.mainText = new PIXI.Text("", this.mainTextOptions); + this.container.addChild(this.mainText); + this.mainText.visible = false; + } + + Messages.prototype = Object.create(Parent.prototype); + + Messages.prototype.onKill = function(options) { + + var killer = options.killer.isMe ? "You" : options.killer.name; + + var victim = options.victim.isMe + ? options.killer.isMe + ? "Yourself" + : "You" + : options.victim.name; + + var text = killer + " killed " + victim + " with " + options.item; + + this.mainText.setText(text); + this.mainText.setStyle(this.mainTextOptions); + this.mainText.position = new PIXI.Point(-this.mainText.width / 2, (Settings.STAGE_HEIGHT / 4) -this.mainText.height / 2); + this.mainText.visible = true; + + var self = this; + setTimeout(function(){ + self.mainText.visible = false; + }, 2000); + + } + + Messages.prototype.render = function(centerPosition, zoom) { + Parent.prototype.render.call(this, centerPosition, 1); + } + + return Messages; + +}); \ No newline at end of file diff --git a/app/Game/Client/View/Pixi/View.js b/app/Game/Client/View/Pixi/View.js index 68403c3..9effbb9 100755 --- a/app/Game/Client/View/Pixi/View.js +++ b/app/Game/Client/View/Pixi/View.js @@ -10,10 +10,11 @@ define([ "Game/Client/View/Pixi/Layers/Ghost", "Game/Client/View/Pixi/Layers/Swiper", "Game/Client/PointerLockManager", - "Game/Client/View/Pixi/Layers/Debug" + "Game/Client/View/Pixi/Layers/Debug", + "Game/Client/View/Pixi/Layers/Messages" ], -function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager, Ghost, Swiper, PointerLockManager, Debug) { +function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, LayerManager, Ghost, Swiper, PointerLockManager, Debug, Messages) { "use strict"; @@ -87,6 +88,9 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer this.debugLayer = Debug; this.layerManager.insert(this.debugLayer, false); + this.messagesLayer = new Messages(); + this.layerManager.insert(this.messagesLayer, false); + this.render(); } diff --git a/app/Lib/Utilities/NotificationCenter.js b/app/Lib/Utilities/NotificationCenter.js index 5a337ab..c751836 100755 --- a/app/Lib/Utilities/NotificationCenter.js +++ b/app/Lib/Utilities/NotificationCenter.js @@ -64,7 +64,8 @@ function (Exception) { toggle: null }, gameStats: { - toggle: null + toggle: null, + kill: null }, swiper: { swipe: null,