File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,6 +47,12 @@ class Alien extends FlxSprite
4747 velocity .x = 10 ;
4848 }
4949
50+ override function kill () {
51+ var snd : String = FlxG .random .getObject ([" assets/alien_die0.wav" , " assets/alien_die1.wav" ]);
52+ FlxG .sound .play (snd , 0.9 );
53+ super .kill ();
54+ }
55+
5056 /**
5157 * Basic game loop is BACK y'all
5258 */
Original file line number Diff line number Diff line change 11package ;
22
3+ import flixel .sound .FlxSound ;
34import flixel .FlxG ;
45import flixel .FlxObject ;
56import flixel .FlxSprite ;
@@ -60,9 +61,17 @@ class PlayState extends FlxState
6061 * Inside this function we will create and orient all the important game objects.
6162 */
6263 override public function create (): Void
63- {
64+ {
65+ if (FlxG .sound .music == null )
66+ FlxG .sound .playMusic (" assets/theme.ogg" );
67+
6468 FlxG .mouse .visible = false ;
6569
70+ if (statusMessage == " YOU LOST" )
71+ {
72+ FlxG .sound .play (" assets/lose.wav" , 0.9 );
73+ }
74+
6675 // First we will instantiate the bullets you fire at your enemies.
6776 var numPlayerBullets : Int = 8 ;
6877 // Initializing the array is very important and easy to forget!
@@ -187,6 +196,8 @@ class PlayState extends FlxState
187196 // Player died, so set our label to YOU LOST
188197 statusMessage = " YOU LOST" ;
189198 FlxG .resetState ();
199+
200+
190201 }
191202 else if (_aliens .getFirstExisting () == null )
192203 {
@@ -201,6 +212,8 @@ class PlayState extends FlxState
201212 */
202213 function stuffHitStuff (Object1 : FlxObject , Object2 : FlxObject ): Void
203214 {
215+ var wallSound : FlxSound = FlxG .sound .play (" assets/wall_break.wav" );
216+ wallSound .pitch = FlxG .random .float (0.9 , 1.1 );
204217 Object1 .kill ();
205218 Object2 .kill ();
206219 }
Original file line number Diff line number Diff line change 11package ;
22
3+ import flixel .sound .FlxSound ;
34import flixel .FlxG ;
45import flixel .FlxSprite ;
56
@@ -62,6 +63,9 @@ class PlayerShip extends FlxSprite
6263 // space bar was just pressed (no autofire in space invaders you guys)
6364 if (FlxG .keys .justPressed .SPACE )
6465 {
66+ // Play a sound effect when the player shoots with slight random pitch
67+ var shootSound : FlxSound = FlxG .sound .play (" assets/player_shoot.wav" , 0.5 );
68+ shootSound .pitch = FlxG .random .float (0.9 , 1.1 );
6569 // Space bar was pressed! FIRE A BULLET
6670 var playState : PlayState = cast FlxG .state ;
6771 var bullet : FlxSprite = playState .playerBullets .recycle ();
You can’t perform that action at this time.
0 commit comments