Skip to content

Commit

Permalink
Added music support and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Memorix101 committed May 10, 2019
1 parent 5389f63 commit 68524e3
Show file tree
Hide file tree
Showing 49 changed files with 68,739 additions and 128 deletions.
4 changes: 0 additions & 4 deletions Engine_XNA3/Audio/Mdx/MdxSoundEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ public MdxSoundEngine()
_audioDevice = new Device();
_audioDevice.SetCooperativeLevel(GameEngine.Game.Window.Handle, CooperativeLevel.Priority);
}

public void SetDefaultVolume(int volume)
{
_defaultVolume = volume;
}

public IListener GetListener()
{
if (_listener == null)
_listener = new MdxListener(_audioDevice);
return _listener;
}

public ISound Load(string name, bool is3d)
{
if (!File.Exists(name)) return null;
Expand All @@ -51,7 +48,6 @@ public void Unregister3dSound(ISound sound)
_sounds.Remove(sound);
}


public void Update()
{
if (_listener == null) return;
Expand Down
53 changes: 48 additions & 5 deletions Engine_XNA3/Audio/MusicPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,68 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using Microsoft.DirectX.DirectSound;
using Microsoft.Xna.Framework.Media;
using NAudio.Wave;

namespace OneAmEngine.Audio
{
class MusicPlayer
public class MusicPlayer
{
/*private SoundPlayer _music;
private WaveOutEvent _music;
public static string modName;
string gamePath = AppDomain.CurrentDomain.BaseDirectory + "/GameData/" + modName + "/MUSIC";
private bool found = false;

public MusicPlayer()
{
_music = new SoundPlayer();
if (Directory.Exists(gamePath))
{
found = true;
Shuffle();
}
}

private void Shuffle()
{
if (!found)
return;

var vorbisStream = new NAudio.Vorbis.VorbisWaveReader(gamePath + "/track0" + new Random().Next(2, 9) + ".ogg");
_music = new WaveOutEvent();
_music.Init(vorbisStream);
_music.Stop();
}

public void Play()
{
_music.PlaySync();
}*/
if (!found)
return;

_music.Play();
}
public void Stop()
{
if (!found)
return;

_music.Stop();
}

public void Update()
{
if (!found)
return;

if (_music.PlaybackState == PlaybackState.Stopped)
{
_music.Stop();
Shuffle();
_music.Play();
}
}
}
}
10 changes: 10 additions & 0 deletions Engine_XNA3/Engine_XNA3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v3.0\References\Windows\x86\Microsoft.Xna.Framework.Game.dll</HintPath>
</Reference>
<Reference Include="NAudio, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.1.9.0\lib\net35\NAudio.dll</HintPath>
</Reference>
<Reference Include="NAudio.Vorbis, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NAudio.Vorbis.1.0.0.0\lib\net35\NAudio.Vorbis.dll</HintPath>
</Reference>
<Reference Include="NVorbis, Version=0.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NVorbis.0.8.4.0\lib\NVorbis.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
Expand Down Expand Up @@ -143,6 +152,7 @@
<Content Include="Content\smoke.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
3 changes: 2 additions & 1 deletion Engine_XNA3/GameEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public static void Update(GameTime gameTime)
{
ElapsedSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds * TimeScale;
TotalSeconds = (float)gameTime.TotalGameTime.TotalSeconds;


OneAmEngine.InputProvider.UpdateGamepadRumble();

GameConsole.Clear();

Expand Down
28 changes: 23 additions & 5 deletions Engine_XNA3/InputProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public class InputProvider : GameComponent
private const float SENSITIVITY = 1.0f;
private MouseInputMode _mouseInputMode;
private float _perFrameMultiplier;


static DateTime startRumble;
static TimeSpan timePassed;

public InputProvider(Game game) : base(game)
{
_mouseDelta = new Vector2();
_mouseMultiplier = 0.3f;

// Initialize the mouse smoothing cache.
_mouseSmoothingCache = new Vector2[MOUSE_SMOOTHING_CACHE_SIZE];
_mouseInputMode = MouseInputMode.FPS;
Expand All @@ -74,7 +76,7 @@ public override void Update(GameTime gameTime)
{
float frameTime = GameEngine.ElapsedSeconds;
_perFrameMultiplier = frameTime * SENSITIVITY;

_previousKeyboardState = _keyboardState;
_previousGamePadState = _gamePadState;
_keyboardState = Keyboard.GetState();
Expand Down Expand Up @@ -102,7 +104,7 @@ public override void Update(GameTime gameTime)

//Mouse.SetPosition((int)screenCenter.X, (int)screenCenter.Y);
}

base.Update(gameTime);
}

Expand Down Expand Up @@ -186,6 +188,22 @@ public bool IsButtonDown(Buttons button)
return _gamePadState.IsButtonDown(button);
}

public void GamepadRumble(float leftMotor, float rightMotor)
{
startRumble = DateTime.Now;
GamePad.SetVibration(PlayerIndex.One, leftMotor, rightMotor);
}

public static void UpdateGamepadRumble()
{
timePassed = DateTime.Now - startRumble;

if (timePassed.TotalSeconds >= 0.2f)
{
GamePad.SetVibration(PlayerIndex.One, 0f, 0f);
}
}

public MouseInputMode MouseMode
{
get { return _mouseInputMode; }
Expand All @@ -201,7 +219,7 @@ public MouseInputMode MouseMode
{
_mouseDelta = new Vector2();
}
_mouseInputMode = value;
_mouseInputMode = value;
}
}

Expand Down
6 changes: 6 additions & 0 deletions Engine_XNA3/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NAudio" version="1.9.0" targetFramework="net35" />
<package id="NAudio.Vorbis" version="1.0.0.0" targetFramework="net35" />
<package id="NVorbis" version="0.8.4.0" targetFramework="net35" />
</packages>
6 changes: 2 additions & 4 deletions OpenC1_XNA3/AnimationPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class AnimationPlayer
int _currentFrame;
List<Texture2D> _frames;

public AnimationPlayer(List<Texture2D> frames)
: this(frames, 0)
public AnimationPlayer(List<Texture2D> frames) : this(frames, 0)
{
}

Expand All @@ -33,7 +32,6 @@ public void Play(bool loop)
_playing = true;
_loop = loop;
}

public void Update()
{
if (!_playing) return;
Expand All @@ -53,10 +51,10 @@ public void Update()
_playing = false;
}
}

_currentFrameTime = 0;
}
}

public Texture2D GetCurrentFrame()
{
return _frames[_currentFrame];
Expand Down
2 changes: 1 addition & 1 deletion OpenC1_XNA3/GameModes/RaceCompletedMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void Update()

if (GameEngine.Input.WasPressed(Keys.Enter) || GameEngine.Input.WasPressed(Keys.Escape) || GameEngine.Input.WasPressed(Buttons.Start))
{
Race.Current.ExitAndReturnToMenu();
Race.Current.ExitAndReturnToMenu();
}
}

Expand Down
3 changes: 2 additions & 1 deletion OpenC1_XNA3/GameModes/StandardGameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public override void Update()
if (GameEngine.Input.WasPressed(Keys.Escape) || GameEngine.Input.WasPressed(Buttons.Start))
{
GameEngine.Screen = new PauseMenuScreen((PlayGameScreen)GameEngine.Screen);
return;
GameEngine.Input.GamepadRumble(0, 0);
return;
}

if (GameEngine.Input.WasPressed(Keys.C) || GameEngine.Input.WasPressed(Buttons.Y)) //cockpit / external view
Expand Down
13 changes: 10 additions & 3 deletions OpenC1_XNA3/MessageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void PostHeaderMessage(string message, float displayTime)
{
_headerText = message;
_headerTtl = displayTime;
_headerRect = CenterRectX(0.13f, _headerText.Length * _scale * 7.5f, 50 * _scale);
_headerRect = CenterRectX(0.13f, _headerText.Length * _scale * 7.5f, 50 * _scale);
}

public void PostMainMessage(string pixname, float displayTime, float y, float scale, float animationSpeed)
Expand All @@ -102,12 +102,19 @@ public void PostMainMessage(string pixname, float displayTime, float y, float sc
_messageX = _screenWidth;
}


public override void Render()
{
if (_headerTtl > 0)
{
FontRenderer.Render(Fonts.Text,_headerText, new Vector2(_headerRect.Left, _headerRect.Top), Color.White);
//FontRenderer.Render(Fonts.Text,_headerText, new Vector2(_headerRect.Left, _headerRect.Top), Color.White);
if (_headerText.Equals("Race mode"))
{
FontRenderer.Render(Fonts.Text, _headerText, new Vector2(_headerRect.Left - 100, _headerRect.Top), Color.White);
}
else
{
FontRenderer.Render(Fonts.Text, _headerText, new Vector2(_headerRect.Left, _headerRect.Top), Color.White);
}
}

if (_timerTtl > 0)
Expand Down
1 change: 0 additions & 1 deletion OpenC1_XNA3/Physics/VehicleChassis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public float SteerRatio
get { return _steerAngle / 0.5f; }
}


public void Update()
{
LastSpeeds.Add(Speed);
Expand Down
2 changes: 1 addition & 1 deletion OpenC1_XNA3/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.4.5.0")]
[assembly: AssemblyVersion("1.4.6.0")]
Loading

0 comments on commit 68524e3

Please sign in to comment.