mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed health bar
This commit is contained in:
parent
c1a756050f
commit
072e984215
5 changed files with 70 additions and 81 deletions
|
|
@ -17,10 +17,6 @@ function (Abstract, DomController, Settings, Exception, Nc) {
|
|||
Nc.on(Nc.ns.client.view.fullscreen.change, this.onFullscreenChange, this),
|
||||
Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, this),
|
||||
|
||||
Nc.on(Nc.ns.client.view.playerInfo.createAndAdd, this.onCreateAndAddPlayerInfo, this),
|
||||
Nc.on(Nc.ns.client.view.playerInfo.update, this.onUpdatePlayerInfo, this),
|
||||
Nc.on(Nc.ns.client.view.playerInfo.remove, this.onRemovePlayerInfo, this),
|
||||
|
||||
Nc.on(Nc.ns.client.game.zoomIn, this.onZoomIn, this),
|
||||
Nc.on(Nc.ns.client.game.zoomOut, this.onZoomOut, this),
|
||||
Nc.on(Nc.ns.client.game.zoomReset, this.onZoomReset, this),
|
||||
|
|
@ -37,9 +33,6 @@ function (Abstract, DomController, Settings, Exception, Nc) {
|
|||
Abstract.prototype.addMethod.call(AbstractView, 'onZoomOut');
|
||||
Abstract.prototype.addMethod.call(AbstractView, 'onZoomReset');
|
||||
Abstract.prototype.addMethod.call(AbstractView, 'toggleInfo', ['show', 'string']);
|
||||
Abstract.prototype.addMethod.call(AbstractView, 'onCreateAndAddPlayerInfo', ['options']);
|
||||
Abstract.prototype.addMethod.call(AbstractView, 'onUpdatePlayerInfo', ['mesh', 'options']);
|
||||
Abstract.prototype.addMethod.call(AbstractView, 'onRemovePlayerInfo', ['mesh']);
|
||||
Abstract.prototype.addMethod.call(AbstractView, 'onUpdateLoader', ['progress']);
|
||||
|
||||
AbstractView.prototype.isWebGlEnabled = function () {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ function (Parent, PIXI, Nc, Settings) {
|
|||
|
||||
this.ncTokens = [
|
||||
Nc.on(Nc.ns.client.view.playerArrow.createAndAdd, this.onCreateAndAddPlayerArrow, this),
|
||||
Nc.on(Nc.ns.client.view.playerArrow.update, this.onUpdatePlayerArrow, this)
|
||||
Nc.on(Nc.ns.client.view.playerArrow.update, this.onUpdatePlayerArrow, this),
|
||||
Nc.on(Nc.ns.client.view.healthBar.createAndAdd, this.onCreateAndAddHealthBar, this),
|
||||
Nc.on(Nc.ns.client.view.healthBar.update, this.onUpdateHealthBar, this),
|
||||
Nc.on(Nc.ns.client.view.healthBar.remove, this.onRemoveHealthBar, this),
|
||||
];
|
||||
|
||||
}
|
||||
|
|
@ -60,7 +63,48 @@ function (Parent, PIXI, Nc, Settings) {
|
|||
arrow.rotation = angle;
|
||||
};
|
||||
|
||||
|
||||
// Player Info
|
||||
|
||||
Ghost.prototype.onCreateAndAddHealthBar = function(callback, options) {
|
||||
var healthBar = new PIXI.Graphics();
|
||||
this.container.addChild(healthBar);
|
||||
|
||||
this.onUpdateHealthBar(healthBar, options);
|
||||
callback(healthBar);
|
||||
};
|
||||
|
||||
Ghost.prototype.onUpdateHealthBar = function(healthBar, options) {
|
||||
var width = 14,
|
||||
height = 2,
|
||||
borderWidth = 1,
|
||||
offsetX = -8,
|
||||
offsetY = -52;
|
||||
|
||||
if(typeof options.healthFactor != 'undefined') {
|
||||
healthBar.clear();
|
||||
|
||||
healthBar.beginFill(0x000000);
|
||||
healthBar.lineStyle(borderWidth, 0x000000);
|
||||
healthBar.drawRect(0, 0, width, height);
|
||||
healthBar.endFill();
|
||||
|
||||
if(options.healthFactor > 0) {
|
||||
var color = 0x00FF00;
|
||||
if(options.healthFactor < 0.30) color = 0xFF0000;
|
||||
healthBar.beginFill(color);
|
||||
healthBar.lineStyle(0, 0x000000);
|
||||
healthBar.drawRect(borderWidth, borderWidth, width * options.healthFactor, height);
|
||||
healthBar.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
if (options.x && options.y) healthBar.position = new PIXI.Point(offsetX + options.x, offsetY + options.y);
|
||||
if (options.visible === true || options.visible === false) healthBar.visible = options.visible;
|
||||
};
|
||||
|
||||
Ghost.prototype.onRemoveHealthBar = function(healthBar) {
|
||||
this.container.removeChild(healthBar);
|
||||
};
|
||||
|
||||
Ghost.prototype.destroy = function() {
|
||||
for (var i = 0; i < this.ncTokens.length; i++) {
|
||||
|
|
|
|||
|
|
@ -98,54 +98,6 @@ function (Parent, DomController, PIXI, Settings, Nc, Exception, GameStats, Layer
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
// 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) {
|
||||
var color = 0x00FF00;
|
||||
if(options.healthFactor < 0.30) color = 0xFF0000;
|
||||
playerInfo.beginFill(color);
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
PixiView.prototype.initLoader = function() {
|
||||
this.loader = new PIXI.Graphics();
|
||||
this.stage.addChild(this.loader);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue