Skip to content
Browse files

parametrized player movement

  • Loading branch information...
1 parent ae7dbe8 commit 42bca33b7897f5824fc9ce000d51a34e0a867dc5 @KaeruCT committed Jul 7, 2012
Showing with 21 additions and 11 deletions.
  1. +21 −11 entities.js
View
32 entities.js
@@ -111,8 +111,8 @@ var CHROMAVORIAN = (function (C) {
// XXX: testing particle effects
if (Math.random() * Math.abs(this.bBody.GetAngularVelocity()) > 10) {
- this.world.particles.add(this.x + Math.cos(theta) * this.radius,
- this.y + Math.sin(theta) * this.radius,
+ this.world.particles.add(this.x,
+ this.y,
Math.cos(theta) * Math.random() * 2,
Math.sin(theta) * Math.random() * 2,
this.color.copy(), 0.5);
@@ -164,6 +164,9 @@ var CHROMAVORIAN = (function (C) {
this.radius = 0.3;
this.restitution = 0.1;
+ this.hImpulse = 0.3;
+ this.vImpulse = 15;
+
this.color = new game.util.Color(255, 255, 255);
this.open = false;
};
@@ -199,39 +202,46 @@ var CHROMAVORIAN = (function (C) {
// input handling
if (game.input.isDown(game.input.RIGHT)) {
- this.bBody.ApplyImpulse(new game.b2Vec2(0.1, 0), new game.b2Vec2(this.x, this.y));
+ this.bBody.ApplyImpulse(new game.b2Vec2(this.hImpulse, 0), new game.b2Vec2(this.x, this.y));
av = this.bBody.GetAngularVelocity();
- this.bBody.SetAngularVelocity(av + 1.0);
+ this.bBody.SetAngularVelocity(av + this.hImpulse);
}
if (game.input.isDown(game.input.LEFT)) {
- this.bBody.ApplyImpulse(new game.b2Vec2(-0.1, 0), new game.b2Vec2(this.x, this.y));
+ this.bBody.ApplyImpulse(new game.b2Vec2(-this.hImpulse, 0), new game.b2Vec2(this.x, this.y));
av = this.bBody.GetAngularVelocity();
- this.bBody.SetAngularVelocity(av - 1.0);
+ this.bBody.SetAngularVelocity(av - this.hImpulse);
}
if (game.input.justPressed(game.input.UP)) {
// play jump sound
game.sound.play('jump');
- this.bBody.ApplyImpulse(new game.b2Vec2(0, -20), new game.b2Vec2(this.x, this.y));
+ this.bBody.ApplyImpulse(new game.b2Vec2(0, -this.vImpulse), new game.b2Vec2(this.x, this.y));
}
if (game.input.isDown(game.input.DOWN)) {
this.bBody.ApplyImpulse(new game.b2Vec2(0, 0.5), new game.b2Vec2(this.x, this.y));
}
if (game.input.justPressed(game.input.ACTION)) {
+ // stop closesound
+ game.sound.stop('close');
+
// play open sound
game.sound.play('open');
}
if (game.input.justReleased(game.input.ACTION)) {
- // play open sound
+ // stop open sound
+ game.sound.stop('open');
+
+ // play close sound
game.sound.play('close');
}
+
if (game.input.isDown(game.input.ACTION)) {
// wakeup nearby chromas so they may react to us being non-solid
if (!this.open) {
@@ -243,16 +253,16 @@ var CHROMAVORIAN = (function (C) {
);
this.bBody.SetAwake(true);
}
-
+
this.open = true;
} else {
this.open = false;
}
// additional open-only particles
if (this.open && Math.random() * Math.abs(this.bBody.GetAngularVelocity()) > 6) {
- this.world.particles.add(this.x + Math.cos(theta) * this.radius,
- this.y + Math.sin(theta) * this.radius,
+ this.world.particles.add(this.x,
+ this.y,
Math.cos(theta) * Math.random() * 2,
Math.sin(theta) * Math.random() * 2,
new game.util.Color(255, 255, 255), 0.5);

0 comments on commit 42bca33

Please sign in to comment.
Something went wrong with that request. Please try again.