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) {
|
function Player(id, physicsEngine, user) {
|
||||||
Parent.call(this, id, physicsEngine, user);
|
Parent.call(this, id, physicsEngine, user);
|
||||||
|
|
||||||
this.playerInfoView = null;
|
this.healthBarView = null;
|
||||||
this.playerInfoViewVisibleTimeout = null;
|
this.healthBarViewVisibleTimeout = null;
|
||||||
this.playerInfoViewVisible = false;
|
this.healthBarViewVisible = false;
|
||||||
this.initHealthBar();
|
this.initHealthBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,36 +29,36 @@ function (Parent, Nc, Settings) {
|
||||||
Player.prototype.initHealthBar = function() {
|
Player.prototype.initHealthBar = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.playerInfoViewVisible = false;
|
this.healthBarViewVisible = false;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
x: 100,
|
x: 100,
|
||||||
y: 100,
|
y: 100,
|
||||||
healthFactor: this.stats.health / 100,
|
healthFactor: this.stats.health / 100,
|
||||||
visible: this.playerInfoViewVisible
|
visible: this.healthBarViewVisible
|
||||||
};
|
};
|
||||||
|
|
||||||
var callback = function(playerInfoView) {
|
var callback = function(healthBarView) {
|
||||||
self.playerInfoView = playerInfoView;
|
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() {
|
Player.prototype.onHealthChange = function() {
|
||||||
if(this.stats.health != 100) {
|
if(this.stats.health != 100) {
|
||||||
this.setPlayerInfoVisible(true);
|
this.setHealthBarVisible(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.spawn = function(x, y) {
|
Player.prototype.spawn = function(x, y) {
|
||||||
Parent.prototype.spawn.call(this, 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;
|
var self = this;
|
||||||
this.playerInfoViewVisible = visible;
|
this.healthBarViewVisible = visible;
|
||||||
if(this.playerInfoViewVisibleTimeout) clearTimeout(this.playerInfoViewVisibleTimeout);
|
if(this.healthBarViewVisibleTimeout) clearTimeout(this.healthBarViewVisibleTimeout);
|
||||||
|
|
||||||
if(visible) {
|
if(visible) {
|
||||||
var position = this.getPosition();
|
var position = this.getPosition();
|
||||||
|
|
@ -67,17 +67,17 @@ function (Parent, Nc, Settings) {
|
||||||
x: position.x * Settings.RATIO,
|
x: position.x * Settings.RATIO,
|
||||||
y: position.y * Settings.RATIO,
|
y: position.y * Settings.RATIO,
|
||||||
healthFactor: this.stats.health / 100,
|
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() {
|
this.healthBarViewVisibleTimeout = setTimeout(function() {
|
||||||
self.playerInfoViewVisible = false;
|
self.healthBarViewVisible = false;
|
||||||
Nc.trigger(Nc.ns.client.view.playerInfo.update, self.playerInfoView, {visible: self.playerInfoViewVisible});
|
Nc.trigger(Nc.ns.client.view.healthBar.update, self.healthBarView, {visible: self.healthBarViewVisible});
|
||||||
}, Settings.HEALTH_DISPLAY_TIME * 1000);
|
}, Settings.HEALTH_DISPLAY_TIME * 1000);
|
||||||
|
|
||||||
} else {
|
} 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();
|
this.doll.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.playerInfoViewVisible) {
|
if(this.healthBarViewVisible) {
|
||||||
var position = this.getPosition();
|
var position = this.getPosition();
|
||||||
var options = {
|
var options = {
|
||||||
healthFactor: this.stats.health / 100,
|
healthFactor: this.stats.health / 100,
|
||||||
x: position.x * Settings.RATIO,
|
x: position.x * Settings.RATIO,
|
||||||
y: position.y * 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() {
|
Player.prototype.destroy = function() {
|
||||||
clearTimeout(this.playerInfoViewVisibleTimeout);
|
clearTimeout(this.healthBarViewVisibleTimeout);
|
||||||
Nc.trigger(Nc.ns.client.view.playerInfo.remove, this.playerInfoView);
|
Nc.trigger(Nc.ns.client.view.healthBar.remove, this.healthBarView);
|
||||||
Parent.prototype.destroy.call(this);
|
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.fullscreen.change, this.onFullscreenChange, this),
|
||||||
Nc.on(Nc.ns.client.view.debugMode.toggle, this.onToggleDebugMode, 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.zoomIn, this.onZoomIn, this),
|
||||||
Nc.on(Nc.ns.client.game.zoomOut, this.onZoomOut, this),
|
Nc.on(Nc.ns.client.game.zoomOut, this.onZoomOut, this),
|
||||||
Nc.on(Nc.ns.client.game.zoomReset, this.onZoomReset, 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, 'onZoomOut');
|
||||||
Abstract.prototype.addMethod.call(AbstractView, 'onZoomReset');
|
Abstract.prototype.addMethod.call(AbstractView, 'onZoomReset');
|
||||||
Abstract.prototype.addMethod.call(AbstractView, 'toggleInfo', ['show', 'string']);
|
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']);
|
Abstract.prototype.addMethod.call(AbstractView, 'onUpdateLoader', ['progress']);
|
||||||
|
|
||||||
AbstractView.prototype.isWebGlEnabled = function () {
|
AbstractView.prototype.isWebGlEnabled = function () {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@ function (Parent, PIXI, Nc, Settings) {
|
||||||
|
|
||||||
this.ncTokens = [
|
this.ncTokens = [
|
||||||
Nc.on(Nc.ns.client.view.playerArrow.createAndAdd, this.onCreateAndAddPlayerArrow, this),
|
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;
|
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() {
|
Ghost.prototype.destroy = function() {
|
||||||
for (var i = 0; i < this.ncTokens.length; i++) {
|
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() {
|
PixiView.prototype.initLoader = function() {
|
||||||
this.loader = new PIXI.Graphics();
|
this.loader = new PIXI.Graphics();
|
||||||
this.stage.addChild(this.loader);
|
this.stage.addChild(this.loader);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ function (Exception) {
|
||||||
animatedMesh: {
|
animatedMesh: {
|
||||||
create: null
|
create: null
|
||||||
},
|
},
|
||||||
playerInfo: {
|
healthBar: {
|
||||||
createAndAdd: null,
|
createAndAdd: null,
|
||||||
remove: null,
|
remove: null,
|
||||||
update: null
|
update: null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue