mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
better feedback on killing. fixes #109
This commit is contained in:
parent
81f5990e0c
commit
5007ab5b02
8 changed files with 95 additions and 22 deletions
|
|
@ -70,7 +70,7 @@ function (Parent, Item, Box2D, Nc) {
|
||||||
var player = item.lastMoved.player;
|
var player = item.lastMoved.player;
|
||||||
|
|
||||||
var callback = function() {
|
var callback = function() {
|
||||||
self.player.addDamage(damage, player);
|
self.player.addDamage(damage, player, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback)
|
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback)
|
||||||
|
|
|
||||||
|
|
@ -58,14 +58,14 @@ function (Parent, Nc) {
|
||||||
this.addDamage(100, this);
|
this.addDamage(100, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.addDamage = function(damage, enemy) {
|
Player.prototype.addDamage = function(damage, enemy, byItem) {
|
||||||
this.stats.health -= damage;
|
this.stats.health -= damage;
|
||||||
|
|
||||||
if(this.stats.health < 0) this.stats.health = 0;
|
if(this.stats.health < 0) this.stats.health = 0;
|
||||||
|
|
||||||
if(this.stats.health <= 0) {
|
if(this.stats.health <= 0) {
|
||||||
if(enemy != this) enemy.score();
|
if(enemy != this) enemy.score();
|
||||||
this.kill(enemy);
|
this.kill(enemy, byItem);
|
||||||
} else {
|
} else {
|
||||||
this.broadcastStats();
|
this.broadcastStats();
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +77,7 @@ function (Parent, Nc) {
|
||||||
this.broadcastStats();
|
this.broadcastStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.kill = function(killedByPlayer) {
|
Player.prototype.kill = function(killedByPlayer, byItem) {
|
||||||
this.stats.deaths++;
|
this.stats.deaths++;
|
||||||
var ragDollId = this.stats.deaths;
|
var ragDollId = this.stats.deaths;
|
||||||
Parent.prototype.kill.call(this, killedByPlayer, ragDollId);
|
Parent.prototype.kill.call(this, killedByPlayer, ragDollId);
|
||||||
|
|
@ -86,9 +86,12 @@ function (Parent, Nc) {
|
||||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "playerKill", {
|
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "playerKill", {
|
||||||
playerId: this.id,
|
playerId: this.id,
|
||||||
killedByPlayerId: killedByPlayer.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
|
Nc.trigger(Nc.ns.channel.events.game.player.killed, this, killedByPlayer); // sends endround
|
||||||
|
|
||||||
if(this.ragDoll) {
|
if(this.ragDoll) {
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,18 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
||||||
var player = this.players[options.playerId];
|
var player = this.players[options.playerId];
|
||||||
var killedByPlayer = this.players[options.killedByPlayerId];
|
var killedByPlayer = this.players[options.killedByPlayerId];
|
||||||
player.kill(killedByPlayer, options.ragDollId);
|
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) {
|
GameController.prototype.onPositionStateReset = function(options) {
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter) {
|
||||||
case "ghost": y++;
|
case "ghost": y++;
|
||||||
case "item": y++;
|
case "item": y++;
|
||||||
case "tile": y++;
|
case "tile": y++;
|
||||||
case "debug": y++;
|
|
||||||
case "spawn": y=y;
|
case "spawn": y=y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,7 +211,6 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter) {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
// we would need another zoom state,
|
// we would need another zoom state,
|
||||||
// to separate fixed zooming (by window size)
|
// to separate fixed zooming (by window size)
|
||||||
// and user zoom by +/-/0 keys
|
// and user zoom by +/-/0 keys
|
||||||
|
|
@ -240,17 +238,8 @@ function (Parent, PIXI, ColorRangeReplaceFilter, Settings, ColorConverter) {
|
||||||
|
|
||||||
// Position
|
// 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) {
|
if (!this.static) {
|
||||||
|
// Fixme: needs to read from actual level size
|
||||||
var levelSize = {
|
var levelSize = {
|
||||||
x: 600,
|
x: 600,
|
||||||
y: 400
|
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.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);
|
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"
|
if (this.name == "spawn"
|
||||||
|| this.name == "tile"
|
|| this.name == "tile"
|
||||||
|| this.name == "item"
|
|| this.name == "item"
|
||||||
|| this.name == "ghost"
|
|| this.name == "ghost"
|
||||||
|| this.name == "debug"
|
|
||||||
|| this.name == "swiper") {
|
|| this.name == "swiper") {
|
||||||
this.container.x = this.position.current.x;
|
this.container.x = this.position.current.x;
|
||||||
this.container.y = this.position.current.y;
|
this.container.y = this.position.current.y;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ function (Parent, PIXI, Settings) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function Debug() {
|
function Debug() {
|
||||||
Parent.call(this, "Debug", 0);
|
Parent.call(this, "debug", 0);
|
||||||
|
|
||||||
|
|
||||||
this.graphics = new PIXI.Graphics();
|
this.graphics = new PIXI.Graphics();
|
||||||
|
|
|
||||||
63
app/Game/Client/View/Pixi/Layers/Messages.js
Normal file
63
app/Game/Client/View/Pixi/Layers/Messages.js
Normal file
|
|
@ -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;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -10,10 +10,11 @@ define([
|
||||||
"Game/Client/View/Pixi/Layers/Ghost",
|
"Game/Client/View/Pixi/Layers/Ghost",
|
||||||
"Game/Client/View/Pixi/Layers/Swiper",
|
"Game/Client/View/Pixi/Layers/Swiper",
|
||||||
"Game/Client/PointerLockManager",
|
"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";
|
"use strict";
|
||||||
|
|
||||||
|
|
@ -87,6 +88,9 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
|
||||||
this.debugLayer = Debug;
|
this.debugLayer = Debug;
|
||||||
this.layerManager.insert(this.debugLayer, false);
|
this.layerManager.insert(this.debugLayer, false);
|
||||||
|
|
||||||
|
this.messagesLayer = new Messages();
|
||||||
|
this.layerManager.insert(this.messagesLayer, false);
|
||||||
|
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,8 @@ function (Exception) {
|
||||||
toggle: null
|
toggle: null
|
||||||
},
|
},
|
||||||
gameStats: {
|
gameStats: {
|
||||||
toggle: null
|
toggle: null,
|
||||||
|
kill: null
|
||||||
},
|
},
|
||||||
swiper: {
|
swiper: {
|
||||||
swipe: null,
|
swipe: null,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue