mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added player arrow to me fixes #76
This commit is contained in:
parent
8f2cf11e38
commit
a58beb58d1
5 changed files with 92 additions and 3 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
define([
|
define([
|
||||||
"Game/Client/Player",
|
"Game/Client/Player",
|
||||||
"Game/Config/Settings"
|
"Game/Config/Settings",
|
||||||
|
"Lib/Utilities/NotificationCenter"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, Settings) {
|
function (Parent, Settings, Nc) {
|
||||||
|
|
||||||
function Me(id, physicsEngine, user) {
|
function Me(id, physicsEngine, user) {
|
||||||
Parent.call(this, id, physicsEngine, user);
|
Parent.call(this, id, physicsEngine, user);
|
||||||
|
|
@ -14,6 +15,9 @@ function (Parent, Settings) {
|
||||||
y: 0
|
y: 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.arrowMesh = null;
|
||||||
|
this.createAndAddArrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
Me.prototype = Object.create(Parent.prototype);
|
Me.prototype = Object.create(Parent.prototype);
|
||||||
|
|
@ -61,6 +65,34 @@ function (Parent, Settings) {
|
||||||
this.doll.body.SetLinearVelocity(options.lv);
|
this.doll.body.SetLinearVelocity(options.lv);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Me.prototype.createAndAddArrow = function(visible) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var position = this.getPosition();
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
x: position.x * Settings.RATIO,
|
||||||
|
y: position.y * Settings.RATIO,
|
||||||
|
};
|
||||||
|
|
||||||
|
var callback = function(arrowMesh) {
|
||||||
|
self.arrowMesh = arrowMesh;
|
||||||
|
}
|
||||||
|
Nc.trigger(Nc.ns.client.view.playerArrow.createAndAdd, callback, options);
|
||||||
|
};
|
||||||
|
|
||||||
|
Me.prototype.render = function() {
|
||||||
|
|
||||||
|
Parent.prototype.render.call(this);
|
||||||
|
|
||||||
|
var position = this.getPosition();
|
||||||
|
var options = {
|
||||||
|
x: position.x * Settings.RATIO,
|
||||||
|
y: position.y * Settings.RATIO,
|
||||||
|
}
|
||||||
|
Nc.trigger(Nc.ns.client.view.playerArrow.update, this.arrowMesh, options);
|
||||||
|
};
|
||||||
|
|
||||||
return Me;
|
return Me;
|
||||||
|
|
||||||
});
|
})
|
||||||
|
|
@ -28,6 +28,9 @@ function (DomController, Settings, Exception, Nc) {
|
||||||
Nc.on(Nc.ns.client.view.playerInfo.update, this.onUpdatePlayerInfo, 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.view.playerInfo.remove, this.onRemovePlayerInfo, 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.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),
|
||||||
|
|
@ -169,6 +172,14 @@ function (DomController, Settings, Exception, Nc) {
|
||||||
throw new Exception('Abstract Function onCreateAndAddPlayerInfo not overwritten');
|
throw new Exception('Abstract Function onCreateAndAddPlayerInfo not overwritten');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AbstractView.prototype.onCreateAndAddPlayerArrow = function(options) {
|
||||||
|
throw new Exception('Abstract Function onCreateAndAddPlayerArrow not overwritten');
|
||||||
|
};
|
||||||
|
|
||||||
|
AbstractView.prototype.onUpdatePlayerArrow = function(options) {
|
||||||
|
throw new Exception('Abstract Function onUpdatePlayerArrow not overwritten');
|
||||||
|
};
|
||||||
|
|
||||||
AbstractView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
|
AbstractView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
|
||||||
throw new Exception('Abstract Function onUpdatePlayerInfo not overwritten');
|
throw new Exception('Abstract Function onUpdatePlayerInfo not overwritten');
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,47 @@ function (Parent, DomController, PIXI, ColorRangeReplaceFilter, Settings, Nc, Ex
|
||||||
this.container.removeChild(playerInfo);
|
this.container.removeChild(playerInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
PixiView.prototype.onCreateAndAddPlayerArrow = function(callback, options) {
|
||||||
|
var arrow = new PIXI.Graphics();
|
||||||
|
arrow.visible = false;
|
||||||
|
this.container.addChild(arrow);
|
||||||
|
|
||||||
|
var width = 12,
|
||||||
|
height = 12;
|
||||||
|
|
||||||
|
arrow.beginFill(0xffffff, 0.1);
|
||||||
|
arrow.lineStyle(0, 0x000000);
|
||||||
|
arrow.moveTo(0, 0);
|
||||||
|
arrow.lineTo(width, 0);
|
||||||
|
arrow.lineTo(width / 2, height);
|
||||||
|
arrow.endFill();
|
||||||
|
arrow.pivot = new PIXI.Point(width/2, height/2);
|
||||||
|
arrow.visible = true;
|
||||||
|
|
||||||
|
this.onUpdatePlayerArrow(arrow, options);
|
||||||
|
|
||||||
|
callback(arrow);
|
||||||
|
};
|
||||||
|
|
||||||
|
PixiView.prototype.onUpdatePlayerArrow = function(arrow, options) {
|
||||||
|
|
||||||
|
var offsetX = 0,
|
||||||
|
offsetY = -60,
|
||||||
|
x = offsetX + options.x,
|
||||||
|
y = offsetY + options.y;
|
||||||
|
|
||||||
|
var target = new PIXI.Point(x, y);
|
||||||
|
|
||||||
|
arrow.position.x += (target.x -arrow.position.x) * Settings.ARROW_GLIDE / 1.5 / 100;
|
||||||
|
arrow.position.y += (target.y -arrow.position.y) * Settings.ARROW_GLIDE / 100;
|
||||||
|
|
||||||
|
var angle = -Math.atan2(arrow.position.x - x, arrow.position.y - options.y);
|
||||||
|
angle += 0.785398163 * 4;
|
||||||
|
|
||||||
|
arrow.rotation = angle;
|
||||||
|
};
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ define(function() {
|
||||||
CAMERA_IS_ORTHOGRAPHIC: true,
|
CAMERA_IS_ORTHOGRAPHIC: true,
|
||||||
CAMERA_GLIDE: 12, // % of the way per frame
|
CAMERA_GLIDE: 12, // % of the way per frame
|
||||||
VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi',
|
VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi',
|
||||||
|
ARROW_GLIDE: 30, // % of the way per frame
|
||||||
|
|
||||||
// GAME PLAY
|
// GAME PLAY
|
||||||
WALK_SPEED: 4,
|
WALK_SPEED: 4,
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ function (Exception) {
|
||||||
remove: null,
|
remove: null,
|
||||||
update: null
|
update: null
|
||||||
},
|
},
|
||||||
|
playerArrow: {
|
||||||
|
createAndAdd: null,
|
||||||
|
update: null
|
||||||
|
},
|
||||||
preloadBar: {
|
preloadBar: {
|
||||||
update: null
|
update: null
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue