mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
refactored Server and Lobby
This commit is contained in:
parent
42475c9b38
commit
d83376d5c7
26 changed files with 29 additions and 29 deletions
78
app/Game/Channel/GameObjects/Doll.js
Executable file
78
app/Game/Channel/GameObjects/Doll.js
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Doll",
|
||||
"Game/Channel/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Parent, Item, Box2D, Nc) {
|
||||
|
||||
function Doll(physicsEngine, uid, player) {
|
||||
Parent.call(this, physicsEngine, uid, player);
|
||||
}
|
||||
|
||||
Doll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Doll.prototype.findCloseItem = function(x, y) {
|
||||
|
||||
function findItem(array) {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
var item = array[i];
|
||||
if(item.isGrabbingAllowed(this.player)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x < 0) { // looking left
|
||||
return findItem(this.reachableItems.left);
|
||||
} else {
|
||||
return findItem(this.reachableItems.right);
|
||||
}
|
||||
}
|
||||
|
||||
Doll.prototype.onImpact = function(isColliding, fixture) {
|
||||
var self = this;
|
||||
|
||||
Parent.prototype.onImpact.call(this, isColliding, fixture);
|
||||
|
||||
if(isColliding) {
|
||||
var otherBody = fixture.GetBody();
|
||||
if(otherBody) {
|
||||
var item = otherBody.GetUserData();
|
||||
if(item instanceof Item) {
|
||||
var itemVelocity = item.body.GetLinearVelocity();
|
||||
var itemMass = item.body.GetMass();
|
||||
|
||||
var ownVelocity = this.body.GetLinearVelocity();
|
||||
|
||||
var b2Math = Box2D.Common.Math.b2Math;
|
||||
|
||||
var absItemVelocity = b2Math.AbsV(itemVelocity)
|
||||
var max = 1;
|
||||
|
||||
if(absItemVelocity.x > max || absItemVelocity.y > max) {
|
||||
if(item.lastMoved && item.lastMoved.player != this.player) {
|
||||
var damage = b2Math.SubtractVV(itemVelocity, ownVelocity);
|
||||
damage.Abs();
|
||||
damage.Multiply(itemMass);
|
||||
|
||||
var player = item.lastMoved.player;
|
||||
|
||||
var callback = function() {
|
||||
self.player.addDamage(damage.Length() * 2, player);
|
||||
}
|
||||
|
||||
Nc.trigger("engine/addToWorldQueue", callback)
|
||||
}
|
||||
}
|
||||
|
||||
item.setLastMovedBy(this.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Doll;
|
||||
|
||||
});
|
||||
9
app/Game/Channel/GameObjects/GameObject.js
Executable file
9
app/Game/Channel/GameObjects/GameObject.js
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/GameObject"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
|
||||
return Parent;
|
||||
|
||||
});
|
||||
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;
|
||||
|
||||
});
|
||||
47
app/Game/Channel/GameObjects/Items/RagDoll.js
Normal file
47
app/Game/Channel/GameObjects/Items/RagDoll.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Items/RagDoll",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Parent, Settings, Nc) {
|
||||
|
||||
function RagDoll(physicsEngine, uid, options) {
|
||||
this.scheduledForDestruction = false;
|
||||
this.destructionTimeout = null;
|
||||
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
}
|
||||
|
||||
RagDoll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
RagDoll.prototype.beingGrabbed = function(player) {
|
||||
Parent.prototype.beingGrabbed.call(this, player);
|
||||
if(this.scheduledForDestruction) {
|
||||
clearTimeout(this.destructionTimeout);
|
||||
}
|
||||
};
|
||||
|
||||
RagDoll.prototype.beingReleased = function(player) {
|
||||
Parent.prototype.beingReleased.call(this, player);
|
||||
if(this.scheduledForDestruction) {
|
||||
this.delayedDestroy();
|
||||
}
|
||||
};
|
||||
|
||||
RagDoll.prototype.delayedDestroy = function() {
|
||||
this.scheduledForDestruction = true;
|
||||
this.destructionTimeout = setTimeout(this.destroy.bind(this), Settings.RAGDOLL_DESTRUCTION_TIME * 1000);
|
||||
};
|
||||
|
||||
RagDoll.prototype.destroy = function() {
|
||||
Nc.trigger("broadcastGameCommand", 'removeGameObject', {
|
||||
type: 'animated',
|
||||
uid: this.uid
|
||||
});
|
||||
Parent.prototype.destroy.call(this);
|
||||
};
|
||||
|
||||
return RagDoll;
|
||||
|
||||
});
|
||||
9
app/Game/Channel/GameObjects/Items/Skateboard.js
Executable file
9
app/Game/Channel/GameObjects/Items/Skateboard.js
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Items/Skateboard"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
|
||||
return Parent;
|
||||
|
||||
});
|
||||
9
app/Game/Channel/GameObjects/SpectatorDoll.js
Normal file
9
app/Game/Channel/GameObjects/SpectatorDoll.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/SpectatorDoll"
|
||||
],
|
||||
|
||||
function (Parent) {
|
||||
|
||||
return Parent;
|
||||
|
||||
});
|
||||
9
app/Game/Channel/GameObjects/Tile.js
Executable file
9
app/Game/Channel/GameObjects/Tile.js
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Tile"
|
||||
],
|
||||
|
||||
function(Parent) {
|
||||
|
||||
return Parent;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue