contrib/asteronits: add sound effects
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 15 Dec 2015 16:41:51 +0000 (11:41 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 16 Dec 2015 13:44:46 +0000 (08:44 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/asteronits/README.md
contrib/asteronits/assets/sounds/explosion_asteroids.wav [new file with mode: 0644]
contrib/asteronits/assets/sounds/explosion_ship.wav [new file with mode: 0644]
contrib/asteronits/assets/sounds/fire.mp3 [new file with mode: 0644]
contrib/asteronits/src/asteronits.nit
contrib/asteronits/src/game_logic.nit

index aefee88..3099861 100644 (file)
@@ -10,4 +10,6 @@ This projects is organized in 3 modules, one per concern:
 
 # Art
 
-Artwork created by Kenney.nl under CC0
+* Graphics and laser sound created by Kenney.nl under CC0.
+* Remote explosion sound created by NenadSimic under CC0.
+* Close explosion sound created by dklon under CC-BY 3.0.
diff --git a/contrib/asteronits/assets/sounds/explosion_asteroids.wav b/contrib/asteronits/assets/sounds/explosion_asteroids.wav
new file mode 100644 (file)
index 0000000..bc2a5f7
Binary files /dev/null and b/contrib/asteronits/assets/sounds/explosion_asteroids.wav differ
diff --git a/contrib/asteronits/assets/sounds/explosion_ship.wav b/contrib/asteronits/assets/sounds/explosion_ship.wav
new file mode 100644 (file)
index 0000000..2291b2b
Binary files /dev/null and b/contrib/asteronits/assets/sounds/explosion_ship.wav differ
diff --git a/contrib/asteronits/assets/sounds/fire.mp3 b/contrib/asteronits/assets/sounds/fire.mp3
new file mode 100644 (file)
index 0000000..d1f2ba2
Binary files /dev/null and b/contrib/asteronits/assets/sounds/fire.mp3 differ
index 588bdb6..2eb5e3a 100644 (file)
@@ -26,6 +26,7 @@ import gamnit::simple_2d
 
 import game_logic
 import spritesheet
+import app::audio
 
 redef class Spritesheet
        # Largest meteors, organized by color
@@ -59,6 +60,11 @@ redef class App
        # Current world in play
        var world = new World(12, 2, display.aspect_ratio) is lazy
 
+       # Sound effects
+       private var fx_fire = new Sound("sounds/fire.mp3")
+       private var fx_explosion_ship = new Sound("sounds/explosion_ship.wav")
+       private var fx_explosion_asteroids = new Sound("sounds/explosion_asteroids.wav")
+
        redef fun on_create
        do
                super
@@ -147,6 +153,12 @@ redef class Asteroid
                sprite = new Sprite(tex, center)
                super
        end
+
+       redef fun destroy
+       do
+               super
+               app.fx_explosion_asteroids.play
+       end
 end
 
 redef class Bullet
@@ -184,6 +196,7 @@ redef class Ship
                # Show or hide the thrust sprite
                if applied_thrust > 0.0 then
                        thrust_sprite.alpha = 1.0
+
                else if thrust_sprite.alpha > 0.0 then
                        thrust_sprite.alpha -= dt*4.0
                        if thrust_sprite.alpha < 0.0 then thrust_sprite.alpha = 0.0
@@ -192,6 +205,18 @@ redef class Ship
                # HACK, the "enemy" ship used for the player points downwards
                sprite.rotation += pi
        end
+
+       redef fun fire
+       do
+               super
+               app.fx_fire.play
+       end
+
+       redef fun hit
+       do
+               super
+               app.fx_explosion_ship.play
+       end
 end
 
 redef class KeyEvent
index 8d45e54..b7ec3f4 100644 (file)
@@ -83,6 +83,7 @@ class World
                                        if object == ship then
                                                # The ship is invincible
                                                # TODO health and losing
+                                               ship.hit
                                        else
                                                object.destroy
                                        end
@@ -197,6 +198,9 @@ class Ship
                world.objects.add bullet
                world.bullets.add bullet
        end
+
+       # Something hits the ship
+       fun hit do end
 end
 
 # Asteroid, the main obstacle in this game