mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added ragdoll with one limb
This commit is contained in:
parent
b55f6d58fc
commit
e488beb203
18 changed files with 511 additions and 132 deletions
|
|
@ -23,6 +23,9 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
s:83,
|
||||
d:68,
|
||||
|
||||
f:70,
|
||||
g:71,
|
||||
|
||||
up: 38,
|
||||
left: 37,
|
||||
down: 40,
|
||||
|
|
@ -51,6 +54,9 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
this.keyboardInput.registerKey(keys.space, 'jump');
|
||||
|
||||
this.keyboardInput.registerKey(keys.tab, 'showInfo', 'hideInfo');
|
||||
|
||||
this.keyboardInput.registerKey(keys.f, 'handActionLeft');
|
||||
this.keyboardInput.registerKey(keys.g, 'handActionRight');
|
||||
}
|
||||
|
||||
PlayerController.prototype.moveLeft = function () {
|
||||
|
|
@ -79,6 +85,14 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
|
|||
NotificationCenter.trigger('sendGameCommand', 'lookAt', options);
|
||||
};
|
||||
|
||||
PlayerController.prototype.handActionLeft = function() {
|
||||
this.handActionRequest(-0.5, 0.5);
|
||||
};
|
||||
|
||||
PlayerController.prototype.handActionRight = function() {
|
||||
this.handActionRequest(0.5, 0.5);
|
||||
};
|
||||
|
||||
PlayerController.prototype.handActionRequest = function(x, y) {
|
||||
var options = {x:x, y:y};
|
||||
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,10 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
|
||||
NotificationCenter.trigger("view/createAnimatedMesh", texturePaths, callback, {
|
||||
visible: false,
|
||||
pivot: "mb",
|
||||
pivot: {
|
||||
x: 35/2,
|
||||
y: 40
|
||||
},
|
||||
width: 35,
|
||||
height: 40
|
||||
});
|
||||
|
|
@ -85,7 +88,10 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
|||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
}
|
||||
NotificationCenter.trigger("view/createMesh", texturePath, callback, {
|
||||
pivot: "mb",
|
||||
pivot: {
|
||||
x: 5,
|
||||
y: 12
|
||||
},
|
||||
width: 10,
|
||||
height: 12
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,7 +31,10 @@ function (Parent, Settings, NotificationCenter) {
|
|||
{
|
||||
width: this.options.width,
|
||||
height: this.options.height,
|
||||
pivot: "mb"
|
||||
pivot: {
|
||||
x: this.options.width / 2,
|
||||
y: this.options.height
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
|||
104
app/Game/Client/GameObjects/Items/RagDoll.js
Normal file
104
app/Game/Client/GameObjects/Items/RagDoll.js
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Items/RagDoll",
|
||||
"Game/Core/GameObjects/Item",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Parent, CoreItem, Settings, NotificationCenter) {
|
||||
|
||||
function RagDoll(physicsEngine, uid, options) {
|
||||
this.limbMeshes = {};
|
||||
this.baseMeshName = "chest";
|
||||
this.characterName = "Chuck";
|
||||
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
}
|
||||
|
||||
RagDoll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
RagDoll.prototype.createMesh = function() {
|
||||
this.createLimbMesh("chest");
|
||||
this.createLimbMesh("head");
|
||||
};
|
||||
|
||||
RagDoll.prototype.createLimbMesh = function(name) {
|
||||
var self = this;
|
||||
var texturePath = Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_CHARACTERS + '/'
|
||||
+ this.characterName + '/';
|
||||
|
||||
var callback = function(mesh) {
|
||||
console.log(name, self.baseMeshName)
|
||||
if(name == self.baseMeshName) {
|
||||
self.mesh = mesh;
|
||||
} else {
|
||||
self.limbMeshes[name] = mesh;
|
||||
}
|
||||
|
||||
NotificationCenter.trigger("view/addMesh", mesh);
|
||||
}
|
||||
|
||||
NotificationCenter.trigger("view/createMesh",
|
||||
texturePath + name + ".png",
|
||||
callback,
|
||||
{
|
||||
width: this.options.limbs[name].width,
|
||||
height: this.options.limbs[name].height,
|
||||
pivot: {
|
||||
x: this.options.limbs[name].width / 2,
|
||||
y: this.options.limbs[name].height / 2
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
RagDoll.prototype.render = function() {
|
||||
Parent.prototype.render.call(this);
|
||||
|
||||
if(this.limbs) {
|
||||
for(var name in this.limbMeshes) {
|
||||
if(this.limbs[name]) {
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.limbMeshes[name],
|
||||
{
|
||||
x: this.limbs[name].GetPosition().x * Settings.RATIO,
|
||||
y: this.limbs[name].GetPosition().y * Settings.RATIO,
|
||||
rotation: this.limbs[name].GetAngle()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RagDoll.prototype.flip = function(direction) {
|
||||
var oldFlipDirection = this.flipDirection;
|
||||
|
||||
// Parent of parent
|
||||
CoreItem.prototype.flip.call(this, direction);
|
||||
|
||||
if(oldFlipDirection != direction) {
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.mesh,
|
||||
{
|
||||
xScale: direction
|
||||
}
|
||||
);
|
||||
|
||||
for (var name in this.limbMeshes) {
|
||||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.limbMeshes[name],
|
||||
{
|
||||
xScale: direction
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
return RagDoll;
|
||||
|
||||
});
|
||||
|
|
@ -35,7 +35,11 @@ function (Parent, Settings, NotificationCenter) {
|
|||
callback,
|
||||
{
|
||||
width: Settings.TILE_SIZE,
|
||||
height: Settings.TILE_SIZE
|
||||
height: Settings.TILE_SIZE,
|
||||
pivot: {
|
||||
x: Settings.TILE_SIZE / 2 * Settings.TILE_RATIO,
|
||||
y: Settings.TILE_SIZE / 2 * Settings.TILE_RATIO
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
@ -50,8 +54,8 @@ function (Parent, Settings, NotificationCenter) {
|
|||
NotificationCenter.trigger("view/updateMesh",
|
||||
this.mesh,
|
||||
{
|
||||
x: this.body.GetPosition().x * Settings.RATIO - Settings.TILE_SIZE / 2,
|
||||
y: this.body.GetPosition().y * Settings.RATIO - Settings.TILE_SIZE / 2
|
||||
x: this.body.GetPosition().x * Settings.RATIO,
|
||||
y: this.body.GetPosition().y * Settings.RATIO
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,26 +121,12 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
|||
if (options.x) mesh.position.x = options.x;
|
||||
if (options.y) mesh.position.y = options.y;
|
||||
if (options.rotation) mesh.rotation = options.rotation;
|
||||
if (options.xScale) mesh.scale.x = options.xScale;
|
||||
if (options.yScale) mesh.scale.y = options.yScale;
|
||||
if (options.width) mesh.width = options.width;
|
||||
if (options.height) mesh.height = options.height;
|
||||
if (options.xScale) mesh.width = Math.abs(mesh.width) * options.xScale;
|
||||
if (options.yScale) mesh.scale.y = options.yScale;
|
||||
if (options.visible === true || options.visible === false) mesh.visible = options.visible;
|
||||
if (options.pivot) {
|
||||
if(options.pivot.length) {
|
||||
switch(options.pivot) {
|
||||
case "lb":
|
||||
mesh.pivot.x = mesh.width / 2;
|
||||
mesh.pivot.y = mesh.height / 2;
|
||||
break;
|
||||
default:
|
||||
mesh.pivot.x = mesh.width / 2;
|
||||
mesh.pivot.y = mesh.height;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
if (options.pivot) mesh.pivot = new PIXI.Point(options.pivot.x, options.pivot.y);
|
||||
}
|
||||
|
||||
PixiView.prototype.calculateCameraPosition = function() {
|
||||
|
|
|
|||
|
|
@ -1,59 +1,68 @@
|
|||
define({
|
||||
STAGE_WIDTH: 600,
|
||||
STAGE_HEIGHT: 400,
|
||||
define(function() {
|
||||
|
||||
// BOX2D INITIALATORS
|
||||
BOX2D_WORLD_AABB_SIZE: 3000,
|
||||
BOX2D_ALLOW_SLEEP: true,
|
||||
BOX2D_GRAVITY: 26,
|
||||
BOX2D_VELOCITY_ITERATIONS: 5,
|
||||
BOX2D_POSITION_ITERATIONS: 5,
|
||||
BOX2D_TIME_STEP: 1 / 60,
|
||||
var Settings = {
|
||||
STAGE_WIDTH: 600,
|
||||
STAGE_HEIGHT: 400,
|
||||
|
||||
// PATHS
|
||||
GRAPHICS_PATH: 'static/img/',
|
||||
GRAPHICS_SUBPATH_ITEMS: 'Items/',
|
||||
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
|
||||
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
||||
MAPS_PATH: 'static/maps/tiled/',
|
||||
DEFAULT_LEVELS: ['stones2'],
|
||||
// BOX2D INITIALATORS
|
||||
BOX2D_WORLD_AABB_SIZE: 3000,
|
||||
BOX2D_ALLOW_SLEEP: true,
|
||||
BOX2D_GRAVITY: 26,
|
||||
BOX2D_VELOCITY_ITERATIONS: 5,
|
||||
BOX2D_POSITION_ITERATIONS: 5,
|
||||
BOX2D_TIME_STEP: 1 / 60,
|
||||
|
||||
RATIO: 21, //35
|
||||
OBJECT_RATIO: 20 / 25,
|
||||
TILE_SIZE: 20, //15, 25 is original picture
|
||||
CAMERA_IS_ORTHOGRAPHIC: true,
|
||||
VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi',
|
||||
// PATHS
|
||||
GRAPHICS_PATH: 'static/img/',
|
||||
GRAPHICS_SUBPATH_ITEMS: 'Items/',
|
||||
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
|
||||
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
||||
MAPS_PATH: 'static/maps/tiled/',
|
||||
DEFAULT_LEVELS: ['debug', 'stones2'],
|
||||
|
||||
// GAME PLAY
|
||||
WALK_SPEED: 4,
|
||||
RUN_SPEED: 8,
|
||||
FLY_SPEED: 6.2,
|
||||
JUMP_SPEED: 20,
|
||||
MAX_THROW_FORCE: 18,
|
||||
MAX_THROW_ANGULAR_VELOCITY: 8,
|
||||
MAX_RUNNING_WEIGHT: 9,
|
||||
RATIO: 21, //35
|
||||
// original tile size is 25 but we want it to resize to 20
|
||||
ORIGINAL_TILE_SIZE: 25,
|
||||
TILE_SIZE: 20,
|
||||
CAMERA_IS_ORTHOGRAPHIC: true,
|
||||
VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi',
|
||||
|
||||
// restitution: bouncyness, friction: rubbing, density: mass
|
||||
TILE_FRICTION: 0.99,
|
||||
TILE_RESTITUTION: 0.1,
|
||||
// GAME PLAY
|
||||
WALK_SPEED: 4,
|
||||
RUN_SPEED: 8,
|
||||
FLY_SPEED: 6.2,
|
||||
JUMP_SPEED: 20,
|
||||
MAX_THROW_FORCE: 18,
|
||||
MAX_THROW_ANGULAR_VELOCITY: 0,
|
||||
MAX_RUNNING_WEIGHT: 9,
|
||||
RESPAWN_TIME: 0.5,
|
||||
|
||||
PLAYER_DENSITY: 3.68,
|
||||
PLAYER_FRICTION: 5,
|
||||
PLAYER_MOTION_FRICTION: 0.1,
|
||||
PLAYER_RESTITUTION: 0.0,
|
||||
PLAYER_LINEAR_DAMPING: 0.8,
|
||||
// restitution: bouncyness, friction: rubbing, density: mass
|
||||
TILE_FRICTION: 0.99,
|
||||
TILE_RESTITUTION: 0.1,
|
||||
|
||||
ITEM_DENSITY: 0.9,
|
||||
ITEM_FRICTION: 0.99,
|
||||
ITEM_RESTITUTION: 0.02,
|
||||
PLAYER_DENSITY: 3.68,
|
||||
PLAYER_FRICTION: 5,
|
||||
PLAYER_MOTION_FRICTION: 0.1,
|
||||
PLAYER_RESTITUTION: 0.0,
|
||||
PLAYER_LINEAR_DAMPING: 0.8,
|
||||
|
||||
// BROWSER
|
||||
CANVAS_DOM_ID: 'canvasContainer',
|
||||
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
||||
USE_WEBGL: true,
|
||||
ITEM_DENSITY: 0.9,
|
||||
ITEM_FRICTION: 0.99,
|
||||
ITEM_RESTITUTION: 0.02,
|
||||
|
||||
// NETWORKING
|
||||
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
||||
NETWORK_LOG_INCOMING: false,
|
||||
NETWORK_LOG_OUTGOING: false
|
||||
})
|
||||
// BROWSER
|
||||
CANVAS_DOM_ID: 'canvasContainer',
|
||||
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
||||
USE_WEBGL: true,
|
||||
|
||||
// NETWORKING
|
||||
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
||||
NETWORK_LOG_INCOMING: false,
|
||||
NETWORK_LOG_OUTGOING: false
|
||||
}
|
||||
|
||||
Settings.TILE_RATIO = Settings.ORIGINAL_TILE_SIZE / Settings.TILE_SIZE;
|
||||
|
||||
return Settings;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
this.holdingJoint = null;
|
||||
this.holdingItem = null;
|
||||
|
||||
this.ragDoll = {head: null, body: null};
|
||||
|
||||
this.createFixtures();
|
||||
this.body.SetActive(false);
|
||||
}
|
||||
|
|
@ -290,16 +292,16 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
this.holdingJoint = null;
|
||||
}
|
||||
|
||||
var p = this.body.GetPosition();
|
||||
this.holdingItem.body.SetPosition(new Box2D.Common.Math.b2Vec2(
|
||||
p.x + ((this.holdingItem.options.width / Settings.RATIO / 2 + this.width / 2 / Settings.RATIO) * this.lookDirection),
|
||||
p.y - 1 // 1m in the air
|
||||
));
|
||||
this.holdingItem.flip(this.lookDirection);
|
||||
this.holdingItem.body.SetAngle((this.holdingItem.options.grabAngle || 0) * this.lookDirection);
|
||||
var bodyPosition = this.body.GetPosition();
|
||||
var handPosition = new Box2D.Common.Math.b2Vec2(
|
||||
bodyPosition.x + ((this.width / 2 / Settings.RATIO) * this.lookDirection),
|
||||
bodyPosition.y - this.height / 3 * 2 / Settings.RATIO // 2/3 of the body height
|
||||
);
|
||||
|
||||
this.holdingItem.reposition(handPosition, this.lookDirection);
|
||||
|
||||
var jointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
|
||||
jointDef.Initialize(this.body, this.holdingItem.body, this.holdingItem.body.GetWorldCenter());
|
||||
jointDef.Initialize(this.body, this.holdingItem.body, this.holdingItem.getGrabPoint());
|
||||
|
||||
this.holdingJoint = this.body.GetWorld().CreateJoint(jointDef);
|
||||
}
|
||||
|
|
@ -310,17 +312,7 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
this.holdingJoint = null;
|
||||
this.holdingItem = null;
|
||||
|
||||
var body = item.body;
|
||||
body.SetAwake(true);
|
||||
|
||||
body.ApplyImpulse(
|
||||
new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE,
|
||||
-y * Settings.MAX_THROW_FORCE * 1.5 // 1.5 is to throw higher then far
|
||||
),
|
||||
body.GetLocalCenter()
|
||||
);
|
||||
body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x); //
|
||||
item.throw(x, y);
|
||||
};
|
||||
|
||||
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/Options",
|
||||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Settings) {
|
||||
function (Parent, Box2D, Options, Settings) {
|
||||
|
||||
function Item(physicsEngine, uid, options) {
|
||||
this.options = {
|
||||
category: options.category,
|
||||
image: options.image,
|
||||
name: options.name,
|
||||
type: options.type,
|
||||
var floatOptions = {
|
||||
grabAngle: parseFloat(options.grabAngle),
|
||||
weight: parseFloat(options.weight),
|
||||
width: parseFloat(options.width),
|
||||
|
|
@ -21,6 +18,9 @@ function (Parent, Box2D, Settings) {
|
|||
x: parseFloat(options.x),
|
||||
y: parseFloat(options.y)
|
||||
};
|
||||
|
||||
this.options = Options.merge(floatOptions, options);
|
||||
|
||||
Parent.call(this, physicsEngine, uid);
|
||||
this.createFixture();
|
||||
this.body.ResetMassData();
|
||||
|
|
@ -40,9 +40,7 @@ function (Parent, Box2D, Settings) {
|
|||
return bodyDef;
|
||||
}
|
||||
|
||||
Item.prototype.createFixture = function () {
|
||||
var self = this;
|
||||
|
||||
Item.prototype.getFixtureDef = function() {
|
||||
var itemShape;
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = this.options.height / Settings.RATIO;
|
||||
|
|
@ -77,6 +75,11 @@ function (Parent, Box2D, Settings) {
|
|||
onCollisionChange: this.onCollisionChange.bind(this)
|
||||
}
|
||||
|
||||
return fixtureDef;
|
||||
};
|
||||
|
||||
Item.prototype.createFixture = function () {
|
||||
var fixtureDef = this.getFixtureDef();
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
}
|
||||
|
||||
|
|
@ -98,6 +101,42 @@ function (Parent, Box2D, Settings) {
|
|||
// overwrite if necessary
|
||||
};
|
||||
|
||||
Item.prototype.reposition = function(handPosition, direction) {
|
||||
var position = new Box2D.Common.Math.b2Vec2(
|
||||
handPosition.x + ((this.options.width / Settings.RATIO / 2) * direction),
|
||||
handPosition.y
|
||||
)
|
||||
this.body.SetPosition(position);
|
||||
this.flip(direction);
|
||||
this.body.SetAngle((this.options.grabAngle || 0) * direction);
|
||||
};
|
||||
|
||||
Item.prototype.getGrabPoint = function() {
|
||||
return this.body.GetWorldCenter();
|
||||
};
|
||||
|
||||
Item.prototype.throw = function(x, y) {
|
||||
var body = this.body;
|
||||
body.SetAwake(true);
|
||||
/*
|
||||
body.ApplyImpulse(
|
||||
new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE,
|
||||
-y * Settings.MAX_THROW_FORCE * 1.5 // 1.5 is to throw higher then far
|
||||
),
|
||||
body.GetLocalCenter()
|
||||
);
|
||||
*/
|
||||
|
||||
var vector = new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE,
|
||||
-y * Settings.MAX_THROW_FORCE * 1.5 // 1.5 is to throw higher then far
|
||||
);
|
||||
this.body.SetLinearVelocity(vector);
|
||||
|
||||
body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
|
||||
};
|
||||
|
||||
return Item;
|
||||
|
||||
});
|
||||
197
app/Game/Core/GameObjects/Items/RagDoll.js
Normal file
197
app/Game/Core/GameObjects/Items/RagDoll.js
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Settings) {
|
||||
|
||||
function RagDoll(physicsEngine, uid, options) {
|
||||
|
||||
// Sensor size
|
||||
options.width = 20;
|
||||
options.height = 40;
|
||||
|
||||
options.limbs = {};
|
||||
options.limbs.chest = {
|
||||
width: 6,
|
||||
height: 12,
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
options.limbs.head = {
|
||||
width: 10,
|
||||
height: 12,
|
||||
x: 0,
|
||||
y: - options.limbs.chest.height / 2 - 5
|
||||
};
|
||||
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
this.createSensor();
|
||||
|
||||
this.limbs = {
|
||||
head: null
|
||||
};
|
||||
this.addHead();
|
||||
|
||||
}
|
||||
|
||||
RagDoll.prototype = Object.create(Parent.prototype);
|
||||
|
||||
RagDoll.prototype.getId = function() {
|
||||
return 1; parseInt(this.uid.split("-")[1], 10);
|
||||
};
|
||||
|
||||
RagDoll.prototype.getBodyDef = function() {
|
||||
var bodyDef = Parent.prototype.getBodyDef.call(this);
|
||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||
//bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
|
||||
return bodyDef;
|
||||
};
|
||||
|
||||
RagDoll.prototype.getFixtureDef = function() {
|
||||
var fixtureDef = Parent.prototype.getFixtureDef.call(this);
|
||||
fixtureDef.density = Settings.PLAYER_DENSITY;
|
||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
||||
fixtureDef.filter.groupIndex = -this.getId();
|
||||
|
||||
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
shape.SetAsOrientedBox(
|
||||
this.options.limbs.chest.width / 2 / Settings.RATIO,
|
||||
this.options.limbs.chest.height / 2 / Settings.RATIO,
|
||||
new Box2D.Common.Math.b2Vec2(0, 0)
|
||||
);
|
||||
|
||||
fixtureDef.shape = shape;
|
||||
|
||||
return fixtureDef;
|
||||
};
|
||||
|
||||
RagDoll.prototype.createSensor = function() {
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = this.options.height / Settings.RATIO;
|
||||
|
||||
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, 0));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
fixtureDef.shape = itemShape;
|
||||
fixtureDef.isSensor = true;
|
||||
|
||||
fixtureDef.userData = {
|
||||
onCollisionChange: this.onCollisionChange.bind(this)
|
||||
}
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
};
|
||||
|
||||
RagDoll.prototype.destroy = function() {
|
||||
Parent.prototype.destroy.call(this);
|
||||
// remove head!!11
|
||||
};
|
||||
|
||||
RagDoll.prototype.addHead = function() {
|
||||
var x = this.options.x + this.options.limbs.head.x,
|
||||
y = this.options.y + this.options.limbs.head.y;
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.position.x = x / Settings.RATIO;
|
||||
bodyDef.position.y = y / Settings.RATIO;
|
||||
bodyDef.angle = 0;
|
||||
|
||||
var shape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
shape.SetRadius(this.options.limbs.head.width / 2 / Settings.RATIO);
|
||||
shape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 0));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
fixtureDef.density = Settings.PLAYER_DENSITY;
|
||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
||||
fixtureDef.shape = shape;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.filter.groupIndex = -this.getId();
|
||||
|
||||
var head = this.body.GetWorld().CreateBody(bodyDef);
|
||||
head.CreateFixture(fixtureDef);
|
||||
|
||||
this.limbs.head = head;
|
||||
|
||||
this.attachHead();
|
||||
};
|
||||
|
||||
RagDoll.prototype.attachHead = function() {
|
||||
var chestPosition = this.body.GetPosition();
|
||||
|
||||
var x = chestPosition.x + this.options.limbs.head.x / Settings.RATIO,
|
||||
y = chestPosition.y + this.options.limbs.head.y / Settings.RATIO;
|
||||
|
||||
var head = this.limbs.head;
|
||||
head.SetPosition(new Box2D.Common.Math.b2Vec2(x, y));
|
||||
head.SetAngle(0);
|
||||
|
||||
var jointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
|
||||
jointDef.enableMotor = false;
|
||||
|
||||
var point = chestPosition;
|
||||
//point.y -= this.options.limbs.chest.height / 2 / Settings.RATIO;
|
||||
jointDef.Initialize(this.body, head, point);
|
||||
jointDef.lowerAngle = -0.25 * Box2D.Common.b2Settings.b2_pi; // -45 degrees
|
||||
jointDef.upperAngle = 0.25 * Box2D.Common.b2Settings.b2_pi; // 45 degrees
|
||||
jointDef.enableLimit = true;
|
||||
|
||||
this.body.GetWorld().CreateJoint(jointDef);
|
||||
};
|
||||
|
||||
RagDoll.prototype.detachHead = function() {
|
||||
var joint = this.limbs.head.GetJointList().joint;
|
||||
if(joint) {
|
||||
this.body.GetWorld().DestroyJoint(joint);
|
||||
}
|
||||
};
|
||||
|
||||
RagDoll.prototype.reposition = function(handPosition, direction) {
|
||||
Parent.prototype.reposition.call(this, handPosition, direction);
|
||||
|
||||
var chestPosition = this.body.GetPosition();
|
||||
|
||||
var position = new Box2D.Common.Math.b2Vec2(
|
||||
chestPosition.x + this.options.limbs.head.x / Settings.RATIO,
|
||||
chestPosition.y + this.options.limbs.head.y / Settings.RATIO
|
||||
)
|
||||
this.limbs.head.SetPosition(position);
|
||||
this.limbs.head.SetAngle((this.options.grabAngle || 0) * direction);
|
||||
};
|
||||
|
||||
RagDoll.prototype.throw = function(x, y) {
|
||||
Parent.prototype.throw.call(this, x, y);
|
||||
|
||||
var limbDampingFactor = 1;
|
||||
|
||||
for(var name in this.limbs) {
|
||||
var body = this.limbs[name];
|
||||
body.SetAwake(true);
|
||||
/*
|
||||
body.ApplyImpulse(
|
||||
new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE * limbDampingFactor,
|
||||
-y * Settings.MAX_THROW_FORCE * 1.5 *limbDampingFactor // 1.5 is to throw higher then far
|
||||
),
|
||||
body.GetLocalCenter()
|
||||
);
|
||||
*/
|
||||
|
||||
var vector = new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE * limbDampingFactor,
|
||||
-y * Settings.MAX_THROW_FORCE * 1.5 *limbDampingFactor // 1.5 is to throw higher then far
|
||||
);
|
||||
this.body.SetLinearVelocity(vector);
|
||||
// body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
|
||||
}
|
||||
};
|
||||
|
||||
return RagDoll;
|
||||
|
||||
});
|
||||
|
|
@ -6,9 +6,10 @@ define([
|
|||
"Game/" + GLOBALS.context + "/Collision/Detector",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Tile",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard"
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll"
|
||||
|
||||
], function (Settings, Box2D, NotificationCenter, Exception, CollisionDetector, Tile, Item, Skateboard) {
|
||||
], function (Settings, Box2D, NotificationCenter, Exception, CollisionDetector, Tile, Item, Skateboard, RagDoll) {
|
||||
|
||||
function Level (uid, engine, gameObjects) {
|
||||
this.uid = uid;
|
||||
|
|
@ -64,21 +65,23 @@ define([
|
|||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var options = items[i];
|
||||
var item;
|
||||
var uid = "item-" + i;
|
||||
|
||||
switch(options.type) {
|
||||
case 'skateboard':
|
||||
item = new Skateboard(this.engine, uid, options);
|
||||
break;
|
||||
default:
|
||||
item = new Item(this.engine, uid, options);
|
||||
break
|
||||
}
|
||||
var item = this.createItem(uid, options);
|
||||
this.gameObjects.animated.push(item);
|
||||
};
|
||||
};
|
||||
|
||||
Level.prototype.createItem = function(uid, options) {
|
||||
switch(options.type) {
|
||||
case 'skateboard':
|
||||
return new Skateboard(this.engine, uid, options);
|
||||
case 'ragdoll':
|
||||
return new RagDoll(this.engine, uid, options);
|
||||
default:
|
||||
return new Item(this.engine, uid, options);
|
||||
}
|
||||
};
|
||||
|
||||
Level.prototype.getRandomSpawnPoint = function() {
|
||||
throw new Error("Level not loaded.");
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -60,19 +60,10 @@ define([
|
|||
for (var i = 0; i < objects.length; i++) {
|
||||
var object = objects[i];
|
||||
var options = object.properties;
|
||||
options.x = object.x * Settings.OBJECT_RATIO;
|
||||
options.y = object.y * Settings.OBJECT_RATIO;
|
||||
var item;
|
||||
options.x = object.x / Settings.TILE_RATIO;
|
||||
options.y = object.y / Settings.TILE_RATIO;
|
||||
var uid = "item-" + i;
|
||||
|
||||
switch(options.type) {
|
||||
case 'skateboard':
|
||||
item = new Skateboard(this.engine, uid, options);
|
||||
break;
|
||||
default:
|
||||
item = new Item(this.engine, uid, options);
|
||||
break
|
||||
}
|
||||
var item = this.createItem(uid, options);
|
||||
this.gameObjects.animated.push(item);
|
||||
};
|
||||
};
|
||||
|
|
@ -99,8 +90,8 @@ define([
|
|||
var object = spawnLayer.objects[parseInt(Math.random() * (size -1), 10)];
|
||||
|
||||
return {
|
||||
x: object.x * Settings.OBJECT_RATIO,
|
||||
y: object.y * Settings.OBJECT_RATIO
|
||||
x: object.x / Settings.TILE_RATIO,
|
||||
y: object.y / Settings.TILE_RATIO
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,15 +67,15 @@ function (Doll, Settings, NotificationCenter) {
|
|||
|
||||
Player.prototype.grab = function(item) {
|
||||
if(!this.isSpawned) return false;
|
||||
item.beingGrabbed(this);
|
||||
this.doll.grab(item);
|
||||
item.beingGrabbed(this);
|
||||
this.holdingItem = item;
|
||||
};
|
||||
|
||||
Player.prototype.throw = function(x, y, item) {
|
||||
if(!this.isSpawned) return false;
|
||||
item.beingReleased(this);
|
||||
this.doll.throw(item, x, y);
|
||||
item.beingReleased(this);
|
||||
this.holdingItem = null;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
};
|
||||
|
||||
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", message);
|
||||
}, 5000);
|
||||
}, Settings.RESPAWN_TIME * 1000);
|
||||
};
|
||||
|
||||
GameController.prototype.createPlayer = function(user) {
|
||||
|
|
|
|||
9
app/Game/Server/GameObjects/Items/RagDoll.js
Normal file
9
app/Game/Server/GameObjects/Items/RagDoll.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/Items/RagDoll"
|
||||
],
|
||||
|
||||
function (Parent) {
|
||||
|
||||
return Parent;
|
||||
|
||||
});
|
||||
|
|
@ -33,7 +33,7 @@ function (Exception) {
|
|||
if(options[key].constructor !== Object) {
|
||||
preset[key] = options[key];
|
||||
} else {
|
||||
preset[key] = mergeOptions(options[key], preset[key]);
|
||||
preset[key] = Options.prototype.merge.call(this, options[key], preset[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
static/img/Items/graveyard/chest.png
Executable file
BIN
static/img/Items/graveyard/chest.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 257 B |
|
|
@ -216,6 +216,28 @@
|
|||
"x":1222.774,
|
||||
"y":33.814666666667
|
||||
},
|
||||
{
|
||||
"height":0,
|
||||
"name":"",
|
||||
"properties":
|
||||
{
|
||||
"category":"graveyard",
|
||||
"grabAngle":"-0.5",
|
||||
"height":"12",
|
||||
"image":"chest.png",
|
||||
"name":"RagDoll",
|
||||
"rotation":"0",
|
||||
"type":"ragdoll",
|
||||
"weight":"5",
|
||||
"width":"6"
|
||||
},
|
||||
"rotation":0,
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":250.0,
|
||||
"y":186.0
|
||||
},
|
||||
{
|
||||
"height":0,
|
||||
"name":"",
|
||||
|
|
@ -651,7 +673,7 @@
|
|||
"type":"",
|
||||
"visible":true,
|
||||
"width":0,
|
||||
"x":250.60285170588,
|
||||
"x":550.60285170588,
|
||||
"y":186.328663790974
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue