- Viewing Profile: Topics: Gihzah
Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics
Community Stats
- Group Members
- Active Posts 22
- Profile Views 614
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Male
134
Neutral
User Tools
Contacts
Gihzah hasn't added any contacts yet.
Topics I've Started
Bullet spacing consistency
22 June 2012 - 08:11 PM
I'm working on a scrolling shooter and I'm having a hard time figuring out how to keep the bullet spacing the same whether the player is moving forward, backward, or not at all. Right now I'm just adding an int value to the bullet's x pos in its update call. What would I need to do to get the effect I'm looking for?
Texture2D question
18 June 2012 - 12:11 AM
So basically I'm trying to add textures defined in my Game.cs class to a list called scrollingTextures defined in a class called ScrollingBackground.
I know this code doesn't work but it's basically what I'm trying to do.
In ScrollingBackground.cs
In Game.cs
What would I need to do to go about this?
I know this code doesn't work but it's basically what I'm trying to do.
In ScrollingBackground.cs
public void AddBackground(Texture2D texture)
{
Texture2D textureDefinedInGame.cs = new Texture2D();
scrollingTextures.Add(textureDefinedInGame.cs);
}
In Game.cs
scrollingBackground.AddBackground(background);
What would I need to do to go about this?
Collision detection in C# via colored pixels?
10 June 2012 - 08:52 PM
I was trying to come up with a way to add collision to the scenery in my game without the use of a level editor. The best thing I could come up with is using an overlay image who's alpha value would be set to 0 and would contain pink pixels outlining the collision on the level - After which, I'd use pointF to draw the collision lines. I'm just not sure how I'd go about telling C# to detect the pink pixels and to put a point on them. Has anyone ever taken this approach? Is it even practical and or possible?
Problem loading sounds (OpenAL & c#)
31 May 2012 - 07:56 PM
I've been trying to figure this out all day/night and I am completely at a loss. Every time I run the code below I get an "Assertion Failed" error. It seems like the problem is with the LoadSound method in the SoundManager class. I've checked the binary directory of my project folder I think 50 times now to make sure the sound files are actually in there as well as the alut.dll, ILU.dll and OpenAL32.dll files...
These are all the classes in the engine related to sound as well as what's relevant in the form.cs file. Any sort of help or nudge in the right direction will be greatly appreciated
Form1.cs
SoundManager.cs
Sound.cs
SoundTestState.cs
These are all the classes in the engine related to sound as well as what's relevant in the form.cs file. Any sort of help or nudge in the right direction will be greatly appreciated
Form1.cs
Spoiler
namespace exByte_Test
{
public partial class Form1 : Form
{
SoundManager _soundManager = new SoundManager();
public Form1()
{
InitializeComponent();
InitializeSounds();
}
private void InitializeSounds()
{
_soundManager.LoadSound("effect", "soundeffect1.wav");
_soundManager.LoadSound("effect2", "soundeffect2.wav");
}
}
}
SoundManager.cs
Spoiler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenAl;
using System.IO;
namespace exByte
{
public class SoundManager : IDisposable
{
struct SoundSource
{
public SoundSource(int bufferId, string filePath)
{
_bufferId = bufferId;
_filePath = filePath;
}
public int _bufferId;
string _filePath;
}
Dictionary<string, SoundSource> _soundIdentifier = new Dictionary<string, SoundSource>();
readonly int MaxSoundChannels = 256;
List<int> _soundChannels = new List<int>();
float _masterVolume = 1.0f;
public SoundManager()
{
Alut.alutInit();
DicoverSoundChannels();
}
private void DicoverSoundChannels()
{
while (_soundChannels.Count < MaxSoundChannels)
{
int src;
Al.alGenSources(1, out src);
if (Al.alGetError() == Al.AL_NO_ERROR)
{
_soundChannels.Add(src);
}
else
{
break; // there's been an error - we've filled all the channels.
}
}
}
private bool IsChannelPlaying(int channel)
{
int value = 0;
Al.alGetSourcei(channel, Al.AL_SOURCE_STATE, out value);
return (value == Al.AL_PLAYING);
}
private int FindNextFreeChannel()
{
foreach (int slot in _soundChannels)
{
if (!IsChannelPlaying(slot))
{
return slot;
}
}
return -1;
}
public void LoadSound(string soundId, string path)
{
// Generate a buffer.
int buffer = -1;
Al.alGenBuffers(1, out buffer);
int errorCode = Al.alGetError();
System.Diagnostics.Debug.Assert(errorCode == Al.AL_NO_ERROR);
int format;
float frequency;
int size;
System.Diagnostics.Debug.Assert(File.Exists(path), "File not found");
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);
System.Diagnostics.Debug.Assert(data != IntPtr.Zero);
// Load wav data into the generated buffer.
Al.alBufferData(buffer, format, data, size, (int)frequency);
// Every seems ok, add it to the library.
_soundIdentifier.Add(soundId, new SoundSource(buffer, path));
}
public Sound PlaySound(string soundId)
{
// Default play sound doesn't loop.
return PlaySound(soundId, false);
}
public Sound PlaySound(string soundId, bool loop)
{
int channel = FindNextFreeChannel();
if (channel != -1)
{
Al.alSourceStop(channel);
Al.alSourcei(channel, Al.AL_BUFFER, _soundIdentifier[soundId]._bufferId);
Al.alSourcef(channel, Al.AL_PITCH, 1.0f);
Al.alSourcef(channel, Al.AL_GAIN, 1.0f);
if (loop)
{
Al.alSourcei(channel, Al.AL_LOOPING, 1);
}
else
{
Al.alSourcei(channel, Al.AL_LOOPING, 0);
}
// Al.alSourcef(channel, Al.AL_GAIN, _masterVolume);
Al.alSourcePlay(channel);
return new Sound(channel);
}
else
{
// Error sound
return new Sound(-1);
}
}
public void ChangeVolume(Sound sound, float value)
{
Al.alSourcef(sound.Channel, Al.AL_GAIN, _masterVolume * value);
}
public bool IsSoundPlaying(Sound sound)
{
return IsChannelPlaying(sound.Channel);
}
public void StopSound(Sound sound)
{
if (sound.Channel == -1)
{
return;
}
Al.alSourceStop(sound.Channel);
}
public void MasterVolume(float value)
{
_masterVolume = value;
foreach (int channel in _soundChannels)
{
Al.alSourcef(channel, Al.AL_GAIN, value);
}
}
#region IDisposable Members
public void Dispose()
{
foreach (SoundSource soundSource in _soundIdentifier.Values)
{
SoundSource temp = soundSource;
Al.alDeleteBuffers(1, ref temp._bufferId);
}
_soundIdentifier.Clear();
foreach (int slot in _soundChannels)
{
int target = _soundChannels[slot];
Al.alDeleteSources(1, ref target);
}
Alut.alutExit();
}
#endregion
}
}
Sound.cs
Spoiler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenAl;
namespace exByte
{
public class Sound
{
public int Channel { get; set; }
public bool FailedToPlay
{
get
{
// minus is an error state.
return (Channel == -1);
}
}
public Sound(int channel)
{
Channel = channel;
}
}
}
[b]SoundTestState.cs[/b]
SoundTestState.cs
Spoiler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using exByte;
namespace exByte_Test
{
class SoundTestState : IGameObject
{
SoundManager _soundManager;
double _count = 3;
public SoundTestState(SoundManager soundManager)
{
_soundManager = soundManager;
_soundManager.MasterVolume(0.1f);
}
public void Render()
{
// The sound test doesn't need to render anything.
}
public void Update(double elapsedTime)
{
_count -= elapsedTime;
if (_count < 0)
{
_count = 3;
_soundManager.PlaySound("effect");
_soundManager.PlaySound("effect2");
}
}
}
}
- Home
- » Viewing Profile: Topics: Gihzah

Find content