C# Game Programming: For Serious Game Creation - Completed

Published August 24, 2011
Advertisement
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
0 likes 9 comments

Comments

calculemus1988
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?

Cya
August 25, 2011 08:33 AM
sprite_hound
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).
August 25, 2011 12:48 PM
calculemus1988
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.
August 25, 2011 01:37 PM
sprite_hound
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...))
August 25, 2011 11:46 PM
calculemus1988
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.

[url="http://www.mediafire.com/?978f8furv662xt7"]Download game[/url]

Thank you
August 26, 2011 08:05 AM
sprite_hound
Yup, I get the same "alutLoadMemoryFromFile failed" error.
August 26, 2011 12:41 PM
yckx
Using spruces from other games is copyright infringement. There are plenty of cheaply- and freely-available art resources online.
August 27, 2011 12:55 AM
calculemus1988
yckx I got them from [url="http://www.gsarchives.net/index2.php?category=all&system=computer&game=starcraft_brood_war&type=sprites&level0=non-animated"]here[/url]

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?

Cya
August 27, 2011 08:49 AM
yckx
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 [url="http://www.gamedev.net/files/file/40-ultimate-ship-pack/"]Ultimate Ship Pack[/url].

I'm also getting the error:
[b]
alutLoadMemoryFromFile failed.

at SoundManager.LoadSound(String soundId, String path)
at GameForm.InitializeSounds()
at GameForm.ctor()
at Program.Main()[/b]

Based on [url="http://distro.ibiblio.org/rootlinux/ports/more/freealut/freealut-1.1.0/doc/alut.html#alutLoadMemoryFromFile"]this reference[/url], you should be able to use something like [b]alutGetErrorString( alutGetError() )[/b] to get a better indication of what is causing the error.
August 27, 2011 03:18 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement