Jump to content

- - - - -

C# Game Programming: For Serious Game Creation - Completed

4: Adsense

Finished my first sprite shooter. I will keep working on it for a while. I won't create the art, I will use sprites from other games. I am more interested in programming, so that is what I will focus on.

Here is the installer, please let me know if it works or does not work for you. I worked in Visual Studio C# and Windows XP, compiled for 32-bit architecture.

Download Game

Aug 25 2011 02:33 AM
Hello zarfius,

Thank you for your input :). You move on keyboard arrows and you shoot on Spacebar.

I guess all the trouble comes from you not having a sound card? Do you suggest I modify my game so that in such cases it is still playable but without sound? I could make that I guess, something like if(soundDeviceDetected){do sound stuff}.

How did you enter the game with that error anyways?

Aug 25 2011 06:48 AM
I get the same SoundManager errors as zarfius (just clicking ignore on the message box seems to work). I don't see why it would be anything to do with a sound card though. Possibly just a sound file in the wrong place or something?

In the game itself, I was at first confused by the player starting off the screen to the left. Also, the movement is a bit odd for a side-scroller, in that the ship actually turns in the direction it's going, rather than just moving up / down while facing the same way. Personally, I was disappointed that the ship bullets don't travel very far (made it rather hard, but perhaps I'm just not very good at it).
Aug 25 2011 07:37 AM
Hello _sprite, thanks for dropping by

Movement: Eventually the ship will move through stuff so that movement will be needed. Right now I agree the movement is odd, but as I add more level elements it will be justified I think.

Sound: Do you get sound to play when you shoot and on explosions?

Bullets: Bullets are alive in a rectangle. Make sure you play the game with window maximized. Or maybe you are at higher resolution and so the ship movement and bullets can only move in some smaller area on screen?

Anyways this is Form1.InitializeSounds()

private void InitializeSounds()
// Sounds are loaded here.
_soundManager.LoadSound("player_shoot", "Sounds/playerShoot.wav");
_soundManager.LoadSound("enemy_shoot", "Sounds/enemyShoot.wav");
_soundManager.LoadSound("enemy_explode", "Sounds/enemyExplode.wav");

For LoadSound first argument is string for easier sound naming, and second one is file path. Maybe I should use absolute paths instead?

Thank you for input :rolleyes:, cya

PS: Will work on that sound error, I have it showing up also on my other laptop PC. Dunno why, for now, on my PC, the one I work on, everything is fine.
Aug 25 2011 05:46 PM
Well, I don't know what the assertion actually is (I guess it comes from somewhere deep inside the LoadSound function since there's one error message for each sound), but in any case relative paths are probably the way to go. No sounds actually seem to play once I'm in the game after getting those messages.

After playing again for a bit, I don't think the bullets are so bad. I think I was just slightly surprised by the way the player's ship velocity is added to the bullet velocity (which is technically correct, I guess, but I think slightly unusual for an arcade style side-scroller (not that I've played many recently...))
Aug 26 2011 02:05 AM
Hi _sprite,

Here is the method LoadSound:

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, "AL_ERROR.");
System.Diagnostics.Debug.Assert(File.Exists(path), "File does not exist.");

int format;
float frequency;
int size;
IntPtr data = Alut.alutLoadMemoryFromFile(path, out format, out size, out frequency);

System.Diagnostics.Debug.Assert(data != IntPtr.Zero, "alutLoadMemoryFromFile failed.");

// 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));

The difference is I added comments to the Asserts so now you will get a message and know which one failed. Here is the game again with these comments added, would you like to please try again and just let me know which error it is? On my laptop I get error "alutLoadMemoryFromFile failed.", from the last Assert. On my PC everything is fine. I suppose you will get the same error.

About the bullets, that behavior was not planned for. I don't want it that way. Don't move and shoot, you will see that still some bullets get just a tiny bit faster for some reason. It is not that critical thing for now but will fix it.

Download game

Thank you
Aug 26 2011 06:41 AM
Yup, I get the same "alutLoadMemoryFromFile failed" error.
Aug 26 2011 06:55 PM
Using spruces from other games is copyright infringement. There are plenty of cheaply- and freely-available art resources online.
Aug 27 2011 02:49 AM
yckx I got them from here

Well if that is the case, I would gladly replace the art. Can you please recommend me where do I find free art resources? I need a whole package, more spaceships with same style.

The backgrounds are from NASA, they are free, I will just have to replace the spaceships. Sounds and explosions are done with free programs, sound and explosion generators.

By the way do you get to play the game, or you get sound error too?

Aug 27 2011 09:18 AM
I'm unsure at best of the legality of using resources from that site. I'm sure they're fine for internal/development use, but before you distribute your game I recommend replacing them with graphics you know you can legally use. You might check GD.net's own marketplace--perhaps the Ultimate Ship Pack.

I'm also getting the error:

alutLoadMemoryFromFile failed.

at SoundManager.LoadSound(String soundId, String path)
at GameForm.InitializeSounds()
at GameForm.ctor()
at Program.Main()

Based on this reference, you should be able to use something like alutGetErrorString( alutGetError() ) to get a better indication of what is causing the error.

Note: GameDev.net moderates comments.