Skip to content

Commit

Permalink
Podsystem audio dla efektów dźwiękowych
Browse files Browse the repository at this point in the history
  • Loading branch information
ktos committed Jan 29, 2022
1 parent 0c90ace commit 6a97879
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 11 deletions.
37 changes: 37 additions & 0 deletions Rex2/AudioManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Raylib_cs;

namespace Rex2
{
public class AudioManager
{
private Dictionary<Sounds, Sound> _sounds;

public static AudioManager Instance { get; private set; } = new AudioManager();

public AudioManager()
{
_sounds = new Dictionary<Sounds, Sound>();
Raylib.InitAudioDevice();

_sounds[Sounds.Bullet] = Raylib.LoadSound(@"assets/laser.ogg");
_sounds[Sounds.Jump] = Raylib.LoadSound(@"assets/jump.ogg");
_sounds[Sounds.Dialogue] = Raylib.LoadSound(@"assets/dialogue.ogg");
_sounds[Sounds.ImportantDialogue] = Raylib.LoadSound(@"assets/important-dialogue.ogg");
_sounds[Sounds.Crush] = Raylib.LoadSound(@"assets/crush.ogg");
}

public void Play(Sounds s)
{
Raylib.PlaySound(_sounds[s]);
}
}

public enum Sounds
{
Bullet,
Jump,
Dialogue,
ImportantDialogue,
Crush
}
}
7 changes: 7 additions & 0 deletions Rex2/DialogueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public DialogueManager()

private void UpdateCurrentSequence()
{
AudioManager.Instance.Play(Sounds.Dialogue);
currentSequence = randomSequences[currentSequenceIndex];
displayedDialogue = currentSequence[0];
dialogueIndex = 0;
Expand Down Expand Up @@ -214,6 +215,11 @@ public void UpdateDialogue(LevelBase level, LevelDefinition def, Player player,
{
if (dialogueIndex + 1 < currentSequence.Count)
{
if (currentSequence[dialogueIndex + 1].Text.Length > 0)
{
AudioManager.Instance.Play(Sounds.Dialogue);
}

dialogueIndex++;
}
else
Expand All @@ -237,6 +243,7 @@ public void UpdateDialogue(LevelBase level, LevelDefinition def, Player player,

public void UpdateDialogueOnSituation(Situation s)
{
AudioManager.Instance.Play(Sounds.ImportantDialogue);
switch (s)
{
case Situation.HighJump:
Expand Down
13 changes: 3 additions & 10 deletions Rex2/Norma.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ private void Check()
}

if (!sw)
{
AudioManager.Instance.Play(Sounds.Crush);
Gravity();
}
}

private void Gravity()
Expand All @@ -157,14 +160,11 @@ private void Gravity()
{
for (int i = 0; i < sizeX; i++)
{
//TODO CAER
if (Fall(i, j))
{
Sw = true;
}
}

//if (j <= sizeY && !fast) //<-Wait
}
}

Expand Down Expand Up @@ -217,13 +217,6 @@ public void MarkActive(int x, int y, Norma parent)
FirstActive = null;
SecondActive = null;
}
//else
//{
// Grid[(int)FirstActive.Value.X, (int)FirstActive.Value.Y].Active = false;
// Grid[(int)SecondActive.Value.X, (int)SecondActive.Value.Y].Active = false;
// FirstActive = null;
// SecondActive = null;
//}
}

private List<Tile> CheckHorizontalMatches()
Expand Down
6 changes: 6 additions & 0 deletions Rex2/Rex2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<None Update="assets\*.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="assets\*.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="assets\*.mp3">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="levels\*.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Binary file added Rex2/assets/crush.ogg
Binary file not shown.
Binary file added Rex2/assets/dialogue.ogg
Binary file not shown.
Binary file added Rex2/assets/important-dialogue.ogg
Binary file not shown.
Binary file added Rex2/assets/jump.ogg
Binary file not shown.
Binary file added Rex2/assets/laser.ogg
Binary file not shown.
29 changes: 28 additions & 1 deletion Rex2/levels/TestLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,35 @@ private void UpdatePlayer1(float deltaTime)
UpdateBullets(deltaTime);
UpdateEnemies(deltaTime);

if (IsKeyDown(KEY_F1))
if (IsKeyPressed(KEY_F1))
{
EnableHighJump();
}

if (IsKeyPressed(KEY_F2))
{
AudioManager.Instance.Play(Sounds.ImportantDialogue);
player.HP++;
}

if (IsKeyPressed(KEY_F3))
{
AudioManager.Instance.Play(Sounds.ImportantDialogue);
player.Ammo++;
}

if (IsKeyPressed(KEY_F4))
{
AudioManager.Instance.Play(Sounds.ImportantDialogue);
player.Shield++;
}

if (IsKeyPressed(KEY_F5))
{
AudioManager.Instance.Play(Sounds.ImportantDialogue);
norma.Energy++;
}

UpdatePlayerOnPlatforms(deltaTime);
UpdateCameraCenter(ref camera, ref player, level.Platforms, deltaTime, screenWidth, screenHeight);
}
Expand Down Expand Up @@ -178,6 +202,8 @@ private void UpdatePlayer(float deltaTime)

if ((IsKeyDown(KEY_SPACE) || IsKeyDown(KEY_W)) && player.CanJump)
{
AudioManager.Instance.Play(Sounds.Jump);

player.Speed = -PLAYER_JUMP_SPD;

player.CanJump = false;
Expand All @@ -187,6 +213,7 @@ private void UpdatePlayer(float deltaTime)
{
if (player.Ammo > 0)
{
AudioManager.Instance.Play(Sounds.Bullet);
level.Bullets.Add(new Bullet { IsOrientedRight = true, RemainingTime = 5, Position = new Vector2(player.Position.X + 20, player.Position.Y - 10) });
player.Ammo--;
}
Expand Down
Binary file added mockup rex2v1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6a97879

Please sign in to comment.