mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed throwing and meter
This commit is contained in:
parent
86dcdf92df
commit
3a07d946b0
4 changed files with 84 additions and 45 deletions
|
|
@ -269,7 +269,15 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
|||
|
||||
var body = item.body;
|
||||
body.SetAwake(true);
|
||||
body.ApplyImpulse(new Box2D.Common.Math.b2Vec2(x * 3, -y * 3), body.GetPosition());
|
||||
|
||||
body.ApplyImpulse(
|
||||
new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE,
|
||||
-y * Settings.MAX_THROW_FORCE * 2 // 2 is to throw higher then far
|
||||
),
|
||||
body.GetLocalCenter()
|
||||
);
|
||||
body.SetAngularVelocity(5);
|
||||
};
|
||||
|
||||
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ function (Parent, Box2D, Settings) {
|
|||
this.options = options;
|
||||
Parent.call(this, physicsEngine, uid);
|
||||
this.createFixture();
|
||||
this.body.ResetMassData();
|
||||
}
|
||||
|
||||
Item.prototype = Object.create(Parent.prototype);
|
||||
|
|
@ -28,16 +29,21 @@ function (Parent, Box2D, Settings) {
|
|||
Item.prototype.createFixture = function () {
|
||||
|
||||
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
var w = this.options.width / 2 / Settings.RATIO;
|
||||
var h = this.options.height / 2 / Settings.RATIO;
|
||||
itemShape.SetAsOrientedBox(w, h, new Box2D.Common.Math.b2Vec2(0, -h));
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = this.options.height / Settings.RATIO;
|
||||
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(h/2)));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
fixtureDef.shape = itemShape;
|
||||
fixtureDef.density = Settings.ITEM_DENSITY;
|
||||
|
||||
var offset = 4,
|
||||
factor = 80;
|
||||
var density = ((this.options.weight + offset) / this.options.width / this.options.height) * factor;
|
||||
fixtureDef.density = density;
|
||||
fixtureDef.friction = Settings.ITEM_FRICTION;
|
||||
fixtureDef.restitution = Settings.ITEM_RESTITUTION;
|
||||
fixtureDef.isSensor = false;
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -104,16 +104,51 @@ define([
|
|||
// o o o
|
||||
|
||||
this.levelObject = {
|
||||
/*
|
||||
Material densities (g/cm^3):
|
||||
|
||||
wood: 0.63
|
||||
steel: 7.859
|
||||
banana: 0.95
|
||||
microwave: 3.744
|
||||
|
||||
*/
|
||||
items: [
|
||||
{
|
||||
name:'Banana',
|
||||
image:'banana.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:0.2,
|
||||
weight: 1,
|
||||
width:5,
|
||||
height:9,
|
||||
x:20,
|
||||
depth: 3,
|
||||
x:40,
|
||||
y:0,
|
||||
rotation: 0
|
||||
},
|
||||
{
|
||||
name:'Refridgerator',
|
||||
image:'fridge.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight: 10,
|
||||
width:31,
|
||||
height:53,
|
||||
x:120,
|
||||
y:0,
|
||||
rotation: 0
|
||||
},
|
||||
{
|
||||
name:'Microwave',
|
||||
image:'microwave.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight: 4,
|
||||
width:19,
|
||||
height:12,
|
||||
depth: 12,
|
||||
x:100,
|
||||
y:0,
|
||||
rotation: 0
|
||||
},
|
||||
|
|
@ -122,7 +157,7 @@ define([
|
|||
image:'cleaver_large.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:1.1,
|
||||
weight: 3,
|
||||
width:8,
|
||||
height:22,
|
||||
x:40,
|
||||
|
|
@ -134,7 +169,7 @@ define([
|
|||
image:'cleaver_small.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:0.8,
|
||||
weight:2,
|
||||
width:6,
|
||||
height:17,
|
||||
x:60,
|
||||
|
|
@ -146,43 +181,19 @@ define([
|
|||
image:'coffeemachine.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:3,
|
||||
weight:2.4,
|
||||
width:11,
|
||||
height:14,
|
||||
x:80,
|
||||
y:0,
|
||||
rotation: 0
|
||||
},
|
||||
{
|
||||
name:'Microwave',
|
||||
image:'microwave.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:7,
|
||||
width:19,
|
||||
height:12,
|
||||
x:100,
|
||||
y:0,
|
||||
rotation: 0
|
||||
},
|
||||
{
|
||||
name:'Refridgerator',
|
||||
image:'fridge.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:5,
|
||||
width:31,
|
||||
height:53,
|
||||
x:120,
|
||||
y:200,
|
||||
rotation: 0
|
||||
},
|
||||
{
|
||||
name:'Knife',
|
||||
image:'knife.gif',
|
||||
shape:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:0.3,
|
||||
weight:1.5,
|
||||
width:4,
|
||||
height:15,
|
||||
x:140,
|
||||
|
|
@ -190,7 +201,21 @@ define([
|
|||
rotation: 0
|
||||
}
|
||||
],
|
||||
tiles: [
|
||||
tiles: /*
|
||||
(function() {
|
||||
var tiles = [];
|
||||
for (var i = 0; i < 50; i++) {
|
||||
tiles.push({
|
||||
s:1,
|
||||
x:i,
|
||||
y:5
|
||||
})
|
||||
};
|
||||
return tiles;
|
||||
})()
|
||||
*/
|
||||
|
||||
[
|
||||
{s:1, x:1, y:1, r:0},
|
||||
{s:1, x:3, y:18},
|
||||
{s:1, x:37, y:27},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue