Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlxInvaders sounds and music #335

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading