Commits

Peter Lockett committed c210b7f

1. Added crackling fire

2. Fixed issue with sound
3. Refactored code.

Comments (0)

Files changed (6)

Coursework/Coursework/Coursework.csproj

     <XnaOutputType>Game</XnaOutputType>
     <ApplicationIcon>Game.ico</ApplicationIcon>
     <Thumbnail>GameThumbnail.png</Thumbnail>
-    <PublishUrl>publish\</PublishUrl>
+    <IsWebBootstrapper>false</IsWebBootstrapper>
+    <PublishUrl>E:\PETER\If XNA isnt installed\</PublishUrl>
     <Install>true</Install>
     <InstallFrom>Disk</InstallFrom>
     <UpdateEnabled>false</UpdateEnabled>
     <MapFileExtensions>true</MapFileExtensions>
     <ApplicationRevision>0</ApplicationRevision>
     <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
-    <IsWebBootstrapper>false</IsWebBootstrapper>
     <UseApplicationTrust>false</UseApplicationTrust>
+    <PublishWizardCompleted>true</PublishWizardCompleted>
     <BootstrapperEnabled>true</BootstrapperEnabled>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
   <PropertyGroup>
     <StartupObject />
   </PropertyGroup>
+  <PropertyGroup>
+    <ManifestCertificateThumbprint>51451D1581A82F832A65426DD3DF67E9D2A1B7B4</ManifestCertificateThumbprint>
+  </PropertyGroup>
+  <PropertyGroup>
+    <ManifestKeyFile>Coursework_TemporaryKey.pfx</ManifestKeyFile>
+  </PropertyGroup>
+  <PropertyGroup>
+    <GenerateManifests>true</GenerateManifests>
+  </PropertyGroup>
+  <PropertyGroup>
+    <SignManifests>true</SignManifests>
+  </PropertyGroup>
   <ItemGroup>
     <ProjectReference Include="..\CourseworkContent\CourseworkContent.contentproj">
       <Name>CourseworkContent %28Content%29</Name>
     <Content Include="Game.ico" />
   </ItemGroup>
   <ItemGroup>
+    <None Include="Coursework_TemporaryKey.pfx" />
     <None Include="GameThumbnail.png">
       <XnaPlatformSpecific>true</XnaPlatformSpecific>
     </None>

Coursework/Coursework/Game1.cs

 
         #region Audio Stuff
 
-        private Cue _baseTrack, _badTrack, _goodTrack, _correctExitHit, _incorrectExitHit;
+        private Cue _baseTrack, _badTrack, _goodTrack, _correctExitHit, _incorrectExitHit, _fireCue;
 
         private Cue _hitObstacle;
 
             _baseTrack = AudioManager.MusicSBank.GetCue("Base"); // Repeats indefinately
             _badTrack = AudioManager.MusicSBank.GetCue("Bad"); // Repeats indefinately
             _goodTrack = AudioManager.MusicSBank.GetCue("Good"); // Repeats indefinately
+            _fireCue = AudioManager.MusicSBank.GetCue("CracklingFire"); // Repeats indefinately
 
             _correctExitHit = AudioManager.SoundEffects.GetCue("ExitFound");
             _hitObstacle = AudioManager.SoundEffects.GetCue("HitObstacle");
             _incorrectExitHit = AudioManager.SoundEffects.GetCue("HitWall");
 
+
             _player = new Player(Content.Load<Texture2D>("Graphics\\Player"), _playerStart, GraphicsDevice);
-            _ufo = new UFO(Content.Load<Texture2D>("Graphics\\UFO"), new Vector3(500, 300, 0), _player._listener);
+            _ufo = new UFO(Content.Load<Texture2D>("Graphics\\UFO"), new Vector3(500, 300, 0), _player.Listener);
 
             _gameroom = new Room(GraphicsDevice, Content);
 
             // Apply 3d on ALL emitters because if the app starts and the closest exit is not the correct one, the game will create an exception.
             for (int i = 0; i < 3; i++)
             {
-                _goodTrack.Apply3D(_player._listener, Room.ExitEmitters[i].Emitter);
-                _badTrack.Apply3D(_player._listener, Room.ExitEmitters[i].Emitter);
+                _goodTrack.Apply3D(_player.Listener, Room.ExitEmitters[i].Emitter);
+                _badTrack.Apply3D(_player.Listener, Room.ExitEmitters[i].Emitter);
             }
 
+            _fireCue.Apply3D(_player.Listener, Room.Obstacles[0]._emitter.Emitter); // We know the furnace obstalce is created first i.e [0]
+
             // Play it here, because it will be repeated indefinately.
             AudioManager.PlayMusic(AudioManager.MusicSBank, "Music", _baseTrack);
             AudioManager.PlayMusic(AudioManager.MusicSBank, "Music", _goodTrack);
             AudioManager.PlayMusic(AudioManager.MusicSBank, "Music", _badTrack);
+            AudioManager.PlayMusic(AudioManager.MusicSBank, "Music", _fireCue);  
         }
 
         /// <summary>
                 ToggleDebug();
 
             _player.Update();
-            _ufo.UpdateSoundAndPos(_player._listener);
+            _ufo.UpdateSoundAndPos(_player.Listener);
 
             CheckCollisions();
             HandleInput();
             {
                 if (Room.ExitEmitters[i].Closest && Room.Exits[i].CheckType == BoundaryRect.Type.Correct)
                 {
-                    _goodTrack.Apply3D(_player._listener, Room.ExitEmitters[i].Emitter);
+                    _goodTrack.Apply3D(_player.Listener, Room.ExitEmitters[i].Emitter);
                 }
-                else if (Room.ExitEmitters[i].Closest && Room.Exits[i].CheckType == BoundaryRect.Type.Incorrect)
+                else if ((Room.ExitEmitters[i].Closest) && Room.Exits[i].CheckType == BoundaryRect.Type.Incorrect || Room.Exits[i].CheckType == BoundaryRect.Type.Previous)
                 {
-                    _badTrack.Apply3D(_player._listener, Room.ExitEmitters[i].Emitter);
+                    _badTrack.Apply3D(_player.Listener, Room.ExitEmitters[i].Emitter);
                 }
             }
 
                     Room.NewRoom();
                     // Play a sound effect that signals one is in a new room
                     AudioManager.PlayEffect(AudioManager.SoundEffects, _correctExitHit, _correctExitHit.Name);
-                    // Warp player to the centre
-                    _player.WarpTo(new Vector3(400, 300, 0));
                 }
 
                 else if (r.CheckAgainst(_player.CollisionRect) == 2)

Coursework/Coursework/Obstacle.cs

 using System.Linq;
 using System.Text;
 using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
 using Microsoft.Xna.Framework.Content;
 using Microsoft.Xna.Framework.Graphics;
 
         // The type of the obstacle
         internal enum Type
         {
-            Table,
+            Furnace,
             Computer,
             Trashcan
         }
 
-        internal readonly Type obstacleType;
-        private SoundEmitter _emitter;
+        private Vector3 _forward = Vector3.Forward;
+        private Vector3 _up = Vector3.Up;
+        private Vector3 _velocity = Vector3.Zero;
+
+        internal readonly Type ObstacleType;
+
+        public SoundEmitter _emitter;
+        public Cue _soundCue;
 
         protected internal Rectangle ObstacleRect;
 
             _wposition = pos;
             _sposition = new Vector2(_wposition.X, _wposition.Y);
 
-            if (type == Type.Table)
+            if (type == Type.Furnace)
             {
                 _obstacleTex = content.Load<Texture2D>("Graphics/Obstacles/Table");
             }
             ObstacleRect = new Rectangle((int)_sposition.X, (int)_sposition.Y, _obstacleTex.Width, _obstacleTex.Height);
 
             // Set the object type so that we can reference it for fancy collision stuff
-            obstacleType = type;
-            _emitter = new SoundEmitter(pos, ObstacleRect, 0f);
+            ObstacleType = type;
+            _emitter = new SoundEmitter(pos, ObstacleRect, 0f) { Emitter = { Forward = _forward, Up = _up, Velocity = _velocity } };
         }
 
         public void Draw(SpriteBatch sb)
             _emitter.Draw(sb);
         }
 
+        public void Update(AudioListener l)
+        {
+            _soundCue.Apply3D(l, _emitter.Emitter);
+        }
+
         /// <summary>
         /// Determines if there is overlap of the non-transparent pixels
         /// between two sprites.

Coursework/Coursework/Player.cs

         #region Fields
 
         public Rectangle CollisionRect;
-        public AudioListener _listener;
+        public AudioListener Listener;
 
         // Per pixel collision stuff
         private readonly Texture2D _playerTexture;
 
             _playerTexture = texture;
 
-            if (_listener == null)
+            if (Listener == null)
             {
-                _listener = new AudioListener { Position = new Vector3(_position.X, _position.Y, 0) };
-                _listener.Forward = _forward;
-                _listener.Up = _up;
-                _listener.Velocity = _velocity;
+                Listener = new AudioListener { Position = new Vector3(_position.X, _position.Y, 0) };
+                Listener.Forward = _forward;
+                Listener.Up = _up;
+                Listener.Velocity = _velocity;
             }
 
             CollisionRect.Height = texture.Height;
             CollisionRect.Y = (int)_position.Y;
 
             // Update the position of the listener
-            _listener.Position = _position;
-            _listener.Forward = _forward;
+            Listener.Position = _position;
+            
+            // Audio doesnt play in different ears if this is explicity set.
+            // _listener.Forward = _forward;
 
             if (_state == State.Walking)
                 AudioManager.PlayEffect(AudioManager.FootStepsSBank, _walkingCue, "Dirt_Steps");
             if (_position.Y > 600) _position.Y = 600;
             _lastKeyState = currentKeyState;
 
-            _listener.Position = _position;
+            Listener.Position = _position;
             _forward = new Vector3((float)Math.Cos(_orientation), (float)Math.Sin(_orientation), 0);
         }
 
 
             _position = Vector3.Transform(_position, transform);
             _orientation += angle;
-
         }
 
         public void Draw(SpriteBatch spriteBatch)

Coursework/Coursework/Room.cs

 
         public static readonly BoundaryRect[] Exits = new BoundaryRect[4]; // Need four rectangles, N E S W
         public static SoundEmitter[] ExitEmitters = new SoundEmitter[4]; // Need sound emitters to play the correct type of music
+        private string[] _exitCompas = {"South", "North", "West", "East"};
 
-        List<Obstacle> _obstacles = new List<Obstacle>();
+        public static List<Obstacle> Obstacles = new List<Obstacle>();
 
         static readonly Random Random = new Random(); // will need a new random to set a different exit to be the correct choice each time
         static int _roomCount;
         private static int _pElement;
         private Cue _hitMovableObstacle;
 
+        // Information for what is the closest exit
+        private string _closetexit;
+
         private SpriteFont _font;
 
         private readonly string[] _distanceString = new string[4];
             for (int j = 0; j < 4; j++)
             {
                 ExitEmitters[j] = new SoundEmitter(new Vector3(Exits[j].Position.X, Exits[j].Position.Y, 0), Exits[j].RetRect(), Exits[j].Rotated());
+                
             }
 
-            _obstacles.Add(new Obstacle(content, new Vector3(100, 200, 0), Obstacle.Type.Table));
-            _obstacles.Add(new Obstacle(content, new Vector3(400, 400, 0), Obstacle.Type.Computer));
-            _obstacles.Add(new Obstacle(content, new Vector3(400, 380, 0), Obstacle.Type.Trashcan));
+            Obstacles.Add(new Obstacle(content, new Vector3(100, 200, 0), Obstacle.Type.Furnace));
+            Obstacles.Add(new Obstacle(content, new Vector3(400, 400, 0), Obstacle.Type.Computer));
+            Obstacles.Add(new Obstacle(content, new Vector3(400, 380, 0), Obstacle.Type.Trashcan));
 
             _hitMovableObstacle = AudioManager.SoundEffects.GetCue("HitObstacle");
 
 
         public void Update(Player p)
         {
-            for (int i = _obstacles.Count - 1; i >= 0; --i)
+            for (int i = Obstacles.Count - 1; i >= 0; --i)
             {
-                if (p.CollisionRect.Intersects(_obstacles[i].ObstacleRect))
+                if (p.CollisionRect.Intersects(Obstacles[i].ObstacleRect))
                 {
                     Console.WriteLine("Collision with object");
 
-                    if (_obstacles[i].obstacleType == Obstacle.Type.Trashcan)
+                    if (Obstacles[i].ObstacleType == Obstacle.Type.Trashcan)
                     {
-                        _obstacles.RemoveAt(i);
+                        Obstacles.RemoveAt(i);
                         Console.WriteLine("That obstacle has been removed");
                         AudioManager.PlayEffect(AudioManager.SoundEffects, _hitMovableObstacle, "HitObstacle");
                         
 
                 float d = 0;
                 var epos = ExitEmitters[i].Position;
-                var ppos = p._listener.Position;
+                var ppos = p.Listener.Position;
                 var distance = Vector3.Distance(epos, ppos);
                 _distanceValues[i] = distance;
 
                 // Might as well also set the emitter that is closest to be 'true'
                 ExitEmitters[FindMin(_distanceValues)].Closest = true;
 
-                // Console.WriteLine("Lowest is : " + FindMin(_distanceValues));
-                Console.WriteLine("Exit : " + i + ExitEmitters[i].Emitter.Forward);
+                _closetexit = "\nClosest exit is : " + _exitCompas[FindMin(_distanceValues)];
 
                 _distanceString[i] = "Exit " + i + " : " + distance;
             }
                 s.Draw(sb);
             }
 
-            foreach (var o in _obstacles)
+            foreach (var o in Obstacles)
             {
                 o.Draw(sb);
             }
 
-            string posdebug = _distanceString[0] + "\n" + _distanceString[1] + "\n" + _distanceString[2] + "\n" + _distanceString[3];
+            string posdebug = _distanceString[0] + "\n" + _distanceString[1] + "\n" + _distanceString[2] + "\n" +
+                              _distanceString[3] + _closetexit;
             sb.DrawString(_font, posdebug, new Vector2(gd.Viewport.Bounds.Left,0), Color.White);
         }
     }

Coursework/CourseworkContent/Audio/AllTheAudio.xap

     Header File = AllTheAudio.h;
     Exclude Category Names = 0;
     Exclude Variable Names = 0;
-    Last Modified Low = 30223454;
-    Last Modified High = 2803417562;
+    Last Modified Low = 2803417562;
+    Last Modified High = 30223454;
 
     Category
     {
         Reserved = 1;
         Read Only = 0;
         Time = 0;
-        Value = 0.000000;
+        Value = 1.000000;
         Initial Value = 1.000000;
         Min = 0.000000;
         Max = 4.000000;
 
         RPC Curve
         {
-            Name = Sound::eaf5ce35-363b-45f0-87ac-3846f226d93a;
+            Name = Sound::4fc6b3bd-78ca-4c77-9ef2-d6298239d8ea;
             Property = 1;
             Sound = 1;
             Line Color = 4289957122;
 
         RPC Curve
         {
-            Name = 1::05744c58-edab-48a2-8a21-12ef7d9bfac4;
+            Name = 1::5cfae691-90a0-4707-961a-9a3b985eb13c;
             Property = 0;
             Sound = 0;
             Line Color = 4290541963;
     Windows Bank Path Edited = 1;
     Seek Tables = 1;
     Compression Preset Name = <none>;
+    Xbox Bank Last Modified Low = 0;
+    Xbox Bank Last Modified High = 0;
+    PC Bank Last Modified Low = 0;
+    PC Bank Last Modified High = 0;
+    Header Last Modified Low = 0;
+    Header Last Modified High = 0;
     Bank Last Revised Low = 1684508688;
     Bank Last Revised High = 30223841;
 
     Streaming = 1;
     Seek Tables = 1;
     Compression Preset Name = <none>;
-    Bank Last Revised Low = 289257074;
-    Bank Last Revised High = 30223836;
+    Bank Last Revised Low = 2231430865;
+    Bank Last Revised High = 30224236;
 
     Wave
     {
             Last Modified High = 30223835;
         }
     }
+
+    Wave
+    {
+        Name = crackling_fire;
+        File = ..\..\..\..\Pete's Stuff 16bit wav\crackling_fire.wav;
+        Build Settings Last Modified Low = 2173887574;
+        Build Settings Last Modified High = 30224236;
+
+        Cache
+        {
+            Format Tag = 0;
+            Channels = 1;
+            Sampling Rate = 44100;
+            Bits Per Sample = 1;
+            Play Region Offset = 44;
+            Play Region Length = 834048;
+            Loop Region Offset = 0;
+            Loop Region Length = 0;
+            File Type = 1;
+            Last Modified Low = 2058046976;
+            Last Modified High = 30223919;
+        }
+    }
 }
 
 Sound Bank
     Windows File = SoundEffects.xsb;
     Xbox Bank Path Edited = 1;
     Windows Bank Path Edited = 1;
+    Header Last Modified High = 0;
+    Header Last Modified Low = 0;
 
     Sound
     {
     Windows File = BackgroundMusic.xsb;
     Xbox Bank Path Edited = 1;
     Windows Bank Path Edited = 1;
-    Header Last Modified High = 0;
-    Header Last Modified Low = 0;
 
     Sound
     {
             RPC Curve Entry
             {
                 RPC Name = Distance;
-                RPC Curve Name = 1::05744c58-edab-48a2-8a21-12ef7d9bfac4;
+                RPC Curve Name = 1::5cfae691-90a0-4707-961a-9a3b985eb13c;
             }
         }
     }
             {
                 Loop Count = 255;
                 Break Loop = 0;
-                Use Speaker Position = 0;
-                Use Center Speaker = 1;
-                New Speaker Position On Loop = 1;
+                Use Speaker Position = 1;
+                Use Center Speaker = 0;
+                New Speaker Position On Loop = 0;
                 Speaker Position Angle = 0.000000;
                 Speaker Position Arc = 0.000000;
 
             RPC Curve Entry
             {
                 RPC Name = Distance;
-                RPC Curve Name = 1::05744c58-edab-48a2-8a21-12ef7d9bfac4;
+                RPC Curve Name = 1::5cfae691-90a0-4707-961a-9a3b985eb13c;
             }
         }
     }
         }
     }
 
+    Sound
+    {
+        Name = crackling_fire;
+        Volume = -1200;
+        Pitch = 0;
+        Priority = 0;
+
+        Category Entry
+        {
+            Name = Default;
+        }
+
+        RPC Entry
+        {
+            RPC Name = Distance;
+        }
+
+        Track
+        {
+            Volume = 0;
+            Use Filter = 0;
+
+            Play Wave Event
+            {
+                Loop Count = 255;
+                Break Loop = 0;
+                Use Speaker Position = 0;
+                Use Center Speaker = 1;
+                New Speaker Position On Loop = 1;
+                Speaker Position Angle = 0.000000;
+                Speaker Position Arc = 0.000000;
+
+                Event Header
+                {
+                    Timestamp = 0;
+                    Relative = 0;
+                    Random Recurrence = 0;
+                    Random Offset = 0;
+                }
+
+                Wave Entry
+                {
+                    Bank Name = Music;
+                    Bank Index = 1;
+                    Entry Name = crackling_fire;
+                    Entry Index = 3;
+                    Weight = 255;
+                    Weight Min = 0;
+                }
+            }
+
+            RPC Curve Entry
+            {
+                RPC Name = Distance;
+                RPC Curve Name = 1::5cfae691-90a0-4707-961a-9a3b985eb13c;
+            }
+        }
+    }
+
     Cue
     {
         Name = Base;
             }
         }
     }
+
+    Cue
+    {
+        Name = CracklingFire;
+
+        Variation
+        {
+            Variation Type = 3;
+            Variation Table Type = 1;
+            New Variation on Loop = 0;
+        }
+
+        Sound Entry
+        {
+            Name = crackling_fire;
+            Index = 3;
+            Weight Min = 0;
+            Weight Max = 255;
+        }
+
+        Instance Limit
+        {
+            Max Instances = 1;
+            Behavior = 0;
+
+            Crossfade
+            {
+                Fade In = 0;
+                Fade Out = 0;
+                Crossfade Type = 0;
+            }
+        }
+    }
 }