Ejemplo n.º 1
0
	preStepPlayerZep: function(body) {
		if (body.thing.state.up && body.thing.go) {
			body.ApplyForce(ccp(0, 25), body.GetPosition());
		} else {
			body.ApplyForce(ccp(0, -15), body.GetPosition());
		}
		
		if (body.thing.state.nitro) {
			body.ApplyForce(ccp(30, 0), body.GetPosition());
		}
		
		var time = Date.now(),
			v = body.GetLinearVelocity();
		
		if (this.groups.puffs && time - this.lastCloudCheck > this.cloudCheckPeriod) {
			this.lastCloudCheck = time;
			
			var impact = 1000;
			
			for (var ii in this.groups.puffs) {
				var puff = this.groups.puffs[ii],
					sqD = geo.ccpLengthSQ(geo.ccpSub(body.thing.location, puff.location));
				
				// distance between centers is less than 4
				if (sqD < 25) {
					var shape1 = new box2d.b2CircleShape(puff.radius * puff.scale),
						t1 = new box2d.b2Transform,
						t2 = new box2d.b2Transform;
					
					t1.position.Set(puff.location.x, puff.location.y);
					t2.position.Set(body.thing.location.x, body.thing.location.y);
					
					if (box2d.b2Shape.TestOverlap(shape1, t1, body.GetFixtureList().GetShape(), t2)) {
						if (puff.dissolveTime) {
							puff.friction = 1 - puff.age / puff.dissolveTime + 0.01; 
						}
						var candidImpact = 0.05 / puff.friction / puff.friction * sqD;
						if (candidImpact < impact) impact = candidImpact;
					}
				}
			}
			
			if (impact < 1000) {
				if (Math.abs(v.x) > impact + this.puffFactor) v.x = impact * geo.sign(v.x);
				if (Math.abs(v.y) > impact + this.puffFactor) v.y = impact * geo.sign(v.y);
			}
		}

		body.thing.velocity = Math.floor(v.x * 10) / 10;
	},
Ejemplo n.º 2
0
	preStepZep: function(body) {
		var speedY = body.GetLinearVelocity().y,
			targetAngle = speedY > 0? 0.15 : -0.15,
			rotation = geo.closestRotation(body.thing.angle, targetAngle);
		
		if (Math.abs(rotation) > 0.05) {
			body.ApplyTorque(geo.sign(rotation)/3 + rotation * 2);
		}

		// compensate gravity
		body.ApplyForce(geo.ccpMult(this.world.GetGravity(), ccp(0, -body.GetMass())), body.thing.location);
		
		// engine pushes at full speed for 0 angle. To make effect stronger we use cos^2
		var cos = Math.cos(body.thing.angle),
			speed = this.thrust * Math.max(0, cos * cos);
		body.ApplyForce(geo.ccpMult(ccp(speed, 0), body.thing.direction), body.thing.location);
		
		// "roof" presses on all zeppelins, seed>-2 limits feedback
		var y = body.thing.location.y;
		if (y > this.roof && speedY > -2) {
			body.ApplyForce(ccp(0, -this.roof * (y-this.roof) * (y-this.roof)), body.thing.location);
		};
	},