mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
refactored Server and Lobby
This commit is contained in:
parent
42475c9b38
commit
d83376d5c7
26 changed files with 29 additions and 29 deletions
87
app/Game/Channel/GameObjects/Item.js
Executable file
87
app/Game/Channel/GameObjects/Item.js
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Item"
|
||||
],
|
||||
|
||||
function (Parent) {
|
||||
|
||||
function Item(physicsEngine, uid, options) {
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
this.heldByPlayers = [];
|
||||
this.lastMoved = null;
|
||||
}
|
||||
|
||||
Item.prototype = Object.create(Parent.prototype);
|
||||
|
||||
|
||||
Item.prototype.setLastMovedBy = function(player) {
|
||||
|
||||
if(player) {
|
||||
this.lastMoved = {
|
||||
player: player,
|
||||
timestamp: new Date()
|
||||
}
|
||||
} else {
|
||||
this.lastMoved = null;
|
||||
}
|
||||
};
|
||||
|
||||
Item.prototype.isGrabbingAllowed = function(player) {
|
||||
return this.heldByPlayers.length == 0;
|
||||
};
|
||||
|
||||
Item.prototype.beingGrabbed = function(player) {
|
||||
Parent.prototype.beingGrabbed.call(this, player);
|
||||
|
||||
if(this.isGrabbingAllowed(player)) {
|
||||
this.heldByPlayers.push(player);
|
||||
this.setLastMovedBy(null);
|
||||
}
|
||||
};
|
||||
|
||||
Item.prototype.isReleasingAllowed = function(player) {
|
||||
return true;
|
||||
};
|
||||
|
||||
Item.prototype.beingReleased = function(player) {
|
||||
Parent.prototype.beingReleased.call(this, player);
|
||||
|
||||
if(this.isReleasingAllowed(player)) {
|
||||
var pos = this.heldByPlayers.indexOf(player);
|
||||
if(pos >= 0) {
|
||||
this.heldByPlayers.splice(pos, 1);
|
||||
this.setLastMovedBy(player);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Item.prototype.onCollisionChange = function(isColliding, fixture) {
|
||||
|
||||
if(isColliding) {
|
||||
var otherBody = fixture.GetBody();
|
||||
if(otherBody) {
|
||||
var otherItem = otherBody.GetUserData();
|
||||
if(otherItem instanceof Item) {
|
||||
if(!this.lastMoved && !otherItem.lastMoved) return;
|
||||
|
||||
if(this.lastMoved && otherItem.lastMoved) {
|
||||
if(this.lastMoved.timestamp > otherItem.lastMoved.timestamp) {
|
||||
this.setLastMovedBy(otherItem.lastMoved.player);
|
||||
} else {
|
||||
otherItem.setLastMovedBy(this.lastMoved.player);
|
||||
}
|
||||
} else {
|
||||
if(!this.lastMoved) {
|
||||
this.setLastMovedBy(otherItem.lastMoved.player);
|
||||
} else {
|
||||
otherItem.setLastMovedBy(this.lastMoved.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Item;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue