fixed throwing and meter

This commit is contained in:
Jeena 2014-01-10 17:25:46 +01:00
parent 86dcdf92df
commit 3a07d946b0
4 changed files with 84 additions and 45 deletions

View file

@ -5,7 +5,7 @@ define({
// BOX2D INITIALATORS // BOX2D INITIALATORS
BOX2D_WORLD_AABB_SIZE: 3000, BOX2D_WORLD_AABB_SIZE: 3000,
BOX2D_ALLOW_SLEEP: true, BOX2D_ALLOW_SLEEP: true,
BOX2D_GRAVITY: 16, BOX2D_GRAVITY: 26,
BOX2D_VELOCITY_ITERATIONS: 5, BOX2D_VELOCITY_ITERATIONS: 5,
BOX2D_POSITION_ITERATIONS: 5, BOX2D_POSITION_ITERATIONS: 5,
BOX2D_TIME_STEP: 1 / 60, BOX2D_TIME_STEP: 1 / 60,
@ -16,27 +16,27 @@ define({
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/', GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
GRAPHICS_SUBPATH_TILES: 'Tiles/', GRAPHICS_SUBPATH_TILES: 'Tiles/',
RATIO: 35, RATIO: 21, //35
TILE_SIZE: 15, //15 TILE_SIZE: 15, //15
CAMERA_IS_ORTHOGRAPHIC: true, CAMERA_IS_ORTHOGRAPHIC: true,
VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi', VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi',
// GAME PLAY // GAME PLAY
WALK_SPEED: 2.5, WALK_SPEED: 4,
RUN_SPEED: 4, RUN_SPEED: 6.4,
FLY_SPEED: 3.2, FLY_SPEED: 5.12,
JUMP_SPEED: 4.0, JUMP_SPEED: 70,
JUMP_UPLIFT: 0.05, MAX_THROW_FORCE: 15,
// restitution: bouncyness, friction: rubbing, density: mass // restitution: bouncyness, friction: rubbing, density: mass
TILE_FRICTION: 0.99, TILE_FRICTION: 0.99,
TILE_RESTITUTION: 0.1, TILE_RESTITUTION: 0.1,
PLAYER_DENSITY: 0.96, PLAYER_DENSITY: 3.68,
PLAYER_FRICTION: 5, PLAYER_FRICTION: 5,
PLAYER_MOTION_FRICTION: 0.1, PLAYER_MOTION_FRICTION: 0.1,
PLAYER_RESTITUTION: 0.0, PLAYER_RESTITUTION: 0.0,
PLAYER_LINEAR_DAMPING: .5, PLAYER_LINEAR_DAMPING: 0.8,
ITEM_DENSITY: 0.9, ITEM_DENSITY: 0.9,
ITEM_FRICTION: 0.99, ITEM_FRICTION: 0.99,

View file

@ -269,7 +269,15 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
var body = item.body; var body = item.body;
body.SetAwake(true); 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) { Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {

View file

@ -10,6 +10,7 @@ function (Parent, Box2D, Settings) {
this.options = options; this.options = options;
Parent.call(this, physicsEngine, uid); Parent.call(this, physicsEngine, uid);
this.createFixture(); this.createFixture();
this.body.ResetMassData();
} }
Item.prototype = Object.create(Parent.prototype); Item.prototype = Object.create(Parent.prototype);
@ -28,16 +29,21 @@ function (Parent, Box2D, Settings) {
Item.prototype.createFixture = function () { Item.prototype.createFixture = function () {
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape(); var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
var w = this.options.width / 2 / Settings.RATIO; var w = this.options.width / Settings.RATIO;
var h = this.options.height / 2 / Settings.RATIO; var h = this.options.height / Settings.RATIO;
itemShape.SetAsOrientedBox(w, h, new Box2D.Common.Math.b2Vec2(0, -h)); itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(h/2)));
var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
fixtureDef.shape = itemShape; 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.friction = Settings.ITEM_FRICTION;
fixtureDef.restitution = Settings.ITEM_RESTITUTION; fixtureDef.restitution = Settings.ITEM_RESTITUTION;
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
this.body.CreateFixture(fixtureDef); this.body.CreateFixture(fixtureDef);
} }

View file

@ -104,16 +104,51 @@ define([
// o o o // o o o
this.levelObject = { this.levelObject = {
/*
Material densities (g/cm^3):
wood: 0.63
steel: 7.859
banana: 0.95
microwave: 3.744
*/
items: [ items: [
{ {
name:'Banana', name:'Banana',
image:'banana.gif', image:'banana.gif',
shape:'rectangle', shape:'rectangle',
category:'kitchen', category:'kitchen',
weight:0.2, weight: 1,
width:5, width:5,
height:9, 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, y:0,
rotation: 0 rotation: 0
}, },
@ -122,7 +157,7 @@ define([
image:'cleaver_large.gif', image:'cleaver_large.gif',
shape:'rectangle', shape:'rectangle',
category:'kitchen', category:'kitchen',
weight:1.1, weight: 3,
width:8, width:8,
height:22, height:22,
x:40, x:40,
@ -134,7 +169,7 @@ define([
image:'cleaver_small.gif', image:'cleaver_small.gif',
shape:'rectangle', shape:'rectangle',
category:'kitchen', category:'kitchen',
weight:0.8, weight:2,
width:6, width:6,
height:17, height:17,
x:60, x:60,
@ -146,43 +181,19 @@ define([
image:'coffeemachine.gif', image:'coffeemachine.gif',
shape:'rectangle', shape:'rectangle',
category:'kitchen', category:'kitchen',
weight:3, weight:2.4,
width:11, width:11,
height:14, height:14,
x:80, x:80,
y:0, y:0,
rotation: 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', name:'Knife',
image:'knife.gif', image:'knife.gif',
shape:'rectangle', shape:'rectangle',
category:'kitchen', category:'kitchen',
weight:0.3, weight:1.5,
width:4, width:4,
height:15, height:15,
x:140, x:140,
@ -190,7 +201,21 @@ define([
rotation: 0 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:1, y:1, r:0},
{s:1, x:3, y:18}, {s:1, x:3, y:18},
{s:1, x:37, y:27}, {s:1, x:37, y:27},