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
|
|
@ -9,9 +9,9 @@ function (Parent, Nc, Settings) {
|
|||
function Player(id, physicsEngine, user) {
|
||||
Parent.call(this, id, physicsEngine, user);
|
||||
|
||||
this.playerInfoView = null;
|
||||
this.playerInfoViewVisibleTimeout = null;
|
||||
this.playerInfoViewVisible = false;
|
||||
this.healthBarView = null;
|
||||
this.healthBarViewVisibleTimeout = null;
|
||||
this.healthBarViewVisible = false;
|
||||
this.initHealthBar();
|
||||
}
|
||||
|
||||
|
|
@ -29,36 +29,36 @@ function (Parent, Nc, Settings) {
|
|||
Player.prototype.initHealthBar = function() {
|
||||
var self = this;
|
||||
|
||||
this.playerInfoViewVisible = false;
|
||||
this.healthBarViewVisible = false;
|
||||
|
||||
var options = {
|
||||
x: 100,
|
||||
y: 100,
|
||||
healthFactor: this.stats.health / 100,
|
||||
visible: this.playerInfoViewVisible
|
||||
visible: this.healthBarViewVisible
|
||||
};
|
||||
|
||||
var callback = function(playerInfoView) {
|
||||
self.playerInfoView = playerInfoView;
|
||||
var callback = function(healthBarView) {
|
||||
self.healthBarView = healthBarView;
|
||||
}
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.createAndAdd, callback, options);
|
||||
Nc.trigger(Nc.ns.client.view.healthBar.createAndAdd, callback, options);
|
||||
};
|
||||
|
||||
Player.prototype.onHealthChange = function() {
|
||||
if(this.stats.health != 100) {
|
||||
this.setPlayerInfoVisible(true);
|
||||
this.setHealthBarVisible(true);
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.spawn = function(x, y) {
|
||||
Parent.prototype.spawn.call(this, x, y);
|
||||
this.setPlayerInfoVisible(false);
|
||||
this.setHealthBarVisible(false);
|
||||
};
|
||||
|
||||
Player.prototype.setPlayerInfoVisible = function(visible) {
|
||||
Player.prototype.setHealthBarVisible = function(visible) {
|
||||
var self = this;
|
||||
this.playerInfoViewVisible = visible;
|
||||
if(this.playerInfoViewVisibleTimeout) clearTimeout(this.playerInfoViewVisibleTimeout);
|
||||
this.healthBarViewVisible = visible;
|
||||
if(this.healthBarViewVisibleTimeout) clearTimeout(this.healthBarViewVisibleTimeout);
|
||||
|
||||
if(visible) {
|
||||
var position = this.getPosition();
|
||||
|
|
@ -67,17 +67,17 @@ function (Parent, Nc, Settings) {
|
|||
x: position.x * Settings.RATIO,
|
||||
y: position.y * Settings.RATIO,
|
||||
healthFactor: this.stats.health / 100,
|
||||
visible: this.playerInfoViewVisible
|
||||
visible: this.healthBarViewVisible
|
||||
};
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, this.playerInfoView, options);
|
||||
Nc.trigger(Nc.ns.client.view.healthBar.update, this.healthBarView, options);
|
||||
|
||||
this.playerInfoViewVisibleTimeout = setTimeout(function() {
|
||||
self.playerInfoViewVisible = false;
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, self.playerInfoView, {visible: self.playerInfoViewVisible});
|
||||
this.healthBarViewVisibleTimeout = setTimeout(function() {
|
||||
self.healthBarViewVisible = false;
|
||||
Nc.trigger(Nc.ns.client.view.healthBar.update, self.healthBarView, {visible: self.healthBarViewVisible});
|
||||
}, Settings.HEALTH_DISPLAY_TIME * 1000);
|
||||
|
||||
} else {
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, this.playerInfoView, {visible: this.playerInfoViewVisible});
|
||||
Nc.trigger(Nc.ns.client.view.healthBar.update, this.healthBarView, {visible: this.healthBarViewVisible});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -91,20 +91,20 @@ function (Parent, Nc, Settings) {
|
|||
this.doll.render();
|
||||
}
|
||||
|
||||
if(this.playerInfoViewVisible) {
|
||||
if(this.healthBarViewVisible) {
|
||||
var position = this.getPosition();
|
||||
var options = {
|
||||
healthFactor: this.stats.health / 100,
|
||||
x: position.x * Settings.RATIO,
|
||||
y: position.y * Settings.RATIO,
|
||||
}
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, this.playerInfoView, options);
|
||||
Nc.trigger(Nc.ns.client.view.healthBar.update, this.healthBarView, options);
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.destroy = function() {
|
||||
clearTimeout(this.playerInfoViewVisibleTimeout);
|
||||
Nc.trigger(Nc.ns.client.view.playerInfo.remove, this.playerInfoView);
|
||||
clearTimeout(this.healthBarViewVisibleTimeout);
|
||||
Nc.trigger(Nc.ns.client.view.healthBar.remove, this.healthBarView);
|
||||
Parent.prototype.destroy.call(this);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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