Skip to content

Commit

Permalink
FlxInvaders sounds and music (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 authored Apr 1, 2024
1 parent 0370009 commit 83e46de
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 1 deletion.
Binary file added Arcade/FlxInvaders/assets/alien_die0.wav
Binary file not shown.
Binary file added Arcade/FlxInvaders/assets/alien_die1.wav
Binary file not shown.
Binary file added Arcade/FlxInvaders/assets/lose.wav
Binary file not shown.
Binary file added Arcade/FlxInvaders/assets/player_shoot.wav
Binary file not shown.
Binary file added Arcade/FlxInvaders/assets/theme.ogg
Binary file not shown.
Binary file added Arcade/FlxInvaders/assets/wall_break.wav
Binary file not shown.
6 changes: 6 additions & 0 deletions Arcade/FlxInvaders/source/Alien.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class Alien extends FlxSprite
velocity.x = 10;
}

override function kill() {
var snd:String = FlxG.random.getObject(["assets/alien_die0.wav", "assets/alien_die1.wav"]);
FlxG.sound.play(snd, 0.9);
super.kill();
}

/**
* Basic game loop is BACK y'all
*/
Expand Down
15 changes: 14 additions & 1 deletion Arcade/FlxInvaders/source/PlayState.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import flixel.sound.FlxSound;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
Expand Down Expand Up @@ -60,9 +61,17 @@ class PlayState extends FlxState
* Inside this function we will create and orient all the important game objects.
*/
override public function create():Void
{
{
if (FlxG.sound.music == null)
FlxG.sound.playMusic("assets/theme.ogg");

FlxG.mouse.visible = false;

if (statusMessage == "YOU LOST")
{
FlxG.sound.play("assets/lose.wav", 0.9);
}

// First we will instantiate the bullets you fire at your enemies.
var numPlayerBullets:Int = 8;
// Initializing the array is very important and easy to forget!
Expand Down Expand Up @@ -187,6 +196,8 @@ class PlayState extends FlxState
// Player died, so set our label to YOU LOST
statusMessage = "YOU LOST";
FlxG.resetState();


}
else if (_aliens.getFirstExisting() == null)
{
Expand All @@ -201,6 +212,8 @@ class PlayState extends FlxState
*/
function stuffHitStuff(Object1:FlxObject, Object2:FlxObject):Void
{
var wallSound:FlxSound = FlxG.sound.play("assets/wall_break.wav");
wallSound.pitch = FlxG.random.float(0.9, 1.1);
Object1.kill();
Object2.kill();
}
Expand Down
4 changes: 4 additions & 0 deletions Arcade/FlxInvaders/source/PlayerShip.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package;

import flixel.sound.FlxSound;
import flixel.FlxG;
import flixel.FlxSprite;

Expand Down Expand Up @@ -62,6 +63,9 @@ class PlayerShip extends FlxSprite
// space bar was just pressed (no autofire in space invaders you guys)
if (FlxG.keys.justPressed.SPACE)
{
// Play a sound effect when the player shoots with slight random pitch
var shootSound:FlxSound = FlxG.sound.play("assets/player_shoot.wav", 0.5);
shootSound.pitch = FlxG.random.float(0.9, 1.1);
// Space bar was pressed! FIRE A BULLET
var playState:PlayState = cast FlxG.state;
var bullet:FlxSprite = playState.playerBullets.recycle();
Expand Down

0 comments on commit 83e46de

Please sign in to comment.