Pong in C# w/ XNA

Started by
28 comments, last by Bromordra 13 years, 6 months ago
I feel I've made too many topics about this project, so I'm going to put down my list of goals for this game and try to keep it in a single topic:


Scoring System. I want to display the player scores onscreen. I figure the score would be an array, though I haven't had much experience with those.

A Win condition: I want to have a win condition of 10 points before the game ends, and it announces the winner, etc, with a free play (no end score) option as well. I also want the option of a 'Sudden Death' mode, where the first one to miss loses. For this I'll also need to handle the next feature.

Menus: I want to have a simple title screen, with a menu where the player can choose to play with the AI, or another human player, and be able to select which point system (as mentioned earlier) they want to play under. I'll need to know how to actually make title screens/menus and how to transition between the screens, as well as how to allow the player to choose their options (I figure this would be centered around Boolean.)

Sound: I want simple sounds for the various actions that occur in the game, and possibly title music. I was also thinking about allowing the player to adjust the audio levels, but I don't know what that would require, and I'd also want the player to be able to save this option so they don't have to do it every time.

I was also thinking about multiple levels of AI difficulty (in regards to how the second paddle moves), though I don't know if the Code I currently use for AI will work with this.

Edit:

Game Background: I want to be able allow the player to choose the background color (or possibly a background image) during the game. It would be in an option menu. I'd like to know how to implement this.

Extras: I wanted to have one background color be available through typing the color name on the keyboard. I don't know how to read keyboard input outside of checking for individual presses, and only if they're held down.

I'd like like to look into custom paddle colors for players to choose from.

I've gotten the collision, and the AI to work correctly, and now I'm onto the next step, which is scoring.


Some of this seems a bit excessive for simply pong, but I want to learn how to do these things now, so I can apply them to later projects once this is complete.

Any assistance on how to do any of these things is highly appreciated.

[Edited by - Slateboard on September 7, 2010 2:51:15 PM]
Advertisement
I can't comment on the XNA-specific aspects of your question, but:
Quote:Scoring System. I want to display the player scores onscreen. I figure the score would be an array, though I haven't had much experience with those.
Typically you would use an integer for the numerical representation of the score, and a string for the textual representation.

In C#, you can easily convert an integer to a string using the ToString() function. Although I can't tell you how to do it off the top of my head, I'm sure you can also format the string to your liking as well (e.g. by adding leading zeros to create a 'fixed-width' string).

I imagine when you mention the use of arrays, you're thinking of an array where each entry is one digit of the score's numerical value. Although you could do it this way, I'd go with using an integer and a string instead, as it's more straightforward (IMO).
Quote:Original post by jyk

In C#, you can easily convert an integer to a string using the ToString() function. Although I can't tell you how to do it off the top of my head,



In .net all types have a ToString() function.
They hated on Jeezus, so you think I give a f***?!
Quote:In .net all types have a ToString() function.
Hm, if you're pointing out that the way to convert an integer to a string is to use ToString(), then yes, that's exactly what I said. If you're pointing out that all types derived from System.Object (not just integer types) have a ToString() method, then yes, that is of course true, but it doesn't contradict my statement in any way.

Anyway, sorry if I'm misunderstanding your post (if I am though, feel free to clarify).
I'm new to xna myself but hopefully i can be of some help.

Scoring: exactly what jyk said, just use an int variable to hold the score and use it with a Spritebatch drawstring as below to draw it on screen:

spriteBatch.DrawString(mySpriteFont, "Player 1 Score: " + player1Score, new Vector2(50, 10), Color.Yellow);


As for the win condition, could have a Win() method which returns a boolean value, true if the score has reached 10 false otherwise, and have the main game loop have a test for checking if win is false then keep doing what its doing, otherwise show gameover screen or something like that.

Menus im actually looking into this myself, look at the xna website it actualy has an example of how to make some basic menus, i think the example is called GameStateManagement (i think).

Sound, with xna it comes with the tool XACT, its straightforward to use to get sounds in a game ( look up riemers xna tutorial, has a specific bit to do with sound in xna)

http://www.riemers.net/eng/Tutorials/XNA/Csharp/series2d.php

but not sure how you would control the volume in game.

Im sure some other people will be able to give better and more detailed answers, im still getting used to XNA. Good luck with the game its good that your wanting to do a finished product rather than just get the basics working and then move on to something else, it will help so much for future projects.


Quote:Original post by jyk
Quote:In .net all types have a ToString() function.
Hm, if you're pointing out that the way to convert an integer to a string is to use ToString(), then yes, that's exactly what I said. If you're pointing out that all types derived from System.Object (not just integer types) have a ToString() method, then yes, that is of course true, but it doesn't contradict my statement in any way.

Anyway, sorry if I'm misunderstanding your post (if I am though, feel free to clarify).
You wrote "Although I can't tell you how to do it off the top of my head" and I'm pretty sure that guy misunderstood that to mean you were talking about ToString. I was a little confused as well at first, but I kept reading and realized you were pre-emptively saying you couldn't tell how to format a string.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by Dr1fter
I'm new to xna myself but hopefully i can be of some help.


Im sure some other people will be able to give better and more detailed answers, im still getting used to XNA. Good luck with the game its good that your wanting to do a finished product rather than just get the basics working and then move on to something else, it will help so much for future projects.


In my mind, if I can incorporate these features into Pong, then I'll be able to add them to future projects much easier due to previous experience.

And there's the possibility of the code being re-usable.
Quote:Original post by jyk
I can't comment on the XNA-specific aspects of your question, but:
Quote:Scoring System. I want to display the player scores onscreen. I figure the score would be an array, though I haven't had much experience with those.
Typically you would use an integer for the numerical representation of the score, and a string for the textual representation.

In C#, you can easily convert an integer to a string using the ToString() function. Although I can't tell you how to do it off the top of my head, I'm sure you can also format the string to your liking as well (e.g. by adding leading zeros to create a 'fixed-width' string).

I imagine when you mention the use of arrays, you're thinking of an array where each entry is one digit of the score's numerical value. Although you could do it this way, I'd go with using an integer and a string instead, as it's more straightforward (IMO).


I wasn't aware that I could use an integer and string. Would you mind elaborating on it?
Quote:Original post by nobodynews
You wrote "Although I can't tell you how to do it off the top of my head" and I'm pretty sure that guy misunderstood that to mean you were talking about ToString. I was a little confused as well at first, but I kept reading and realized you were pre-emptively saying you couldn't tell how to format a string.
Even if Fl4sh misread my statement as you described, how would the statement:
Quote:In .net all types have a ToString() function.
Be relevant? Still doesn't really make much sense to me :|
Quote:Original post by Slateboard
I wasn't aware that I could use an integer and string. Would you mind elaborating on it?
There's really not much more to it than what was described previously: store the score as an integer, and then convert it to a string for display.

Can you specify what you need clarification on?
Well, I'm not really familiar with the process itself. So an example would be appreciated.

This topic is closed to new replies.

Advertisement