Ver Fonte

Some sounds

Josh Engebretson há 11 anos atrás
pai
commit
68596434ab

+ 8 - 1
PhysicsPlatformer/Resources/Components/Avatar.js

@@ -5,13 +5,14 @@ ThePlayer = self;
 
 var node = self.node;
 
+// Resources
 var animationSet = cache.getResource("AnimationSet2D", "Sprites/Hero/Hero.scml");
+var jumpSound = cache.getResource("Sound","Sounds/Jump13.ogg");
 
 var sprite = node.createComponent("AnimatedSprite2D");
 sprite.setAnimation(animationSet, "Idle");
 sprite.setLayer(100);
 
-
 camera.zoom = .9;
 
 node.setPosition(PlayerSpawnPoint);
@@ -56,6 +57,9 @@ self.onPhysicsEndContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 
 function start() {
 
+    self.soundSource = node.createComponent("SoundSource");
+    self.soundSource.soundType = Atomic.SOUND_EFFECT;
+
     self.listenToEvent(null, "PhysicsBeginContact2D", self.onPhysicsBeginContact2D);
     self.listenToEvent(null, "PhysicsEndContact2D", self.onPhysicsEndContact2D);
 }
@@ -175,6 +179,9 @@ function handleInput(timeStep) {
         circle.friction = 0.0;
 
     if (jump && contactCount) {
+            //soundSource.gain = 0.75;
+        self.soundSource.play(jumpSound );
+
         vel[1] = 0;
         body.linearVelocity = vel;
         body.applyLinearImpulse([0, 3], pos, true);

+ 35 - 2
PhysicsPlatformer/Resources/Components/Coin.js

@@ -2,13 +2,15 @@
 keepAlive = typeof(keepAlive) == "undefined" ? [] : keepAlive;
 keepAlive.push(self);
 
-
 var glmatrix = require("gl-matrix");
 var vec2 = glmatrix.vec2;
 
 var node = self.node;
 
+// Resources
 var animationSet = cache.getResource("AnimationSet2D", "Sprites/GoldIcon.scml");
+var coinSound = cache.getResource("Sound","Sounds/Pickup_Coin8.ogg");
+var coinBounceSound = cache.getResource("Sound","Sounds/Coin_Bounce.ogg");
 
 var sprite = node.createComponent("AnimatedSprite2D");
 sprite.setAnimation(animationSet, "idle");
@@ -18,12 +20,43 @@ var activated = false;
 
 var body;
 
-self.onPlayerHit = function() {
+function onPlayerHit() {
     
     // sprite enabled is not removing the sprite
     node.scale2D = [0, 0];
     sprite.enabled = false;
     body.enabled = false;
+    self.soundSource.gain = 1.0;
+    self.soundSource.play(coinSound );
+    
+}
+
+self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
+
+    if (nodeA == ThePlayer.node && nodeB == node) {
+        onPlayerHit();
+    }
+    else if (nodeB == node)
+    {
+        var vel = body.linearVelocity;
+        if (vec2.length(vel) > 3)
+        {
+            self.soundSource.gain = .4;
+            self.soundSource.play(coinBounceSound);
+       }
+    }
+
+}
+
+
+function start() {
+
+    self.soundSource = node.createComponent("SoundSource");
+    self.soundSource.soundType = Atomic.SOUND_EFFECT;
+    
+    // would just like to listen to body collisions here
+    self.listenToEvent(null, "PhysicsBeginContact2D", self.onPhysicsBeginContact2D);
+    
 
 }
 

+ 3 - 3
PhysicsPlatformer/Resources/Components/Level.js

@@ -27,9 +27,9 @@ var bats = [];
 
 self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 
-    if (nodeA == ThePlayer.node && self.coinNodes.indexOf(nodeB) != -1) {
-        nodeB.coin.onPlayerHit();
-    }
+    //if (nodeA == ThePlayer.node && self.coinNodes.indexOf(nodeB) != -1) {
+    //    nodeB.coin.onPlayerHit();
+   // }
 
 }
 

+ 9 - 0
PhysicsPlatformer/Resources/Components/UI.js

@@ -11,6 +11,15 @@ function update(timeStep) {
 
 function start() {
 
+    var musicFile = cache.getResource("Sound", "Sounds/JumpingBat.ogg");
+    musicFile.looped = true;
+    var musicNode = scene.createChild("MusicNode");
+    var musicSource = musicNode.createComponent("SoundSource");
+    musicSource.gain = 1.0;
+    musicSource.soundType = Atomic.SOUND_MUSIC;
+    musicSource.play(musicFile);
+
+
     // Construct new Text object
     scoreText = new Atomic.Text();
 

BIN
PhysicsPlatformer/Resources/Sounds/Coin_Bounce.ogg


BIN
PhysicsPlatformer/Resources/Sounds/Jump13.ogg


BIN
PhysicsPlatformer/Resources/Sounds/JumpingBat.ogg


BIN
PhysicsPlatformer/Resources/Sounds/Pickup_Coin8.ogg