Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

parametrized player movement

  • Loading branch information...
commit 42bca33b7897f5824fc9ce000d51a34e0a867dc5 1 parent ae7dbe8
@KaeruCT authored
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,15 +202,15 @@ 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)) {
@@ -215,7 +218,7 @@ var CHROMAVORIAN = (function (C) {
// 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)) {
@@ -223,15 +226,22 @@ var CHROMAVORIAN = (function (C) {
}
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,7 +253,7 @@ var CHROMAVORIAN = (function (C) {
);
this.bBody.SetAwake(true);
}
-
+
this.open = true;
} else {
this.open = false;
@@ -251,8 +261,8 @@ var CHROMAVORIAN = (function (C) {
// 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);
Please sign in to comment.
Something went wrong with that request. Please try again.