Skip to content

Commit 83e46de

Browse files
FlxInvaders sounds and music (#335)
1 parent 0370009 commit 83e46de

9 files changed

Lines changed: 24 additions & 1 deletion

File tree

31 KB
Binary file not shown.
31 KB
Binary file not shown.

Arcade/FlxInvaders/assets/lose.wav

354 KB
Binary file not shown.
31 KB
Binary file not shown.
2.24 MB
Binary file not shown.
13.8 KB
Binary file not shown.

Arcade/FlxInvaders/source/Alien.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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
*/

Arcade/FlxInvaders/source/PlayState.hx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package;
22

3+
import flixel.sound.FlxSound;
34
import flixel.FlxG;
45
import flixel.FlxObject;
56
import 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
}

Arcade/FlxInvaders/source/PlayerShip.hx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package;
22

3+
import flixel.sound.FlxSound;
34
import flixel.FlxG;
45
import 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();

0 commit comments

Comments
 (0)