Permalink
Browse files

adding more sounds

  • Loading branch information...
1 parent 5569a78 commit e2b7d8f25a852d5eb7ac546f501212f8a34a4e48 @gotosleep committed Apr 27, 2012
Showing with 27 additions and 4 deletions.
  1. +27 −4 js/redeye.js
  2. BIN sounds/abduct.wav
  3. BIN sounds/hurt.wav
View
@@ -75,7 +75,8 @@ $(document).ready(function () {
building:"sounds/building.wav",
planeExplode:"sounds/planeExplode.wav",
bullet:"sounds/bullet.wav",
- abduct:"sounds/abduct.wav"
+ abduct:"sounds/abduct.wav",
+ hurt:"sounds/hurt.wav"
});
Crafty.c('Attached', {
@@ -218,6 +219,7 @@ $(document).ready(function () {
return;
}
var beam = this;
+ Crafty.audio.playOnce("abduct");
$.each(this.hit("food"), function (index, value) {
var target = value.obj;
@@ -306,6 +308,7 @@ $(document).ready(function () {
_abduct:undefined,
Robo:function () {
this.requires("SpriteAnimation, Collision, Life");
+ this.hurtSound = "hurt";
this._resting = this.y;
//setup animations
this.animate("walk_left", 2, 0, 3)
@@ -474,27 +477,45 @@ $(document).ready(function () {
}
});
+ Crafty.audio.isPlaying = function (id) {
+ var sounds = this._elems[id];
+ if (sounds) {
+ for (var i = 0; i < sounds.length; ++i) {
+ var sound = sounds[i];
+ if (sound.currentTime > 0 && sound.ended === false) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ Crafty.audio.playOnce = function (id) {
+ !this.isPlaying(id) && this.play(id);
+ }
+
Crafty.c('Life', {
_points:10,
_maxLife:1,
_life:1,
_cost:1,
_power:1,
_deathSound:undefined,
+ hurtSound:undefined,
init:function () {
},
attack:function (other) {
other.hurt(this._power);
this.hurt(other.cost());
},
hurt:function (power) {
- if (power === undefined) {
- power = 1;
- }
+ power = power || 1;
this._life -= power;
this._notify();
if (this._life <= 0) {
this.die();
+ } else if (this.hurtSound) {
+ Crafty.audio.playOnce(this.hurtSound);
}
},
_notify:function () {
@@ -607,13 +628,15 @@ $(document).ready(function () {
.life(2)
.cost(5)
.deathSound("explode");
+ this.hurtSound = "hurt";
}
});
Crafty.c("Plane", {
init:function () {
this.requires("NPC, plane")
.deathSound("planeExplode");
+ this.hurtSound = "hurt";
}
});
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit e2b7d8f

Please sign in to comment.